anthropic.Client

One model turn against Anthropic's Messages API (`POST https://api.anthropic.com/v1/messages`).

Reference version

Signature

class anthropic.Client

One model turn against Anthropic's Messages API (POST https://api.anthropic.com/v1/messages).

Construction reads no environment variable, so declaring a client is always safe; the credential resolves when a request is built.

Source:<builtin>/anthropic/messages.bamlbytes 27918576

Fields

model

string

api_key

ai.Credential | null

base_url

ai.Credential | null

request_timeout_ms

int | null

time_to_first_token_timeout_ms

int | null

max_tokens

int

temperature

float | null

top_p

float | null

top_k

int | null

stop_sequences

string[] | null

request_body

baml.json.json | null

headers

map<string, string> | null

query_params

map<string, string> | null

capture_wire

bool

Static methods

function

new

(
model: string = …,
api_key: ai.Credential | null = …,
base_url: ai.Credential | null = …,
request_timeout_ms: int | null = …,
time_to_first_token_timeout_ms: int | null = …,
max_tokens: int = …,
temperature: float | null = …,
top_p: float | null = …,
top_k: int | null = …,
stop_sequences: string[] | null = …,
thinking: anthropic.ThinkingConfig | null = …,
tool_choice: anthropic.ToolChoice | null = …,
request_body: baml.json.json | null = …,
headers: map<string, string> | null = …,
query_params: map<string, string> | null = …,
capture_wire: bool = …
) -> anthropic.Client

NOTE: the task spec named "claude-3-5-haiku-latest" as the default, but that model was retired (the API 404s on it); claude-haiku-4-5 is the current Haiku.

max_tokens defaults to 8192, not the engine's 4096 (PLAN §5): every model this client can address supports at least that, and 4096 silently truncates ordinary structured answers.

Instance methods

function

resolved_api_key

(
self
) -> string throws baml.errors.Io | baml.errors.ParseError | ai.errors.InvalidRequest

The request-time credential: an explicit value, else the provider's canonical one.

A missing credential is a CATCHABLE configuration error, thrown the same way the chat family reports one (_chat_headers): baml.env.get_or_panic used to raise an uncatchable panic that escaped catch_all — so it bypassed this client's own invoke normalize wrapper and turned the one misconfiguration every deployment hits first into a process-level failure.

function

resolved_base_url

(self) -> string | null throws baml.errors.Io | baml.errors.ParseError

The request-time base URL, or null for the provider default.

Implementations

ai.Client for anthropic.Client

Instance methods

function

id

(self) -> string
function

invoke

(
self,
input: ai.ModelTurnInput
) -> ai.ModelTurn throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure
function

render

(
self,
input: ai.ModelTurnInput
) -> baml.http.Request throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/anthropic/messages.bamlbytes 77288284

ai.stream.StreamingClient for anthropic.Client

Instance methods

function

invoke_stream

(
self,
input: ai.ModelTurnInput
) -> ai.stream.TurnStream throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Source:<builtin>/anthropic/messages.bamlbytes 82908574