Skip to content

OpenAI provider forces Responses API, breaking tool calls with Chat Completions-only proxies #15016

Closed

Description

@conglinyizhi

Description

When using the openai provider with a custom baseURL pointing to a middleware/proxy that only supports the Chat Completions API (/v1/chat/completions), tool calls are rendered as raw JSON text output instead of being executed as tools.

Root cause: provider.ts hardcodes sdk.responses(modelID) for the openai provider with no fallback:

// provider.ts ~L153
openai: async () => {
  return {
    autoload: false,
    async getModel(sdk: any, modelID: string) {
      return sdk.responses(modelID)  // hardcoded — no fallback to sdk.chat()
    },
  }
},

When the proxy returns a Chat Completions-format response, the Responses API stream parser cannot match the event format. tool_calls fields are ignored and content falls through to text-delta, producing raw JSON in the chat output.

Note: azure and azure-cognitive-services providers already handle this correctly via options.useCompletionUrls — the same pattern could be applied here.

Steps to Reproduce

  1. Configure the openai provider with a baseURL pointing to a Chat Completions-only proxy
  2. Start a session with any GPT model
  3. Tool calls appear as raw JSON text instead of being invoked

Suggested Fix

Mirror the existing azure provider pattern:

openai: async () => {
  return {
    autoload: false,
    async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
      if (options?.['useCompletionUrls']) {
        return sdk.chat(modelID)
      }
      return sdk.responses(modelID)
    },
    options: ,
  }
},

Users opt in via opencode.json:

{
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://your-proxy/v1",
        "useCompletionUrls": true
      }
    }
  }
}

OpenCode Version

1.2.6


描述

使用 openai provider 并将 baseURL 指向仅支持 Chat Completions API 的中间层/代理时,工具调用会以原始 JSON 文本的形式输出,而不是被正常执行。

根本原因:provider.ts 中 openai provider 硬编码使用 sdk.responses(modelID),没有任何 fallback 到 sdk.chat(modelID)。

当代理返回 Chat Completions 格式的响应时,Responses API 的流式解析器无法匹配事件格式,导致 tool_calls 字段被忽略,内容落入 text-delta 路径,最终在聊天界面输出原始 JSON。

注:azure 和 azure-cognitive-services provider 已通过 options.useCompletionUrls 标志正确处理了这一情况,同样的模式可以应用到 openai provider。

复现步骤

  1. 使用 openai provider 配置自定义 baseURL,指向仅支持 Chat Completions 的代理
  2. 用任意 GPT 模型开启会话
  3. 工具调用以原始 JSON 文本形式出现在输出中,而非被正常调用

建议修复

为 openai provider 添加 useCompletionUrls 支持,参考现有的 azure provider 实现(见上方英文部分)。

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 25, 2026
  2. github-actions commented on Feb 25, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Please check if your issue is already covered by these, and consider commenting there instead.

  3. conglinyizhi commented on Feb 25, 2026

    @conglinyizhi
    Author

    Hit #7793

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions