Skip to content

Codex CLI tools are incompatible with OpenRouter Responses API #537

@whhjdi

Description

@whhjdi

Problem

When using Codex CLI with OpenRouter as the backend via the Responses API, requests fail with a tool schema validation error. Codex CLI passes its internal tool definitions directly to the OpenRouter Responses API, but OpenRouter only accepts tools with openrouter:-prefixed type names.

Steps to Reproduce

  1. Configure Codex CLI to use OpenRouter as the provider
  2. Run any prompt that triggers tool use
  3. Observe the error returned from OpenRouter

Actual Behavior

{
  "error": {
    "code": "invalid_prompt",
    "message": "Invalid Responses API request"
  },
  "metadata": {
    "raw": [
      {
        "code": "invalid_union",
        "path": ["tools", 12],
        "message": "Invalid input",
        "errors": [
          { "code": "invalid_value", "values": ["openrouter:datetime"], "message": "Invalid input: expected \"openrouter:datetime\"" },
          { "code": "invalid_value", "values": ["openrouter:image_generation"], "message": "Invalid input: expected \"openrouter:image_generation\"" },
          { "code": "invalid_value", "values": ["openrouter:web_search"], "message": "Invalid input: expected \"openrouter:web_search\"" },
          { "code": "invalid_value", "values": ["openrouter:web_fetch"], "message": "Invalid input: expected \"openrouter:web_fetch\"" }
        ]
      }
    ]
  }
}

Expected Behavior

Codex CLI should either translate its tool definitions to a compatible format, or fall back to the Chat Completions API (/api/v1/chat/completions) when the provider doesn't fully support the Responses API tool schema.

Suggested Fix

Use /api/v1/chat/completions instead of the Responses API when the provider is OpenRouter, as it has broader compatibility with third-party tool formats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions