🧭 feat: Add OpenRouter Prompt Cache Setting#13029
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an OpenRouter-specific promptCache toggle for custom endpoints, ensuring the setting is preserved through conversation parsing/compaction and only forwarded to the OpenRouter client configuration (not standard OpenAI requests).
Changes:
- Added
openRouterSchemaand wired it intoparseConvo/parseCompactConvoviadefaultParamsEndpoint: openroutersupport. - Exposed
promptCachein OpenRouter parameter UI/config settings and validated it through custom endpoint config loading. - Passed
promptCachethrough the OpenAI endpoint LLM config path only whenuseOpenRouteris true, with Jest coverage and updatedlibrechat.example.yaml.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/data-provider/src/schemas.ts | Introduces openRouterSchema to preserve promptCache alongside OpenAI-like fields. |
| packages/data-provider/src/parsers.ts | Adds OpenRouter schema selection for defaultParamsEndpoint, including compact parsing support. |
| packages/data-provider/src/parameterSettings.ts | Adds OpenRouter parameter configuration including promptCache toggle. |
| packages/data-provider/specs/parsers.spec.ts | Tests that promptCache is preserved for OpenRouter custom endpoints in normal/compact parsing. |
| packages/api/src/types/openai.ts | Extends client options type to allow promptCache in LLM config. |
| packages/api/src/endpoints/openai/llm.ts | Applies promptCache via default/add/drop params and forwards it only for OpenRouter. |
| packages/api/src/endpoints/openai/llm.spec.ts | Adds tests ensuring promptCache is only emitted for OpenRouter and respects param precedence. |
| packages/api/src/endpoints/openai/config.spec.ts | Adds config-path coverage asserting promptCache flows from custom param definitions. |
| librechat.example.yaml | Documents defaultParamsEndpoint: openrouter and promptCache param definition example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -28,10 +31,11 @@ | |||
|
|
|||
| export type EndpointSchemaKey = EModelEndpoint; | |||
|
|
|||
| const endpointSchemas: Record<EndpointSchemaKey, EndpointSchema> = { | |||
| const endpointSchemas: Record<string, EndpointSchema> = { | |||
| [EModelEndpoint.openAI]: openAISchema, | |||
| [EModelEndpoint.azureOpenAI]: openAISchema, | |||
| [EModelEndpoint.custom]: openAISchema, | |||
| [Providers.OPENROUTER]: openRouterSchema, | |||
| type CompactEndpointSchema = | ||
| | typeof openAISchema | ||
| | typeof compactAssistantSchema | ||
| | typeof compactAgentsSchema | ||
| | typeof compactGoogleSchema | ||
| | typeof openRouterSchema | ||
| | typeof anthropicSchema | ||
| | typeof bedrockInputSchema; | ||
|
|
||
| const compactEndpointSchemas: Record<EndpointSchemaKey, CompactEndpointSchema> = { | ||
| const compactEndpointSchemas: Record<string, CompactEndpointSchema> = { | ||
| [EModelEndpoint.openAI]: openAISchema, | ||
| [EModelEndpoint.azureOpenAI]: openAISchema, | ||
| [EModelEndpoint.custom]: openAISchema, | ||
| [Providers.OPENROUTER]: openRouterSchema, | ||
| [EModelEndpoint.assistants]: compactAssistantSchema, | ||
| [EModelEndpoint.azureAssistants]: compactAssistantSchema, | ||
| [EModelEndpoint.agents]: compactAgentsSchema, |
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16335d6129
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (useOpenRouter && enablePromptCache === true) { | ||
| llmConfig.promptCache = true; |
There was a problem hiding this comment.
Honor OpenRouter promptCache for proxied endpoint names
promptCache is only forwarded when useOpenRouter is true, but useOpenRouter is derived in getOpenAIConfig from endpoint/baseURL string matching ("openrouter"), not from customParams.defaultParamsEndpoint. In setups that route OpenRouter through a custom domain or non-OpenRouter endpoint name, defaultParamsEndpoint: openrouter will preserve promptCache in parsing/UI yet this branch drops it before request construction, so the new prompt-cache toggle silently has no effect for those valid custom-endpoint configurations.
Useful? React with 👍 / 👎.
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
10867c6 to
a905b4a
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
GitNexus: 🚀 deployedThe |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
GitNexus: 🚀 deployedThe |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
* feat: add OpenRouter prompt cache setting * fix: type OpenRouter schema lookup * fix: honor proxied OpenRouter prompt cache * refactor: flatten endpoint schema fallback * chore: Bump `@librechat/agents` to version 3.1.82 * fix: Default OpenRouter prompt cache params * test: Align OpenRouter config expectations * test: Update OpenRouter default cache expectation * fix: Align OpenRouter Detection * chore: Bump `@librechat/agents` to version 3.1.83 * docs: Remove OpenRouter prompt cache setup note * refactor: Use provider enum for OpenRouter defaults * style: Format OpenRouter defaults guard
* feat: add OpenRouter prompt cache setting * fix: type OpenRouter schema lookup * fix: honor proxied OpenRouter prompt cache * refactor: flatten endpoint schema fallback * chore: Bump `@librechat/agents` to version 3.1.82 * fix: Default OpenRouter prompt cache params * test: Align OpenRouter config expectations * test: Update OpenRouter default cache expectation * fix: Align OpenRouter Detection * chore: Bump `@librechat/agents` to version 3.1.83 * docs: Remove OpenRouter prompt cache setup note * refactor: Use provider enum for OpenRouter defaults * style: Format OpenRouter defaults guard
Summary
I added OpenRouter prompt caching as a custom endpoint parameter and wired it through the OpenAI endpoint config path so LibreChat can pass
promptCacheto the agents OpenRouter client without leaking it to standard OpenAI requests.promptCachetoggle.defaultParamsEndpoint: openrouter, preservingpromptCachefor custom endpoint presets and compact conversations.promptCacheinto OpenRouter LLM config while respectingdefaultParams,addParams, anddropParams.librechat.example.yaml.Change Type
Testing
npx jest src/endpoints/openai/llm.spec.ts src/endpoints/openai/config.spec.ts --runInBand --coverage=falsefrompackages/api.npx jest specs/parsers.spec.ts --runInBand --coverage=falsefrompackages/data-provider.npx tsc --noEmit --project packages/data-provider/tsconfig.json.npx tsc --noEmit --project packages/api/tsconfig.json; it fails on the existing Redis client type mismatch inpackages/api/src/cache/cacheFactory.ts:47, outside this change.Test Configuration:
origin/devat implementation time.Checklist