fix(inference): route codex requests to non-versioned backends#1140
fix(inference): route codex requests to non-versioned backends#1140cosmicnet wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
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>
There was a problem hiding this comment.
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/*asopenai_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.
| 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..]); | ||
| } |
|
Thanks for splitting this out. The scoped I think this still needs a bit more wiring before it works reliably as a user-facing Codex OAuth path:
I think the clean fix is to model this as a Codex-specific inference provider/profile rather than treating it as generic |
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 aschatgpt.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
POST /v1/codex/*asopenai_responses/v1/codex/...to/codex/...for non-versioned upstream bases/v1/*routeshttps://inference.local/v1Testing
mise run pre-commitpassesManual / focused testing:
https://inference.local/v1within the sandboxhttps://inference.local/v1/v1prefixcargo test -p openshell-router --lib verify_cargo test -p openshell-cli --test sandbox_create_lifecycle_integration sandbox_create_keeps_sandbox_with_forwarding -- --exact --nocapturemise run docsChecklist