Skip to content

🧭 feat: Add OpenRouter Prompt Cache Setting#13029

Merged
danny-avila merged 13 commits into
devfrom
danny-avila/openrouter-prompt-cache
May 9, 2026
Merged

🧭 feat: Add OpenRouter Prompt Cache Setting#13029
danny-avila merged 13 commits into
devfrom
danny-avila/openrouter-prompt-cache

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Summary

I added OpenRouter prompt caching as a custom endpoint parameter and wired it through the OpenAI endpoint config path so LibreChat can pass promptCache to the agents OpenRouter client without leaking it to standard OpenAI requests.

  • Added OpenRouter parameter settings based on OpenAI plus the promptCache toggle.
  • Added OpenRouter schema parsing for defaultParamsEndpoint: openrouter, preserving promptCache for custom endpoint presets and compact conversations.
  • Passed promptCache into OpenRouter LLM config while respecting defaultParams, addParams, and dropParams.
  • Documented the OpenRouter custom endpoint example in librechat.example.yaml.
  • Added API and data-provider coverage for config, model option handling, and parser behavior.

Change Type

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Testing

  • Ran npx jest src/endpoints/openai/llm.spec.ts src/endpoints/openai/config.spec.ts --runInBand --coverage=false from packages/api.
  • Ran npx jest specs/parsers.spec.ts --runInBand --coverage=false from packages/data-provider.
  • Ran npx tsc --noEmit --project packages/data-provider/tsconfig.json.
  • Ran focused ESLint on the touched API and data-provider files.
  • Tried npx tsc --noEmit --project packages/api/tsconfig.json; it fails on the existing Redis client type mismatch in packages/api/src/cache/cacheFactory.ts:47, outside this change.

Test Configuration:

  • Local worktree based on latest origin/dev at implementation time.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Copilot AI review requested due to automatic review settings May 8, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 openRouterSchema and wired it into parseConvo / parseCompactConvo via defaultParamsEndpoint: openrouter support.
  • Exposed promptCache in OpenRouter parameter UI/config settings and validated it through custom endpoint config loading.
  • Passed promptCache through the OpenAI endpoint LLM config path only when useOpenRouter is true, with Jest coverage and updated librechat.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.

Comment on lines 23 to +38
@@ -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,
Comment on lines 291 to 307
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,
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila marked this pull request as ready for review May 8, 2026 20:40
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@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: 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".

Comment on lines +291 to +292
if (useOpenRouter && enablePromptCache === true) {
llmConfig.promptCache = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila force-pushed the danny-avila/openrouter-prompt-cache branch from 10867c6 to a905b4a Compare May 9, 2026 00:07
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

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

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

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

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13029 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

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

@danny-avila danny-avila merged commit 8a654dc into dev May 9, 2026
15 checks passed
@danny-avila danny-avila deleted the danny-avila/openrouter-prompt-cache branch May 9, 2026 15:46
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request May 11, 2026
* 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
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
* 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
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