Skip to content

OpenRouter model catalog parsing fails on startup #24286

Open

Description

@alexandrelealbess

Summary

@openai/codex / codex-cli v0.133.0 fails during startup when using an OpenRouter model provider profile. The failure happens before the prompt is handled, while codex_models_manager refreshes the available model catalog.

Environment

Reproduction

  1. Configure OpenRouter in ~/.codex/config.toml:

    [model_providers.openrouter]
    name = "OpenRouter"
    base_url = "https://openrouter.ai/api/v1"
    env_key = "OPENROUTER_API_KEY"
    wire_api = "responses"
    
    [profiles.or-opus]
    model_provider = "openrouter"
    model = "anthropic/claude-opus-4.7"
    
    [profiles.or-sonnet]
    model_provider = "openrouter"
    model = "anthropic/claude-sonnet-4.6"
    
    [profiles.or-cheap]
    model_provider = "openrouter"
    model = "deepseek/deepseek-v4-pro"
  2. Export a valid OpenRouter API key:

    export OPENROUTER_API_KEY=...
  3. Run Codex with the OpenRouter profile:

    codex exec --profile or-cheap "Responda apenas: ok"

Expected

Codex should start normally, use the configured OpenRouter profile, send the prompt to deepseek/deepseek-v4-pro, and return the model response.

Actual

Codex fails during startup while refreshing the model catalog:

2026-05-23T23:59:02.585758Z ERROR codex_models_manager::manager:
  failed to refresh available models: stream disconnected before completion:
  failed to decode models response: missing field `models` at line 1 column 426380;
  body: {"data":[{"id":"qwen/qwen3.7-max","canonical_slug":"qwen/qwen3.7-max-20260520",...

The command does not reach the actual prompt execution path. OpenRouter via Codex is therefore unusable with this configuration.

Root cause hypothesis

This looks like a model catalog response shape mismatch.

The OpenRouter models endpoint returns a JSON payload shaped like:

{"data":[...]}

The error suggests codex_models_manager is trying to deserialize the response as a payload containing a top-level models field:

missing field `models` at line 1 column 426380

Because the OpenRouter catalog response is large, the failure is reported after reading more than 426 KB of JSON. The startup path appears to either require the wrong schema for OpenRouter's /models response, or to route the OpenRouter model refresh through a parser intended for another provider's catalog format.

Validation that OpenRouter API is OK

Calling OpenRouter directly with the same API key and target model works:

curl -s https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek/deepseek-v4-pro","messages":[{"role":"user","content":"Responda apenas: ok"}],"max_tokens":10}'

Observed response:

{
  "id": "gen-1779581673-4UydX3iYJz0VXDnxLTFv",
  "model": "deepseek/deepseek-v4-pro-20260423",
  "provider": "Novita"
}

This confirms the OpenRouter API key, account, model name, and provider routing are working outside Codex.

Workaround

  • Call OpenRouter directly via curl or another OpenAI-compatible client.
  • Use Codex with the default subscription/auth profile instead of the OpenRouter profile.
  • If there is or will be a flag/config option to disable online model catalog refresh for custom providers, that would likely avoid this startup blocker.

Related

Searches attempted:

  • gh issue list -R openai/codex --search "openrouter" --state all
  • gh issue list -R openai/codex --search "models manager refresh" --state all
  • gh issue list -R openai/codex --search "missing field models" --state all

The local gh calls failed with error connecting to api.github.com, so related issue discovery was completed via web search instead.

Possibly related OpenRouter/custom-provider issues:

No exact duplicate for missing field models on the OpenRouter catalog response was found in the available search results.

Activity

  1. added
    bug
    CLI
    custom-model
    on May 24, 2026
  2. yui-stingray commented on May 24, 2026

    @yui-stingray

    This looks related to the same missing field models failure mode reported in #22205, though this repro appears to hit OpenRouter during startup instead of Azure during exec.

    From the current main evidence, codex-rs/model-provider/src/models_endpoint.rs calls list_models, codex-rs/codex-api/src/endpoint/models.rs deserializes the response body with serde_json::from_slice::<ModelsResponse>(&resp.body), and codex-rs/protocol/src/openai_models.rs defines ModelsResponse as expecting a top-level models: Vec<ModelInfo> field.

    So if OpenRouter's /models response is really {"data":[...]}, this probably needs either provider-specific parsing for that catalog shape or a path that skips remote catalog refresh when the user has already configured an explicit custom model/catalog.

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

    CLIbugcustom-model

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions