llumpy.providers.AsyncAnthropicClient

class AsyncAnthropicClient(model)[source]

Bases: AsyncModelClient

Async client interface for interacting with Anthropic API

Parameters:

model (str)

__init__(model)[source]

Initialize connection to Anthropic

Parameters:

model (str) – LLM to use

Raises:

EnvironmentError – If the ‘ANTHROPIC_API_KEY’ env var is not defined

Methods

__init__(model)

Initialize connection to Anthropic

extract_text(response)

Extract LLM response text from Anthropic object

prompt_many(conversation, *[, handler, retries])

Prompt a model with a full conversation

prompt_one(message, *[, handler, retries])

Prompt a model with a single user message

prompt_stream(conversation, **prompt_kwargs)

Prompt a model and stream the response

system([content, file])

Init conversation with a system message

user([content, file])

Init conversation with a user message

validate()

Verify Anthropic key is valid and has access to the requested model

vendor_prompt(conversation, **prompt_kwargs)

Prompt a model for Anthropic chat completion

vendor_prompt_stream(conversation, ...)

Prompt a model for a streamed Anthropic chat completion

Attributes

model

Name of the model

extract_text(response)[source]

Extract LLM response text from Anthropic object

Parameters:

response (Message | Annotated[TextEvent | CitationEvent | ThinkingEvent | SignatureEvent | InputJsonEvent | RawMessageStartEvent | RawMessageDeltaEvent | MessageStopEvent | RawContentBlockStartEvent | RawContentBlockDeltaEvent | ContentBlockStopEvent, PropertyInfo(alias='None', format=None, format_template='None', discriminator='type')]) – Anthropic chat response

Returns:

Text message if present, else None

Return type:

str | None

async validate()[source]

Verify Anthropic key is valid and has access to the requested model

Raises:
  • InvalidAPIKeyError – If the Anthropic key is invalid

  • ModelNotFoundError – If requested model does not exist

  • PermissionDeniedError – If key does not have access to requested model

Return type:

None

async vendor_prompt(conversation, **prompt_kwargs)[source]

Prompt a model for Anthropic chat completion

Parameters:
  • conversation (Conversation) – Messages to send to llm

  • prompt_kwargs (Any) – kwargs for chat

Returns:

Chat completion

Return type:

Message

async vendor_prompt_stream(conversation, **prompt_kwargs)[source]

Prompt a model for a streamed Anthropic chat completion

Parameters:
  • conversation (Conversation) – Messages to send to llm

  • prompt_kwargs (Any) – kwargs for chat

Returns:

Chat completion stream

Return type:

AsyncStream[Annotated[RawMessageStartEvent | RawMessageDeltaEvent | RawMessageStopEvent | RawContentBlockStartEvent | RawContentBlockDeltaEvent | RawContentBlockStopEvent, PropertyInfo(alias=’None’, format=None, format_template=’None’, discriminator=’type’)]]