Class AnthropicApiClient
- Namespace
- AnthropicClient
- Assembly
- AnthropicClient.dll
Represents a client for interacting with the Anthropic API.
public class AnthropicApiClient : IAnthropicApiClient
- Inheritance
-
AnthropicApiClient
- Implements
- Inherited Members
Constructors
AnthropicApiClient(string, HttpClient)
Initializes a new instance of the AnthropicApiClient class.
public AnthropicApiClient(string apiKey, HttpClient httpClient)
Parameters
apiKey
stringThe API key to use for the client.
httpClient
HttpClientThe HTTP client to use for the client.
Exceptions
- ArgumentNullException
Thrown when the API key or HTTP client is null.
Methods
CancelMessageBatchAsync(string, CancellationToken)
Cancels a message batch asynchronously.
public Task<AnthropicResult<MessageBatchResponse>> CancelMessageBatchAsync(string batchId, CancellationToken cancellationToken = default)
Parameters
batchId
stringThe ID of the message batch to cancel.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<MessageBatchResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is MessageBatchResponse.
CountMessageTokensAsync(CountMessageTokensRequest, CancellationToken)
Counts the tokens in a message asynchronously.
public Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request, CancellationToken cancellationToken = default)
Parameters
request
CountMessageTokensRequestThe count message tokens request.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<TokenCountResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is TokenCountResponse.
CreateMessageAsync(MessageRequest, CancellationToken)
Creates a message asynchronously.
public Task<AnthropicResult<MessageResponse>> CreateMessageAsync(MessageRequest request, CancellationToken cancellationToken = default)
Parameters
request
MessageRequestThe message request to create.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<MessageResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T>.
CreateMessageAsync(StreamMessageRequest, CancellationToken)
Creates a message asynchronously and streams the response.
public IAsyncEnumerable<AnthropicEvent> CreateMessageAsync(StreamMessageRequest request, CancellationToken cancellationToken = default)
Parameters
request
StreamMessageRequestThe message request to create.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- IAsyncEnumerable<AnthropicEvent>
An asynchronous enumerable that yields the response event by event.
CreateMessageBatchAsync(MessageBatchRequest, CancellationToken)
Creates a batch of messages asynchronously.
public Task<AnthropicResult<MessageBatchResponse>> CreateMessageBatchAsync(MessageBatchRequest request, CancellationToken cancellationToken = default)
Parameters
request
MessageBatchRequestThe message batch request to create.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<MessageBatchResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is MessageBatchResponse.
DeleteMessageBatchAsync(string, CancellationToken)
Deletes a message batch asynchronously.
public Task<AnthropicResult<MessageBatchDeleteResponse>> DeleteMessageBatchAsync(string batchId, CancellationToken cancellationToken = default)
Parameters
batchId
stringThe ID of the message batch to delete.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<MessageBatchDeleteResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is MessageBatchDeleteResponse.
GetMessageBatchAsync(string, CancellationToken)
Gets a message batch asynchronously.
public Task<AnthropicResult<MessageBatchResponse>> GetMessageBatchAsync(string batchId, CancellationToken cancellationToken = default)
Parameters
batchId
stringThe ID of the message batch to get.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<MessageBatchResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is MessageBatchResponse.
GetMessageBatchResultsAsync(string, CancellationToken)
Gets the results of a message batch asynchronously.
public Task<AnthropicResult<IAsyncEnumerable<MessageBatchResultItem>>> GetMessageBatchResultsAsync(string batchId, CancellationToken cancellationToken = default)
Parameters
batchId
stringThe ID of the message batch to get the results for.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<IAsyncEnumerable<MessageBatchResultItem>>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is IAsyncEnumerable<T> where T is MessageBatchResultItem.
GetModelAsync(string, CancellationToken)
Gets a model by its ID asynchronously.
public Task<AnthropicResult<AnthropicModel>> GetModelAsync(string modelId, CancellationToken cancellationToken = default)
Parameters
modelId
stringThe ID of the model to get.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<AnthropicModel>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is AnthropicModel.
ListAllMessageBatchesAsync(int, CancellationToken)
Lists all message batches asynchronously.
public IAsyncEnumerable<AnthropicResult<Page<MessageBatchResponse>>> ListAllMessageBatchesAsync(int limit = 20, CancellationToken cancellationToken = default)
Parameters
limit
intThe maximum number of message batches to return in each page.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- IAsyncEnumerable<AnthropicResult<Page<MessageBatchResponse>>>
An asynchronous enumerable that yields the response as an AnthropicResult<T> where T is Page<T> where T is MessageBatchResponse.
ListAllModelsAsync(int, CancellationToken)
Lists all models asynchronously, returning every page of results.
public IAsyncEnumerable<AnthropicResult<Page<AnthropicModel>>> ListAllModelsAsync(int limit = 20, CancellationToken cancellationToken = default)
Parameters
limit
intThe maximum number of models to return in each page.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- IAsyncEnumerable<AnthropicResult<Page<AnthropicModel>>>
An asynchronous enumerable that yields the response as an AnthropicResult<T> where T is Page<T> where T is AnthropicModel.
ListMessageBatchesAsync(PagingRequest?, CancellationToken)
Lists the message batches asynchronously.
public Task<AnthropicResult<Page<MessageBatchResponse>>> ListMessageBatchesAsync(PagingRequest? request = null, CancellationToken cancellationToken = default)
Parameters
request
PagingRequestThe paging request to use for listing the message batches.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<Page<MessageBatchResponse>>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is Page<T> where T is MessageBatchResponse.
ListModelsAsync(PagingRequest?, CancellationToken)
Lists models asynchronously, returning a single page of results.
public Task<AnthropicResult<Page<AnthropicModel>>> ListModelsAsync(PagingRequest? request = null, CancellationToken cancellationToken = default)
Parameters
request
PagingRequestThe paging request to use for listing the models.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
- Task<AnthropicResult<Page<AnthropicModel>>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T> where T is Page<T> where T is AnthropicModel.