Skip to content

distill::backends::base::TeacherBackend

More...

Inherits from ABC

Inherited by distill.backends.anthropic_backend.AnthropicBackend, distill.backends.openai_backend.OpenAIBackend

Public Functions

Name
init(self self, dict endpoint_config, str model_id, str api_key)
dict generate(self self, list messages, int max_tokens, float temperature, ** kwargs)
str backend_type(self self)
float estimate_cost(int prompt_tokens, int completion_tokens)

Protected Attributes

Name
_endpoint_config
_model_id
_api_key

Detailed Description

class distill::backends::base::TeacherBackend;
Abstract interface that every teacher API backend must implement.

Concrete backends wrap their respective SDKs (openai, anthropic),
converting native responses into a uniform response dict with keys:
    content:           str   — the completion text
    prompt_tokens:     int   — tokens consumed by the prompt
    completion_tokens: int   — tokens produced by the completion
    raw_response:      object — the original SDK response object

Public Functions Documentation

function init

__init__(
    self self,
    dict endpoint_config,
    str model_id,
    str api_key
)

Reimplemented by: distill::backends::anthropic_backend::AnthropicBackend::init, distill::backends::openai_backend::OpenAIBackend::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 generate

dict generate(
    self self,
    list messages,
    int max_tokens,
    float temperature,
    ** kwargs
)

Reimplemented by: distill::backends::anthropic_backend::AnthropicBackend::generate, distill::backends::openai_backend::OpenAIBackend::generate

Send a completion request and return a uniform response dict.

Returns:
    dict with keys ``content``, ``prompt_tokens``,
    ``completion_tokens``, ``raw_response``.

function backend_type

str backend_type(
    self self
)

Reimplemented by: distill::backends::anthropic_backend::AnthropicBackend::backend_type, distill::backends::openai_backend::OpenAIBackend::backend_type

Return a short identifier for this backend (e.g. ``"openai"``).```


### function estimate_cost

```python
static float estimate_cost(
    int prompt_tokens,
    int completion_tokens
)
Estimate the USD cost of a completion.

Default formula: (prompt_tokens * 0.27 + completion_tokens * 1.10) / 1_000_000.
Subclasses that use different pricing SHOULD override this.

Protected Attributes Documentation

variable _endpoint_config

_endpoint_config;

variable _model_id

_model_id;

variable _api_key

_api_key;

Updated on 2026-07-25 at 22:56:57 +0000