Skip to content

Anthropic-compatible API gateway fails to convert tools format — causes missing field 'name' error on DeepSeek models #24344

@lqx3089

Description

@lqx3089

Description

This issue is generated by GLM-5 and reviewed by human.The bug iexist actually, but the resolution may still have some problems.

Anthropic-compatible API gateway fails to convert tools format — causes missing field 'name' error on DeepSeek models

Summary

When using OpenCode's Anthropic-compatible API endpoint with DeepSeek models (e.g., deepseek-v4-pro, deepseek-v4-flash), all tool-calling requests fail with a 400 Bad Request error. The root cause is that OpenCode's API gateway does not convert the tools field from Anthropic format to OpenAI format before forwarding the request to DeepSeek.

Environment

  • API provider: OpenCode (Anthropic-compatible endpoint)
  • Model: deepseek-v4-pro / deepseek-v4-flash
  • Client SDK: Anthropic Python SDK via agentscope's _anthropic_model.py
  • Framework: CoPaw (QwenPaw)

Steps to Reproduce

  1. Configure an agent to use DeepSeek models via OpenCode's Anthropic-compatible API endpoint.
  2. Send any message that triggers tool calling (i.e., the request includes a tools parameter).
  3. The API returns a 400 Bad Request error immediately.

Expected Behavior

OpenCode should accept Anthropic-format tools in the request body and correctly convert them to OpenAI format before forwarding to DeepSeek. The tool call should succeed.

Actual Behavior

The request is rejected with:

400 Bad Request
{
  "error": {
    "message": "Error from provider (DeepSeek): Failed to deserialize the JSON body into the target type: tools[0].function: missing field `name` at line 1 column 16482",
    "type": "invalid_request_error",
    "code": "invalid_request_error"
  }
}

Root Cause Analysis

The Anthropic API expects tools in this format:

{
  "tools": [
    {
      "name": "get_weather",
      "description": "Get weather info",
      "input_schema": {
        "type": "object",
        "properties": { ... }
      }
    }
  ]
}

However, DeepSeek's API expects the OpenAI format:

{
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather info",
        "parameters": {
          "type": "object",
          "properties": { ... }
        }
      }
    }
  ]
}

The error message tools[0].function: missing field 'name' clearly indicates that DeepSeek is trying to parse the tools field in OpenAI format (looking for tools[].function.name), but OpenCode forwarded the Anthropic-format tools unchanged. DeepSeek finds a function key doesn't exist at tools[0], or finds the Anthropic-format object where it expects {function: {name: ...}}.

Evidence

  • Other models work fine: Using the same framework with models that use the OpenAI SDK (e.g., GLM-5) has no issue, because those requests are sent in OpenAI format directly.
  • The error is consistent across all 7 failed requests observed in testing, regardless of message content or session — every request that includes tools fails.
  • DeepSeek never receives a valid request: The error occurs at the JSON deserialization stage, meaning the model never even starts processing.

Suggested Fix

OpenCode's API gateway should convert the tools field from Anthropic format to OpenAI format before forwarding requests to DeepSeek:

Anthropic format OpenAI format
tools[].name tools[].function.name
tools[].description tools[].function.description
tools[].input_schema tools[].function.parameters
(absent) tools[].type = "function"

This is a gateway-level conversion that should be transparent to the client.

Workaround

Until this is fixed, users can use the OpenAI-compatible endpoint directly with DeepSeek models instead of the Anthropic-compatible endpoint.

Plugins

No response

OpenCode version

API

Steps to reproduce

Send a minimal Anthropic-format request with tools to the OpenCode API endpoint using deepseek-v4-pro:

curl -X POST https:///v1/messages
-H "Content-Type: application/json"
-H "x-api-key: "
-H "anthropic-version: 2023-06-01"
-d '{
"model": "deepseek-v4-pro",
"max_tokens": 256,
"messages": [
{"role": "user", "content": "Hello"}
],
"tools": [
{
"name": "get_weather",
"description": "Get weather for a location",
"input_schema": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
]
}'

Expected: A successful response (the model may or may not call the tool).

Actual: 400 Bad Request with the error message about tools[0].function: missing field 'name'.

Note: The same request without the tools parameter succeeds normally. The issue only occurs when tools are included.

Expected Behavior

OpenCode should accept Anthropic-format tools in the request body and correctly convert them to OpenAI format before forwarding to DeepSeek. The tool call should succeed.
Actual Behavior

The request is rejected with:

400 Bad Request
{
"error": {
"message": "Error from provider (DeepSeek): Failed to deserialize the JSON body into the target type: tools[0].function: missing field name at line 1 column 16482",
"type": "invalid_request_error",
"code": "invalid_request_error"
}
}

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions