Skip to content

fix(adapters): forward prompt_cache_key through openai-chat adapter (#217) - #224

Merged
lidge-jun merged 2 commits into
lidge-jun:devfrom
Wibias:codex/fix-prompt-cache-key-forward
Jul 21, 2026
Merged

lidge-jun merged 2 commits into
lidge-jun:devfrom
Wibias:codex/fix-prompt-cache-key-forward

Conversation

@Wibias

@Wibias Wibias commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

The Responses parser writes \prompt_cache_key\ to \options.promptCacheKey, but the \openai-chat\ adapter's \�uildRequest()\ never copied it into the outbound /chat/completions\ body. OpenAI's Chat Completions API accepts \prompt_cache_key\ as an optional string for prompt-cache affinity grouping.

Changes

  • Copy \parsed.options.promptCacheKey\ to \�ody.prompt_cache_key\ when set, omit when unset
  • The \openai-responses\ passthrough adapter already preserves it via _rawBody\ forwarding, so only \openai-chat\ needed the change

Tests

  • Added test asserting the field is forwarded when present
  • Added test asserting it is absent when not provided
  • All existing tests pass
  • Typecheck clean

Fixes #217

…217)

The Responses parser writes prompt_cache_key to options.promptCacheKey,
but the openai-chat adapter's buildRequest() never copied it into the
outbound /chat/completions body. OpenAI's Chat Completions API accepts
prompt_cache_key as an optional string for prompt-cache affinity grouping.

Copy parsed.options.promptCacheKey to body.prompt_cache_key when set,
omit when unset. The openai-responses passthrough adapter already
preserves it via _rawBody forwarding.

Add two tests: one asserting the field is forwarded when present,
one asserting it is absent when not provided.

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

Copy link
Copy Markdown

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: 5443c923ab

ℹ️ 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".

Comment thread src/adapters/openai-chat.ts Resolved
The previous unconditional copy forwarded prompt_cache_key to every
openai-chat backend. Strict providers (Groq, Cerebras, etc.) reject
unknown body fields, so this could break those routed requests.

Add an opt-in promptCacheKey boolean flag to OcxProviderConfig and
ProviderRegistryEntry, wired through router scalar backfill. The
adapter now only forwards body.prompt_cache_key when the provider
explicitly opts in. Default off, so no built-in provider is affected.

The built-in OpenAI provider uses openai-responses (passthrough),
which already preserves prompt_cache_key via _rawBody forwarding.
This flag is for user-configured openai-chat providers that document
prompt_cache_key support.

Tests updated to cover opt-in, opt-out, and unset cases.
@lidge-jun
lidge-jun merged commit 15d83ba into lidge-jun:dev Jul 21, 2026
7 checks passed
@Wibias
Wibias deleted the codex/fix-prompt-cache-key-forward branch July 25, 2026 07:01
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…idge-jun#217) (lidge-jun#224)

* fix(adapters): forward prompt_cache_key through openai-chat adapter (lidge-jun#217)

The Responses parser writes prompt_cache_key to options.promptCacheKey,
but the openai-chat adapter's buildRequest() never copied it into the
outbound /chat/completions body. OpenAI's Chat Completions API accepts
prompt_cache_key as an optional string for prompt-cache affinity grouping.

Copy parsed.options.promptCacheKey to body.prompt_cache_key when set,
omit when unset. The openai-responses passthrough adapter already
preserves it via _rawBody forwarding.

Add two tests: one asserting the field is forwarded when present,
one asserting it is absent when not provided.

* fix(adapters): gate prompt_cache_key behind provider opt-in flag

The previous unconditional copy forwarded prompt_cache_key to every
openai-chat backend. Strict providers (Groq, Cerebras, etc.) reject
unknown body fields, so this could break those routed requests.

Add an opt-in promptCacheKey boolean flag to OcxProviderConfig and
ProviderRegistryEntry, wired through router scalar backfill. The
adapter now only forwards body.prompt_cache_key when the provider
explicitly opts in. Default off, so no built-in provider is affected.

The built-in OpenAI provider uses openai-responses (passthrough),
which already preserves prompt_cache_key via _rawBody forwarding.
This flag is for user-configured openai-chat providers that document
prompt_cache_key support.

Tests updated to cover opt-in, opt-out, and unset cases.
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