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
apiKeystringThe API key to use for the client.
httpClientHttpClientThe HTTP client to use for the client.
Exceptions
- ArgumentNullException
Thrown when the API key or HTTP client is null.
Methods
CountMessageTokensAsync(CountMessageTokensRequest)
Counts the tokens in a message asynchronously.
public Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request)
Parameters
requestCountMessageTokensRequestThe count message tokens request.
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)
Creates a message asynchronously.
public Task<AnthropicResult<MessageResponse>> CreateMessageAsync(MessageRequest request)
Parameters
requestMessageRequestThe message request to create.
Returns
- Task<AnthropicResult<MessageResponse>>
A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult<T>.
CreateMessageAsync(StreamMessageRequest)
Creates a message asynchronously and streams the response.
public IAsyncEnumerable<AnthropicEvent> CreateMessageAsync(StreamMessageRequest request)
Parameters
requestStreamMessageRequestThe message request to create.
Returns
- IAsyncEnumerable<AnthropicEvent>
An asynchronous enumerable that yields the response event by event.
GetModelAsync(string)
Gets a model by its ID asynchronously.
public Task<AnthropicResult<AnthropicModel>> GetModelAsync(string modelId)
Parameters
modelIdstringThe ID of the model to get.
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.
ListAllModelsAsync(int)
Lists the models asynchronously
public IAsyncEnumerable<AnthropicResult<Page<AnthropicModel>>> ListAllModelsAsync(int limit = 20)
Parameters
limitintThe maximum number of models to return in each page.
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.
ListModelsAsync(PagingRequest?)
Lists the models asynchronously.
public Task<AnthropicResult<Page<AnthropicModel>>> ListModelsAsync(PagingRequest? request = null)
Parameters
requestPagingRequestThe paging request to use for listing the models.
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.