package ocaml-ai-sdk
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4f3f22ae61d360b994cd75323bcb6b6bf915f6755fd1e7bab6844ca8a240c1e7
sha512=3c52b17096da818f5d3bcf9fe16826c3bec4533d6a1681e8ba0f957f37ee4f425696017cb78f1a24732f8851010d436cf446f873b72b6a4f5004d6b492072abf
doc/ocaml-ai-sdk.ai_provider_openrouter/Ai_provider_openrouter/Cache_control_options/index.html
Module Ai_provider_openrouter.Cache_control_optionsSource
Per-content-part cache control via Provider_options for OpenRouter.
Mirrors Ai_provider_anthropic.Cache_control_options but uses Openrouter_cache_control.t. Resolution follows upstream getCacheControl() in src/chat/convert-to-openrouter-chat-messages.ts: look up the OpenRouter key first, then fall back to the Anthropic Cache_control_options.Cache key for compatibility with prompts written against the Anthropic-native provider.
Supported placement today:
- System message: pass via
Generate_text.system_provider_options/Stream_text.system_provider_options. - User text and file parts: attach to each
Prompt.user_part'sprovider_options. - Assistant text, file, reasoning, and tool_call parts: attach to each
Prompt.assistant_part'sprovider_options. - Tool results: attach to each
Prompt.tool_result'sprovider_options.
Not yet supported: Message-level provider_options on Prompt.User, Prompt.Assistant, and Prompt.Tool variants. Upstream resolves messagePO ?? partPO, but our Prompt.message type does not carry provider_options on those constructors — only on Prompt.System. Set the cache marker on the specific part (typically the last text part for a multi-part user message) or on the tool_result instead. Tracked in docs/plans/2026-03-26-v3-roadmap.md under "Message-level provider_options on User / Assistant / Tool prompts".
type Ai_provider.Provider_options.key += | Cache : Cache_control.t Ai_provider.Provider_options.key(*GADT key for per-part cache control on OpenRouter requests.
*)
val with_cache_control :
?cache_control:Cache_control.t ->
Ai_provider.Provider_options.t ->
Ai_provider.Provider_options.tAdd cache control to provider options. No-op if cache_control is None.
Extract cache control from provider options.
Resolution order (mirrors upstream openrouter.cacheControl ?? openrouter.cache_control ?? anthropic.cacheControl ?? anthropic.cache_control):
Openrouter_cache_control_options.Cache(this module's key)Ai_provider_anthropic.Cache_control_options.Cache(record rebuilt at the boundary)