The client: the configured HttpClient and the Messages calls.
make builds it; Service(http_client, create_message, create_message_stream) makes one of two functions (a test double,
say).
Attributes#
| Attribute | Type | Description |
|---|---|---|
http_client | HttpClientService[HttpClientError] = http_client | |
max_response_bytes | ByteSize = max_response_bytes |
Functions#
__init__#
__init__(http_client, create_message, create_message_stream, max_response_bytes=P.DEFAULT_MAX_RESPONSE_BYTES) -> None| Parameter | Type | Description |
|---|---|---|
http_client | HttpClientService[HttpClientError] | |
create_message | CreateMessage | |
create_message_stream | CreateMessageStream | |
max_response_bytes | ByteSize = P.DEFAULT_MAX_RESPONSE_BYTES |
def __init__(
self,
http_client: HttpClientService[HttpClientError],
create_message: CreateMessage,
create_message_stream: CreateMessageStream,
max_response_bytes: ByteSize = P.DEFAULT_MAX_RESPONSE_BYTES,
) -> None:
self.http_client = http_client
self._create_message = create_message
self._create_message_stream = create_message_stream
self.max_response_bytes = max_response_bytescreate_message#
create_message(payload, params=None) -> Effect[tuple[W.Message, HttpClientResponse], AiError]Create a message: POST /v1/messages?beta=true with
payload, params giving the anthropic-beta and
anthropic-version headers; an AnthropicConfig in context
transforms the client for this call. The decoded message and the
response. Every failure is an AiError: an error status maps to
its reason (a 429 to a RateLimitError), a malformed body to an
InvalidResponseError.
| Parameter | Type | Description |
|---|---|---|
payload | Payload | |
params | MessageParams | None = None |
Returns Effect[tuple[W.Message, HttpClientResponse], AiError]
def create_message(
self, payload: Payload, params: MessageParams | None = None, /
) -> Effect[tuple[W.Message, HttpClientResponse], AiError]:
"""Create a message: ``POST /v1/messages?beta=true`` with
``payload``, ``params`` giving the ``anthropic-beta`` and
``anthropic-version`` headers; an ``AnthropicConfig`` in context
transforms the client for this call. The decoded message and the
response. Every failure is an ``AiError``: an error status maps to
its reason (a 429 to a ``RateLimitError``), a malformed body to an
``InvalidResponseError``."""
return self._create_message(payload, params)create_message_stream#
create_message_stream(payload, params=None) -> Effect[tuple[HttpClientResponse, Stream[W.MessageStreamEvent, AiError]], AiError]Create a message as server-sent events: POST /v1/messages
with payload and "stream": true. The response and its
events (pings left out), ending after message_stop. Failures,
of the request or of the stream, are AiError s mapped as in
create_message.
| Parameter | Type | Description |
|---|---|---|
payload | Payload | |
params | MessageParams | None = None |
Returns Effect[tuple[HttpClientResponse, Stream[W.MessageStreamEvent, AiError]], AiError]
def create_message_stream(
self, payload: Payload, params: MessageParams | None = None, /
) -> Effect[tuple[HttpClientResponse, Stream[W.MessageStreamEvent, AiError]], AiError]:
"""Create a message as server-sent events: ``POST /v1/messages``
with ``payload`` and ``"stream": true``. The response and its
events (pings left out), ending after ``message_stop``. Failures,
of the request or of the stream, are ``AiError`` s mapped as in
``create_message``."""
return self._create_message_stream(payload, params)