distill::backends::anthropic_backend::AnthropicBackend¶
Inherits from distill.backends.base.TeacherBackend, ABC
Public Functions¶
| Name | |
|---|---|
| init(self self, dict endpoint_config, str model_id, str api_key) | |
| str | backend_type(self self) |
| dict | generate(self self, list messages, int max_tokens, float temperature, ** kwargs) |
Protected Functions¶
| Name | |
|---|---|
| dict | _convert_messages(list messages) |
Protected Attributes¶
| Name | |
|---|---|
| _client |
Additional inherited members¶
Public Functions inherited from distill.backends.base.TeacherBackend
| Name | |
|---|---|
| float | estimate_cost(int prompt_tokens, int completion_tokens) |
Protected Attributes inherited from distill.backends.base.TeacherBackend
| Name | |
|---|---|
| _endpoint_config | |
| _model_id | |
| _api_key |
Detailed Description¶
Teacher backend that talks to the Anthropic Messages API.
Used for endpoints whose ``apiType`` is ``"anthropic"`` — either a
direct Anthropic API connection or an Anthropic-compatible proxy.
Public Functions Documentation¶
function init¶
Reimplements: distill::backends::base::TeacherBackend::init
Initialise the backend with connection details.
Args:
endpoint_config: The resolved ``endpoints[name]`` dict from
pipeline.yaml (contains ``url``, ``apiType``, etc.).
model_id: The literal model identifier from the ``models``
config block (e.g. ``"deepseek-v4-pro[1m]"``).
api_key: The API key to authenticate requests.
function backend_type¶
Reimplements: distill::backends::base::TeacherBackend::backend_type
Return a short identifier for this backend (e.g. ``"openai"``).```
### function generate
```python
dict generate(
self self,
list messages,
int max_tokens,
float temperature,
** kwargs
)
Reimplements: distill::backends::base::TeacherBackend::generate
Send a completion via the Anthropic Messages API.
Converts OpenAI-format messages to Anthropic format, extracts
the first system message as the top-level ``system`` parameter,
and normalises the response into the uniform dict.
Extended thinking (``thinking={"type": "enabled", ...}``) is
passed through in ``**kwargs`` if supplied.
Returns:
Uniform dict with ``content``, ``prompt_tokens``,
``completion_tokens``, ``raw_response``.
Protected Functions Documentation¶
function _convert_messages¶
Convert an OpenAI-format message list to Anthropic API parameters.
Args:
messages: List of dicts with ``role`` and ``content`` keys.
Roles may be ``"system"``, ``"user"``, or ``"assistant"``.
Returns:
dict with keys ``system`` (str or None) and ``messages`` (list
of ``{"role": ..., "content": ...}`` dicts containing only
``"user"`` and ``"assistant"`` roles).
Protected Attributes Documentation¶
variable _client¶
Updated on 2026-07-25 at 22:56:57 +0000