Skip to content

OpenAI chat-completions response parsing rejects standard wire shapes (usage/tool_calls) #2591

Description

@asdshuaishuai

环境

rig-core 0.42.0,OpenAI-compatible 自定义 base_url(Client::builder().api_key(..).base_url(..).build() + completion_model(model) → POST /chat/completions)。

问题

chat-completions 响应的解析对标准 wire 过严,两处连续失败:

1) usage 要求 responses-API 风格字段。 真实 OpenAI 兼容端点(DeepSeek/MiniMax/StepFun 及 OpenAI 自家 chat completions)发的是:

{"usage": {"prompt_tokens": 11, "completion_tokens": 7, "total_tokens": 18}}

解析报:JsonError: missing field "input_tokens"——内部 compat 响应直接用 crate::completion::Usage(要求 input_tokens/cached_input_tokens 等归一字段,无 serde 别名/默认值)。

2) 工具调用响应的 id 严格性。 把 usage 改成 input_tokens 风格后,标准工具调用响应(tool_calls[0].id = "call_1"、function.arguments 为 JSON 字符串)又报 missing field "id"(列位置落在 tool_calls/message 边界)。

影响

任何发标准 chat-completions wire 的真实端点都无法用 0.42 的 openai chat 路径完成一次基础往返(mock 服务器直连验证,非网络问题)。

期望

chat-completions 兼容层对 wire 的 usage/tool_calls/message 字段做宽容解析(alias + default),或在文档明确 0.42 只支持 Responses API wire。

复现

mock 服务器返回上述两个标准形状响应体即可复现;完整的 mock 响应体与错误信息可提供。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions