fix: always use array content for system messages with block-level cache control#399
Merged
robert-j-y merged 3 commits intomainfrom Feb 9, 2026
Merged
Conversation
…ontrol When cache control is specified on a system message via providerOptions, the content is now converted to array format with cache_control on the text block, matching the existing behavior for user messages. This ensures consistent Anthropic prompt caching behavior across all message types. Fixes #389 Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
louisgv
reviewed
Feb 9, 2026
| export interface ChatCompletionSystemMessageParam { | ||
| role: 'system'; | ||
| content: string; | ||
| content: string | Array<ChatCompletionContentPartText>; |
Contributor
There was a problem hiding this comment.
I'd argue to rid this union and just use an array for this
louisgv
approved these changes
Feb 9, 2026
Contributor
louisgv
left a comment
There was a problem hiding this comment.
Overall lgtm 👍
Would double check that the cache_control is not duplicated between top level and child level part
…ol duplication - System message content is always array format (no string union) - Removed message-level cache_control from ChatCompletionSystemMessageParam - cache_control only appears on content blocks, never at message level - Addresses PR review comments from louisgv Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Merged
kesavan-byte
pushed a commit
to osm-API/ai-sdk-provider
that referenced
this pull request
Feb 13, 2026
…che control (OpenRouterTeam#399) * fix: convert system message to array content with block-level cache control When cache control is specified on a system message via providerOptions, the content is now converted to array format with cache_control on the text block, matching the existing behavior for user messages. This ensures consistent Anthropic prompt caching behavior across all message types. Fixes OpenRouterTeam#389 Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * refactor: always use array format for system messages, no cache_control duplication - System message content is always array format (no string union) - Removed message-level cache_control from ChatCompletionSystemMessageParam - cache_control only appears on content blocks, never at message level - Addresses PR review comments from louisgv Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> * chore: update changeset to minor Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Description
Fixes #389
System messages now always use array content format, with
cache_controlplaced exclusively on content blocks (never at the message level). This eliminates thestring | Arrayunion and prevents any possibility ofcache_controlduplication between message and block levels.Before:
{ "role": "system", "content": "...", "cache_control": { "type": "ephemeral" } }After (with cache control):
{ "role": "system", "content": [{ "type": "text", "text": "...", "cache_control": { "type": "ephemeral" } }] }After (without cache control):
{ "role": "system", "content": [{ "type": "text", "text": "..." }] }Key changes:
src/types/openrouter-chat-completions-input.ts):ChatCompletionSystemMessageParam.contentis nowArray<ChatCompletionContentPartText>(no string union). Removed message-levelcache_controlfield entirely.src/chat/convert-to-openrouter-chat-messages.ts): System content always converts to array format.cache_controlis conditionally spread onto the block only when present.e2e/issues/issue-389-system-cache-control.test.ts): Verifies cache write/read behavior with system message cache control.Cache control audit (no duplication)
Validation
cache_controlis the canonical Anthropic pattern per their docsChatCompletionSystemMessageParamis not exported publicly — type change is internal onlyHuman review checklist
...(cacheControl && { cache_control: cacheControl })correctly omitscache_controlwhen undefinedcache_controlappears at both message and block level for any message typeChecklist
pnpm stylecheckandpnpm typecheckpnpm testand all tests passChangeset
pnpm changesetto create a changeset fileLink to Devin run: https://app.devin.ai/sessions/ac3d2be5447d40518a2b0ecac907e315
Requested by: @robert-j-y