feat: forward cache routing headers for Responses API prompt caching#165
Merged
mcowger merged 2 commits intomcowger:mainfrom Apr 15, 2026
Merged
Conversation
Contributor
Author
|
The The workflow likely needs |
7a4d4a3 to
4abdd08
Compare
mcowger
requested changes
Apr 15, 2026
Owner
mcowger
left a comment
There was a problem hiding this comment.
Overall looks good, but it appears you accidentally captured some changes to the workflow definition.
Can you remove those (thanks for the note about the token fix) and then I'll merge?
Clients (Codex CLI, pi-agent, hermes-agent) send session_id and x-client-request-id headers for server-side cache routing. Without these headers, upstream providers (theclawbay, OpenAI) cannot route requests to the same backend server that holds cached prompt prefixes, causing every request to be a cache miss. Changes: - types/unified.ts: add cacheRoutingHeaders to UnifiedChatRequest - routes/inference/responses.ts: capture session_id and x-client-request-id from incoming request headers, with fallback to prompt_cache_key from the body - services/dispatcher.ts: forward cache routing headers to upstream in setupHeaders() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Codex CLI and pi-agent with openai-codex-responses wire API send requests to /v1/codex/responses. Register the same handler on both /v1/responses and /v1/codex/responses so codex clients can go through plexus without URL mismatch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6d8eb96 to
543b95c
Compare
Contributor
Author
|
Removed the workflow file changes -- force-pushed with only the 3 intended files:
Those workflow files came from a sync merge with upstream before branching. Sorry about that. |
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
session_idandx-client-request-idheaders from incoming Responses API requests to upstream providers for prompt cache routing/v1/codex/responsesroute alias so Codex CLI and pi-agent clients can connect through plexus without URL mismatchprompt_cache_keyfrom the request body when client headers are absentDetails
session_idandx-client-request-idheaders to route requests to the same backend server that holds cached prompt prefixes. Without these headers,prompt_cache_keyin the body is ineffective and every request is a full-price cache miss.codex-rs/codex-api/src/requests/headers.rs) sends these headers unconditionally. Third-party clients (pi-agent, hermes-agent) also send them. Plexus was silently dropping them insetupHeaders().responses.tsroute handler, attached toUnifiedChatRequest.cacheRoutingHeaders, and forwarded bydispatcher.tssetupHeaders(). When client headers are absent,prompt_cache_keyfrom the body is used as fallback./v1/codex/responsesalias is needed because pi-agent'sopenai-codex-responseswire API appends/codex/responsesto the base URL. The handler is shared -- no code duplication.Files changed
packages/backend/src/types/unified.tscacheRoutingHeaderstoUnifiedChatRequestinterfacepackages/backend/src/routes/inference/responses.tssession_id/x-client-request-idheaders withprompt_cache_keyfallback; extract handler for dual-route registration; add/v1/codex/responsesaliaspackages/backend/src/services/dispatcher.tscacheRoutingHeadersto upstream insetupHeaders()Configuration note
No config schema changes needed. Providers that support the Responses API can already be configured using the existing
api_base_urlrecord format:This makes
getProviderTypes()return['responses'], the incoming type matches directly, pass-through optimization activates, and the cache routing headers are forwarded.OAuth-based providers (
api_base_url: oauth://) also work -- the OAuth path handles codex responses natively.Verification
bun run typecheck-- zero type errors from changed files (all errors are pre-existing in test files, frontend, andindex.tsbundle types)cd packages/backend && bun test src/routes/inference/__tests__/auth.test.ts src/services/__tests__/dispatcher-failover.test.ts-- 35 tests pass, 0 failures192.168.66.12:4000against live config/SQLite:/v1/codex/responsesaccepts requests and returns responses correctlyopenai-codex-responseswire API (baseUrlhttp://192.168.66.12:4000/v1) successfully connects through plexus to theclawbay OAuth providersession_idandx-client-request-idheaders forwarded to upstream/v1/responsesendpoint -- pass-through optimization active for responses-to-responses routing