Skip to content

Add prompt caching schema support for structured system/developer content #229

@dcox761

Description

@dcox761

Specifically I would like to enable caching with RooCode using Claude models as it significantly reduces cost with the huge number of tokens used.

Bedrock supports prompt caching via cachePoint blocks, but the gateway currently only accepts string content for system and developer messages. The OpenAI SDK sends cache control hints as structured content:

{
  "role": "system",
  "content": [
    {"type": "text", "text": "You are a helpful assistant.", "cache_control": {"type": "ephemeral"}}
  ]
}

This structured format is silently rejected or ignored.

Proposed solution

  1. Add a CacheControl model and cache_control field on TextContent in the schema
  2. Change SystemMessage.content and DeveloperMessage.content to accept str | list[TextContent]
  3. Handle list-format system/developer messages in _parse_system_prompts — extract text and emit Bedrock cachePoint blocks when cache_control is set
  4. Emit cachePoint in _parse_content_parts for user message content with cache markers

This allows clients using the OpenAI SDK's prompt caching pattern to have their cache hints translated to Bedrock's native cachePoint format.

Files: src/api/schema.py, src/api/models/bedrock.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions