new-api icon indicating copy to clipboard operation
new-api copied to clipboard

[Bug] Channel model_mapping does not map tools[].model (Anthropic advisor tool, Responses image_generation)

Open Hahrix opened this issue 4 days ago • 0 comments

Agent: Claude Code unknown · tx-org/ce/claude-opus-5-5 · macOS arm64 · 2026-12-01 UTC

Request summary

The PR author asked the agent to file the issue that PR #8488 fixes. The agent reproduced the behavior on an unmodified v1.0.0-rc.52 build without help from the author.

Summary

Bug: channel model_mapping rewrites only the top-level model. It does not rewrite a model field inside tools[]. If a client sends a model alias in a tool definition, new-api forwards the alias upstream unchanged. Two official tools carry such a field:

  • the Anthropic advisor tool (type: advisor_20260301). Its model is required and names the advisor model (docs).
  • the OpenAI Responses image_generation tool. Its model is optional and selects the image model (docs).
 relay/helper.ModelMappedHelper
   request.model       alias -> mapped upstream name
-  request.tools[].model   alias forwarded unchanged

Evidence

  • Version / deploy / database: tag v1.0.0-rc.52 (04dfcbb71), built from source with Go 1.27.4 on macOS arm64, SQLite, one instance. Pass-through is off.

  • Actual: the upstream receives the mapped top-level model and the unmapped tool model.

  • Expected: the channel model_mapping also maps the tool model, the same way it maps the top-level model.

  • Reproduce: a local mock upstream records the request body that new-api sends.

    1. Create an Anthropic channel (type 14) with base_url set to the mock and this model_mapping:

      {"ce/claude-opus-5-5": "claude-sonnet-5", "ld/claude-fable-5-2": "claude-opus-5-5"}
      
    2. Send this request with header anthropic-beta: advisor-tool-2026-03-01:

      curl $BASE/v1/messages -H "x-api-key: $KEY" -H 'anthropic-version: 2023-06-01' \
        -H 'anthropic-beta: advisor-tool-2026-03-01' -H 'Content-Type: application/json' \
        -d '{"model":"ce/claude-opus-5-5","max_tokens":1024,
             "tools":[{"type":"advisor_20260301","name":"advisor","model":"ld/claude-fable-5-2"}],
             "messages":[{"role":"user","content":"hi"}]}'
      

      The mock upstream receives:

      model = claude-sonnet-5
      tools = [{"type": "advisor_20260301", "name": "advisor", "model": "ld/claude-fable-5-2"}]
      
    3. Create an OpenAI channel (type 1) with model_mapping set to {"ce/gpt-5": "gpt-5", "ce/gpt-image-1": "gpt-image-1"}. Then send this request:

      curl $BASE/v1/responses -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
        -d '{"model":"ce/gpt-5","input":"draw a cat",
             "tools":[{"type":"image_generation","model":"ce/gpt-image-1"}]}'
      

      The mock upstream receives:

      model = gpt-5
      tools = [{"type": "image_generation", "model": "ce/gpt-image-1"}]
      

    A mock upstream returns 200 for any model name, so the steps above show only the forwarded body. The real Anthropic and OpenAI APIs do not know the alias names ld/claude-fable-5-2 and ce/gpt-image-1, so they reject the forwarded request.

Blast Radius

  • Impact: a site that exposes model aliases through model_mapping cannot serve the advisor tool or a Responses image_generation tool with a model. The client must know the real upstream model name. That name may differ between channels, so one alias cannot route to several channels.
  • Frequency: every request that sets tools[].model to a mapped alias. Requests without a tool model are not affected.

Hahrix avatar Dec 01 '26 10:12 Hahrix