Skip to content

Fix: Route gpt-5.1 models to Responses API#384

Merged
cjgalione merged 2 commits intomainfrom
curtis-fix-gpt-5-1-responses-routing
Feb 5, 2026
Merged

Fix: Route gpt-5.1 models to Responses API#384
cjgalione merged 2 commits intomainfrom
curtis-fix-gpt-5-1-responses-routing

Conversation

@cjgalione
Copy link
Contributor

@cjgalione cjgalione commented Feb 5, 2026

Problem

Customers using gpt-5.x-codex models (e.g., gpt-5.1-codex, gpt-5.2-codex, gpt-5.3-codex) with:

  • The invoke() method for Braintrust prompts
  • Online scorers

Were encountering errors because these models were being routed to the Chat Completions API (/v1/chat/completions) instead of the Responses API (/v1/responses).

Root Cause

The proxy routing logic only matched:

  • gpt-5-pro
  • gpt-5-codex
  • o1-pro
  • o3-pro

The pattern startsWith("gpt-5-codex") matched "gpt-5-codex" but NOT "gpt-5.1-codex", "gpt-5.2-codex", "gpt-5.3-codex", etc.

Solution

Added a flexible pattern in packages/proxy/src/proxy.ts:2092-2093 that matches any gpt-5 codex variant:

if (
  bodyData?.model?.startsWith("o1-pro") ||
  bodyData?.model?.startsWith("o3-pro") ||
  bodyData?.model?.startsWith("gpt-5-pro") ||
  (bodyData?.model?.startsWith("gpt-5") &&
    bodyData?.model?.includes("-codex"))  // ← NEW: Future-proof pattern
) {
  return fetchOpenAIResponsesTranslate({ ... });
}

This pattern matches models that:

  1. Start with "gpt-5" AND
  2. Contain "-codex"

This is a conservative but future-proof approach that only routes codex variants to the Responses API, while leaving other gpt-5 models on the Chat Completions API.

Models Fixed

gpt-5-codex
gpt-5.1-codex
gpt-5.1-codex-mini
gpt-5.2-codex
gpt-5.3-codex
✅ Any future gpt-5.x-codex variants

Models Unchanged

Other gpt-5 models continue to use Chat Completions API:

  • gpt-5-mini
  • gpt-5-nano
  • gpt-5.1
  • gpt-5.1-2025-11-13
  • gpt-5.1-chat-latest

Testing

  • Updated test to validate flexible gpt-5.x-codex routing pattern
  • All 19 tests in openai.test.ts pass
  • Test validates that gpt-5.x-codex models with reasoning_effort: "minimal" are properly converted to reasoning.effort: "low" in the Responses API format

Impact

  • Invoke() method: Now works with all current and future gpt-5.x-codex models
  • Online scorers: Now work with all gpt-5.x-codex models
  • Customer unblocked: Can use model-agnostic prompts with gpt-5 codex variants across multiple providers
  • Future-proof: Automatically supports newly released codex models (gpt-5.2-codex, gpt-5.3-codex, etc.)

Files Changed

  • packages/proxy/src/proxy.ts - Added flexible gpt-5.x-codex routing pattern
  • packages/proxy/src/providers/openai.test.ts - Updated test to reflect flexible pattern

🤖 Generated with Claude Code

Previously, only gpt-5-pro and gpt-5-codex were routed to OpenAI's
Responses API. This caused gpt-5.1 models (including gpt-5.1-codex
and gpt-5.1-codex-mini) to incorrectly use the Chat Completions API,
resulting in errors.

This change adds gpt-5.1 model prefix to the routing logic so all
gpt-5.1 models (gpt-5.1, gpt-5.1-codex, gpt-5.1-codex-mini, etc.)
are properly routed to the Responses API via fetchOpenAIResponsesTranslate.

Fixes issue where customers using invoke() or online scorers with
gpt-5.1-codex models were getting errors due to incorrect endpoint routing.

Related models affected:
- gpt-5.1
- gpt-5.1-2025-11-13
- gpt-5.1-chat-latest
- gpt-5.1-codex
- gpt-5.1-codex-mini
@vercel
Copy link

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-proxy Ready Ready Preview, Comment Feb 5, 2026 10:51pm

Request Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 921a22954f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Updated routing logic to target all gpt-5 codex variants using a flexible
pattern that matches gpt-5-codex, gpt-5.1-codex, gpt-5.2-codex, gpt-5.3-codex,
and any future gpt-5.x-codex models.

Changes:
- Added flexible pattern: starts with 'gpt-5' AND contains '-codex' (proxy.ts:2092-2093)
- Updated test to validate gpt-5.x-codex routing (openai.test.ts)

Models affected:
- gpt-5-codex (existing)
- gpt-5.1-codex
- gpt-5.1-codex-mini
- gpt-5.2-codex (future)
- gpt-5.3-codex (future)
- Any future gpt-5.x-codex variants

Other gpt-5 models (gpt-5-mini, gpt-5.1, gpt-5.1-chat-latest, etc.) will
continue to use the Chat Completions API as before.

Fixes customer issue where gpt-5.x-codex models failed with invoke() and
online scorers due to incorrect endpoint routing.
bodyData?.model?.startsWith("gpt-5-pro") ||
bodyData?.model?.startsWith("gpt-5-codex")
(bodyData?.model?.startsWith("gpt-5") &&
bodyData?.model?.includes("-codex"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very tiny nit, i would probably test that it starts with "gpt" and ends with "codex" to be safe. but i dont think it matters.

@cjgalione cjgalione merged commit da4155c into main Feb 5, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants