Skip to content

fix(inference): route codex requests to non-versioned backends#1140

Open
cosmicnet wants to merge 1 commit intoNVIDIA:mainfrom
cosmicnet:fix/codex-v1-prefix-forwarding
Open

fix(inference): route codex requests to non-versioned backends#1140
cosmicnet wants to merge 1 commit intoNVIDIA:mainfrom
cosmicnet:fix/codex-v1-prefix-forwarding

Conversation

@cosmicnet
Copy link
Copy Markdown

Summary

This is the separate OpenAI Codex OAuth follow-up requested in #618. It adds Codex-specific matching for /v1/codex/* requests and rewrites only that Codex path when forwarding to non-versioned upstream backends such as chatgpt.com/backend-api. Multi-model routing and Ollama support from #618 are intentionally not included.

Related Issue

Follow-up to #618.

This specifically matches the review request there to split out just the Codex path fix into a narrowly scoped PR.

Changes

  • add sandbox inference matching for POST /v1/codex/* as openai_responses
  • rewrite forwarded OpenAI Codex OAuth requests from /v1/codex/... to /codex/... for non-versioned upstream bases
  • preserve existing behavior for non-Codex /v1/* routes
  • add focused router unit and integration coverage for the Codex path handling
  • update user-facing inference docs and examples to document OpenAI Codex OAuth support through https://inference.local/v1

Testing

  • mise run pre-commit passes
  • Unit tests added/updated
  • E2E tests added/updated (if applicable)

Manual / focused testing:

  • manually tested from a fresh OpenShell setup
  • verified with curl requests to https://inference.local/v1 within the sandbox
  • verified OpenClaw OpenAI OAuth Codex through https://inference.local/v1
  • confirmed Codex requests are forwarded to non-versioned upstreams without the extra /v1 prefix
  • cargo test -p openshell-router --lib verify_
  • cargo test -p openshell-cli --test sandbox_create_lifecycle_integration sandbox_create_keeps_sandbox_with_forwarding -- --exact --nocapture
  • mise run docs

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

Add a Codex-specific inference matcher for /v1/codex/* requests and strip the intercepted /v1 prefix before forwarding upstream when the backend base URL does not carry a version segment.

This keeps inference.local-compatible Codex requests pointed at non-versioned upstreams such as chatgpt.com/backend-api/codex/responses, with focused unit and integration coverage for the forwarded path shape.

Signed-off-by: Lyle Hopkins <lyle@cosmicnetworks.com>
Copilot AI review requested due to automatic review settings May 2, 2026 22:24
@cosmicnet cosmicnet requested a review from a team as a code owner May 2, 2026 22:24
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 2, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class support for OpenAI Codex OAuth request paths (/v1/codex/*) in the sandbox inference matcher and ensures those requests are forwarded correctly to non-versioned upstream bases (e.g. chatgpt.com/backend-api) by stripping the /v1 prefix only for Codex paths.

Changes:

  • Add sandbox L7 inference pattern matching for POST /v1/codex/* as openai_responses.
  • Rewrite forwarded Codex paths from /v1/codex/... to /codex/... for non-versioned upstream bases.
  • Add targeted unit + integration tests and update inference docs/examples to document Codex OAuth support via https://inference.local/v1.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/local-inference/README.md Documents the new /v1/codex/* routing pattern.
docs/inference/configure.mdx Adds guidance for configuring Codex OAuth clients against https://inference.local/v1.
docs/inference/about.mdx Lists /v1/codex/* as a supported request pattern.
crates/openshell-sandbox/src/l7/inference.rs Adds Codex path pattern + unit test for detection.
crates/openshell-router/src/backend.rs Updates backend URL construction to strip /v1 for Codex paths on non-versioned bases + unit test.
crates/openshell-router/tests/backend_integration.rs Adds integration coverage ensuring Codex forwarding strips /v1 correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 515 to +523
fn build_backend_url(endpoint: &str, path: &str) -> String {
let base = endpoint.trim_end_matches('/');
if base.ends_with("/v1") && (path == "/v1" || path.starts_with("/v1/")) {
return format!("{base}{}", &path[3..]);
}

if path == "/v1/codex" || path.starts_with("/v1/codex/") {
return format!("{base}{}", &path[3..]);
}
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