fix(inference): route codex requests to non-versioned backends#1140
Open
cosmicnet wants to merge 1 commit intoNVIDIA:mainfrom
Open
fix(inference): route codex requests to non-versioned backends#1140cosmicnet wants to merge 1 commit intoNVIDIA:mainfrom
cosmicnet 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.
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..]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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