The framework provides adapter from AI DIAL Chat Completion API to Anthropic Messages API.
Automatic caching is the simplest way to use prompt caching. A single top-level cache breakpoint instructs Anthropic to automatically apply a cache point to the last cacheable block of the request. This is ideal for multi-turn conversations where the growing message history should be cached automatically. See Automatic caching in the Anthropic docs.
To enable automatic caching, set custom_fields.cache_breakpoint at the top level of the Chat Completion request:
Top-level cache breakpoint
{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "user", "content": "Hello!"}
],
"custom_fields": {
"cache_breakpoint": {}
}
}Explicit cache breakpoints give fine-grained control over which parts of the prompt get cached. You can place a cache breakpoint on individual system messages, user/assistant messages, or tool definitions. See Explicit cache breakpoints in the Anthropic docs.
To add a breakpoint, set custom_fields.cache_breakpoint on a message or tool object:
System cache breakpoint
{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant with extensive knowledge.",
"custom_fields": {
"cache_breakpoint": {}
}
},
{"role": "user", "content": "Hello!"}
]
}Message cache breakpoint
{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": "Here is a long document: ...",
"custom_fields": {
"cache_breakpoint": {}
}
},
{"role": "user", "content": "Summarize it."}
]
}Tools cache breakpoint
{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "user", "content": "What's the weather?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
},
"custom_fields": {
"cache_breakpoint": {}
}
}
]
}A cache breakpoint may include an optional ttl field. Supported values are 5m (5 minutes, default) and 1h (one hour). The ttl field is supported on both top-level and explicit breakpoints. See TTL support in the Anthropic docs.
Top-level cache breakpoint with TTL
{
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "user", "content": "Hello!"}
],
"custom_fields": {
"cache_breakpoint": {
"ttl": "1h"
}
}
}This project requires Python ≥3.11 and Poetry ≥2.1.1 for dependency management.
-
Install Poetry. See the official installation guide.
-
(Optional) Specify custom Python or Poetry executables in
.env.dev. This is useful if multiple versions are installed. By default,pythonandpoetryare used.POETRY_PYTHON=path-to-python-exe POETRY=path-to-poetry-exe
-
Create and activate the virtual environment:
make init_env source .venv/bin/activate -
Install project dependencies (including linting, formatting, and test tools):
make install
Run the linting before committing:
make lintTo auto-fix formatting issues run:
make formatRun unit tests locally for available python versions:
make testRun unit tests for the specific python version:
make test PYTHON=3.13To remove the virtual environment and build artifacts run:
make cleanTo build the package run:
make buildTo publish the package to PyPI run:
make publishYou may optionally install Git hooks that will automatically run the linting step on Git push. You only need to do it once for the given repository.
make install_git_hooksImportant
This command doesn't work if you have already installed Git hooks locally or globally.