From 4a7d2c39be15dd7181e2cf3fb5f5aed7f60eae79 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Fri, 3 Jan 2025 02:56:41 +0000 Subject: [PATCH] docs: documentation for v0.4.0 [skip ci] --- .../AnthropicClient.AnthropicApiClient.html | 49 ++- .../AnthropicClient.IAnthropicApiClient.html | 39 ++ ...ropicClient.Models.BaseMessageRequest.html | 5 +- ...ient.Models.CountMessageTokensRequest.html | 401 ++++++++++++++++++ ...AnthropicClient.Models.MessageRequest.html | 5 +- ...picClient.Models.StreamMessageRequest.html | 5 +- ...ropicClient.Models.TokenCountResponse.html | 214 ++++++++++ docs/api/AnthropicClient.Models.html | 10 + docs/api/toc.html | 6 + docs/api/toc.json | 2 +- docs/index.html | 62 ++- docs/index.json | 24 +- docs/manifest.json | 20 + docs/xrefmap.yml | 135 ++++++ 14 files changed, 918 insertions(+), 59 deletions(-) create mode 100644 docs/api/AnthropicClient.Models.CountMessageTokensRequest.html create mode 100644 docs/api/AnthropicClient.Models.TokenCountResponse.html diff --git a/docs/api/AnthropicClient.AnthropicApiClient.html b/docs/api/AnthropicClient.AnthropicApiClient.html index 245a1c8..5a7a9a4 100644 --- a/docs/api/AnthropicClient.AnthropicApiClient.html +++ b/docs/api/AnthropicClient.AnthropicApiClient.html @@ -89,7 +89,7 @@

-Class AnthropicApiClient +Class AnthropicApiClient

@@ -163,7 +163,7 @@ Class AnthropicApiClient AnthropicApiClient(string, HttpClient) - +

Initializes a new instance of the AnthropicApiClient class.

@@ -205,11 +205,50 @@ Class AnthropicApiClient + +

+ CountMessageTokensAsync(CountMessageTokensRequest) + +

+ +

Counts the tokens in a message asynchronously.

+
+
+ +
+
public Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request)
+
+ +

Parameters

+
+
request CountMessageTokensRequest
+

The 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.

@@ -248,7 +287,7 @@ Class AnthropicApiClient CreateMessageAsync(StreamMessageRequest) - +

Creates a message asynchronously and streams the response.

@@ -287,7 +326,7 @@ Class AnthropicApiClient - Edit this page + Edit this page
diff --git a/docs/api/AnthropicClient.IAnthropicApiClient.html b/docs/api/AnthropicClient.IAnthropicApiClient.html index 7e8a1e0..0eb6fbc 100644 --- a/docs/api/AnthropicClient.IAnthropicApiClient.html +++ b/docs/api/AnthropicClient.IAnthropicApiClient.html @@ -121,6 +121,45 @@ Interface IAnthropicApiClient + +

+ CountMessageTokensAsync(CountMessageTokensRequest) + +

+ +

Counts the tokens in a message asynchronously.

+
+
+ +
+
Task<AnthropicResult<TokenCountResponse>> CountMessageTokensAsync(CountMessageTokensRequest request)
+
+ +

Parameters

+
+
request CountMessageTokensRequest
+

The 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.

+
+
+ + + + + + + + + + +

diff --git a/docs/api/AnthropicClient.Models.BaseMessageRequest.html b/docs/api/AnthropicClient.Models.BaseMessageRequest.html index a58bd5a..2e0e791 100644 --- a/docs/api/AnthropicClient.Models.BaseMessageRequest.html +++ b/docs/api/AnthropicClient.Models.BaseMessageRequest.html @@ -164,7 +164,7 @@ Class BaseMessageRequest BaseMessageRequest(string, List<Message>, int, string?, Dictionary<string, object>?, decimal, int?, decimal?, ToolChoice?, List<Tool>?, bool, List<string>?, List<TextContent>?) - +

Initializes a new instance of the BaseMessageRequest class.

@@ -228,9 +228,6 @@ Class BaseMessageRequest Exceptions
-
ArgumentException
-

Thrown when the model ID is invalid.

-
ArgumentNullException

Thrown when the model or messages is null.

diff --git a/docs/api/AnthropicClient.Models.CountMessageTokensRequest.html b/docs/api/AnthropicClient.Models.CountMessageTokensRequest.html new file mode 100644 index 0000000..77f3009 --- /dev/null +++ b/docs/api/AnthropicClient.Models.CountMessageTokensRequest.html @@ -0,0 +1,401 @@ + + + + + Class CountMessageTokensRequest | AnthropicClient + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+
Table of Contents
+ +
+
+ +
+
+
+ +
+
+ + + +
+ +
+ + + +

+Class CountMessageTokensRequest +

+ +
+
Namespace
AnthropicClient.Models
+
Assembly
AnthropicClient.dll
+
+ +

Represents a request to count the number of tokens in a message.

+
+
+ +
+
public class CountMessageTokensRequest
+
+ + + + +
+
Inheritance
+
+ +
CountMessageTokensRequest
+
+
+ + + +
+
Inherited Members
+
+ + + + + + + +
+ + + + + + +

Constructors +

+ + + + +

+ CountMessageTokensRequest(string, List<Message>, ToolChoice?, List<Tool>?, List<TextContent>?) + +

+ +

Initializes a new instance of the CountMessageTokensRequest class.

+
+
+ +
+
public CountMessageTokensRequest(string model, List<Message> messages, ToolChoice? toolChoice = null, List<Tool>? tools = null, List<TextContent>? systemPrompt = null)
+
+ +

Parameters

+
+
model string
+

The model ID to use for the request.

+
+
messages List<Message>
+

The messages to count the number of tokens in.

+
+
toolChoice ToolChoice
+

The tool choice mode to use for the request.

+
+
tools List<Tool>
+

The tools to use for the request.

+
+
systemPrompt List<TextContent>
+

The system prompt to use for the request.

+
+
+ + + + + + + + + +

Exceptions

+
+
ArgumentNullException
+

Thrown when model or messages is null.

+
+
ArgumentException
+

Thrown when messages is empty.

+
+
+ + + +

Properties +

+ + + + +

+ Messages + +

+ +

Gets the messages to count the number of tokens in.

+
+
+ +
+
public List<Message> Messages { get; init; }
+
+ + + + + +

Property Value

+
+
List<Message>
+
+
+ + + + + + + + + + +

+ Model + +

+ +

Gets the model ID to be used for the request.

+
+
+ +
+
public string Model { get; init; }
+
+ + + + + +

Property Value

+
+
string
+
+
+ + + + + + + + + + +

+ SystemPrompt + +

+ +

Gets the system prompt to use for the request.

+
+
+ +
+
[JsonPropertyName("system")]
+public List<TextContent>? SystemPrompt { get; init; }
+
+ + + + + +

Property Value

+
+
List<TextContent>
+
+
+ + + + + + + + + + +

+ ToolChoice + +

+ +

Gets the tool choice mode to use for the request.

+
+
+ +
+
[JsonPropertyName("tool_choice")]
+public ToolChoice? ToolChoice { get; init; }
+
+ + + + + +

Property Value

+
+
ToolChoice
+
+
+ + + + + + + + + + +

+ Tools + +

+ +

Gets the tools to use for the request.

+
+
+ +
+
public List<Tool>? Tools { get; init; }
+
+ + + + + +

Property Value

+
+
List<Tool>
+
+
+ + + + + + + + + +
+ + + + +
+ +
+ +
+
+ +
+ +
+
+
+ Made with docfx +
+
+
+ + diff --git a/docs/api/AnthropicClient.Models.MessageRequest.html b/docs/api/AnthropicClient.Models.MessageRequest.html index 594c487..51fc2d2 100644 --- a/docs/api/AnthropicClient.Models.MessageRequest.html +++ b/docs/api/AnthropicClient.Models.MessageRequest.html @@ -200,7 +200,7 @@ Class MessageRequest MessageRequest(string, List<Message>, int, string?, Dictionary<string, object>?, decimal, int?, decimal?, ToolChoice?, List<Tool>?, List<string>?, List<TextContent>?) - +

Initializes a new instance of the MessageRequest class.

@@ -261,9 +261,6 @@ Class MessageRequest Exceptions
-
ArgumentException
-

Thrown when the model ID is invalid.

-
ArgumentNullException

Thrown when the model or messages is null.

diff --git a/docs/api/AnthropicClient.Models.StreamMessageRequest.html b/docs/api/AnthropicClient.Models.StreamMessageRequest.html index 7e459c2..eaea53f 100644 --- a/docs/api/AnthropicClient.Models.StreamMessageRequest.html +++ b/docs/api/AnthropicClient.Models.StreamMessageRequest.html @@ -200,7 +200,7 @@ Class StreamMessageRequest StreamMessageRequest(string, List<Message>, int, string?, Dictionary<string, object>?, decimal, int?, decimal?, ToolChoice?, List<Tool>?, List<string>?, List<TextContent>?) - +

Initializes a new instance of the StreamMessageRequest class.

@@ -261,9 +261,6 @@ Class StreamMessageRequest Exceptions
-
ArgumentException
-

Thrown when the model ID is invalid.

-
ArgumentNullException

Thrown when the model or messages is null.

diff --git a/docs/api/AnthropicClient.Models.TokenCountResponse.html b/docs/api/AnthropicClient.Models.TokenCountResponse.html new file mode 100644 index 0000000..f9f7e4c --- /dev/null +++ b/docs/api/AnthropicClient.Models.TokenCountResponse.html @@ -0,0 +1,214 @@ + + + + + Class TokenCountResponse | AnthropicClient + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+
Table of Contents
+ +
+
+ +
+
+
+ +
+
+ + + +
+ +
+ + + +

+Class TokenCountResponse +

+ +
+
Namespace
AnthropicClient.Models
+
Assembly
AnthropicClient.dll
+
+ +

Represents a response to a token count request.

+
+
+ +
+
public class TokenCountResponse
+
+ + + + +
+
Inheritance
+
+ +
TokenCountResponse
+
+
+ + + +
+
Inherited Members
+
+ + + + + + + +
+ + + + + + +

Properties +

+ + + + +

+ InputTokens + +

+ +

The number of input tokens counted.

+
+
+ +
+
[JsonPropertyName("input_tokens")]
+public int InputTokens { get; init; }
+
+ + + + + +

Property Value

+
+
int
+
+
+ + + + + + + + + +
+ + + + +
+ +
+ +
+
+ +
+ +
+
+
+ Made with docfx +
+
+
+ + diff --git a/docs/api/AnthropicClient.Models.html b/docs/api/AnthropicClient.Models.html index 6c86df3..2d205be 100644 --- a/docs/api/AnthropicClient.Models.html +++ b/docs/api/AnthropicClient.Models.html @@ -187,6 +187,11 @@ Classes
ContentType

Represents the content type.

+
+
+
+
CountMessageTokensRequest
+

Represents a request to count the number of tokens in a message.

@@ -367,6 +372,11 @@ Classes
TextDelta

Represents a text delta.

+
+
+
+
TokenCountResponse
+

Represents a response to a token count request.

diff --git a/docs/api/toc.html b/docs/api/toc.html index 3e22cdf..dfa271f 100644 --- a/docs/api/toc.html +++ b/docs/api/toc.html @@ -87,6 +87,9 @@
  • ContentType
  • +
  • + CountMessageTokensRequest +
  • DocumentContent
  • @@ -198,6 +201,9 @@
  • TextDelta
  • +
  • + TokenCountResponse +
  • Tool
  • diff --git a/docs/api/toc.json b/docs/api/toc.json index 8bef275..823efe6 100644 --- a/docs/api/toc.json +++ b/docs/api/toc.json @@ -1,2 +1,2 @@ -{"items":[{"name":"AnthropicClient","href":"AnthropicClient.html","topicHref":"AnthropicClient.html","topicUid":"AnthropicClient","type":"Namespace","items":[{"name":"AnthropicApiClient","href":"AnthropicClient.AnthropicApiClient.html","topicHref":"AnthropicClient.AnthropicApiClient.html","topicUid":"AnthropicClient.AnthropicApiClient","type":"Class"},{"name":"IAnthropicApiClient","href":"AnthropicClient.IAnthropicApiClient.html","topicHref":"AnthropicClient.IAnthropicApiClient.html","topicUid":"AnthropicClient.IAnthropicApiClient","type":"Interface"}]},{"name":"AnthropicClient.Models","href":"AnthropicClient.Models.html","topicHref":"AnthropicClient.Models.html","topicUid":"AnthropicClient.Models","type":"Namespace","items":[{"name":"AnthropicError","href":"AnthropicClient.Models.AnthropicError.html","topicHref":"AnthropicClient.Models.AnthropicError.html","topicUid":"AnthropicClient.Models.AnthropicError","type":"Class"},{"name":"AnthropicEvent","href":"AnthropicClient.Models.AnthropicEvent.html","topicHref":"AnthropicClient.Models.AnthropicEvent.html","topicUid":"AnthropicClient.Models.AnthropicEvent","type":"Class"},{"name":"AnthropicFunction","href":"AnthropicClient.Models.AnthropicFunction.html","topicHref":"AnthropicClient.Models.AnthropicFunction.html","topicUid":"AnthropicClient.Models.AnthropicFunction","type":"Class"},{"name":"AnthropicHeaders","href":"AnthropicClient.Models.AnthropicHeaders.html","topicHref":"AnthropicClient.Models.AnthropicHeaders.html","topicUid":"AnthropicClient.Models.AnthropicHeaders","type":"Class"},{"name":"AnthropicModels","href":"AnthropicClient.Models.AnthropicModels.html","topicHref":"AnthropicClient.Models.AnthropicModels.html","topicUid":"AnthropicClient.Models.AnthropicModels","type":"Class"},{"name":"AnyToolChoice","href":"AnthropicClient.Models.AnyToolChoice.html","topicHref":"AnthropicClient.Models.AnyToolChoice.html","topicUid":"AnthropicClient.Models.AnyToolChoice","type":"Class"},{"name":"ApiError","href":"AnthropicClient.Models.ApiError.html","topicHref":"AnthropicClient.Models.ApiError.html","topicUid":"AnthropicClient.Models.ApiError","type":"Class"},{"name":"AuthenticationError","href":"AnthropicClient.Models.AuthenticationError.html","topicHref":"AnthropicClient.Models.AuthenticationError.html","topicUid":"AnthropicClient.Models.AuthenticationError","type":"Class"},{"name":"AutoToolChoice","href":"AnthropicClient.Models.AutoToolChoice.html","topicHref":"AnthropicClient.Models.AutoToolChoice.html","topicUid":"AnthropicClient.Models.AutoToolChoice","type":"Class"},{"name":"BaseMessageRequest","href":"AnthropicClient.Models.BaseMessageRequest.html","topicHref":"AnthropicClient.Models.BaseMessageRequest.html","topicUid":"AnthropicClient.Models.BaseMessageRequest","type":"Class"},{"name":"CacheControl","href":"AnthropicClient.Models.CacheControl.html","topicHref":"AnthropicClient.Models.CacheControl.html","topicUid":"AnthropicClient.Models.CacheControl","type":"Class"},{"name":"CacheControlType","href":"AnthropicClient.Models.CacheControlType.html","topicHref":"AnthropicClient.Models.CacheControlType.html","topicUid":"AnthropicClient.Models.CacheControlType","type":"Class"},{"name":"Content","href":"AnthropicClient.Models.Content.html","topicHref":"AnthropicClient.Models.Content.html","topicUid":"AnthropicClient.Models.Content","type":"Class"},{"name":"ContentDelta","href":"AnthropicClient.Models.ContentDelta.html","topicHref":"AnthropicClient.Models.ContentDelta.html","topicUid":"AnthropicClient.Models.ContentDelta","type":"Class"},{"name":"ContentDeltaEventData","href":"AnthropicClient.Models.ContentDeltaEventData.html","topicHref":"AnthropicClient.Models.ContentDeltaEventData.html","topicUid":"AnthropicClient.Models.ContentDeltaEventData","type":"Class"},{"name":"ContentDeltaType","href":"AnthropicClient.Models.ContentDeltaType.html","topicHref":"AnthropicClient.Models.ContentDeltaType.html","topicUid":"AnthropicClient.Models.ContentDeltaType","type":"Class"},{"name":"ContentStartEventData","href":"AnthropicClient.Models.ContentStartEventData.html","topicHref":"AnthropicClient.Models.ContentStartEventData.html","topicUid":"AnthropicClient.Models.ContentStartEventData","type":"Class"},{"name":"ContentStopEventData","href":"AnthropicClient.Models.ContentStopEventData.html","topicHref":"AnthropicClient.Models.ContentStopEventData.html","topicUid":"AnthropicClient.Models.ContentStopEventData","type":"Class"},{"name":"ContentType","href":"AnthropicClient.Models.ContentType.html","topicHref":"AnthropicClient.Models.ContentType.html","topicUid":"AnthropicClient.Models.ContentType","type":"Class"},{"name":"DocumentContent","href":"AnthropicClient.Models.DocumentContent.html","topicHref":"AnthropicClient.Models.DocumentContent.html","topicUid":"AnthropicClient.Models.DocumentContent","type":"Class"},{"name":"DocumentSource","href":"AnthropicClient.Models.DocumentSource.html","topicHref":"AnthropicClient.Models.DocumentSource.html","topicUid":"AnthropicClient.Models.DocumentSource","type":"Class"},{"name":"EphemeralCacheControl","href":"AnthropicClient.Models.EphemeralCacheControl.html","topicHref":"AnthropicClient.Models.EphemeralCacheControl.html","topicUid":"AnthropicClient.Models.EphemeralCacheControl","type":"Class"},{"name":"Error","href":"AnthropicClient.Models.Error.html","topicHref":"AnthropicClient.Models.Error.html","topicUid":"AnthropicClient.Models.Error","type":"Class"},{"name":"ErrorEventData","href":"AnthropicClient.Models.ErrorEventData.html","topicHref":"AnthropicClient.Models.ErrorEventData.html","topicUid":"AnthropicClient.Models.ErrorEventData","type":"Class"},{"name":"ErrorType","href":"AnthropicClient.Models.ErrorType.html","topicHref":"AnthropicClient.Models.ErrorType.html","topicUid":"AnthropicClient.Models.ErrorType","type":"Class"},{"name":"EventData","href":"AnthropicClient.Models.EventData.html","topicHref":"AnthropicClient.Models.EventData.html","topicUid":"AnthropicClient.Models.EventData","type":"Class"},{"name":"EventType","href":"AnthropicClient.Models.EventType.html","topicHref":"AnthropicClient.Models.EventType.html","topicUid":"AnthropicClient.Models.EventType","type":"Class"},{"name":"FunctionParameterAttribute","href":"AnthropicClient.Models.FunctionParameterAttribute.html","topicHref":"AnthropicClient.Models.FunctionParameterAttribute.html","topicUid":"AnthropicClient.Models.FunctionParameterAttribute","type":"Class"},{"name":"FunctionPropertyAttribute","href":"AnthropicClient.Models.FunctionPropertyAttribute.html","topicHref":"AnthropicClient.Models.FunctionPropertyAttribute.html","topicUid":"AnthropicClient.Models.FunctionPropertyAttribute","type":"Class"},{"name":"ITool","href":"AnthropicClient.Models.ITool.html","topicHref":"AnthropicClient.Models.ITool.html","topicUid":"AnthropicClient.Models.ITool","type":"Interface"},{"name":"ImageContent","href":"AnthropicClient.Models.ImageContent.html","topicHref":"AnthropicClient.Models.ImageContent.html","topicUid":"AnthropicClient.Models.ImageContent","type":"Class"},{"name":"ImageSource","href":"AnthropicClient.Models.ImageSource.html","topicHref":"AnthropicClient.Models.ImageSource.html","topicUid":"AnthropicClient.Models.ImageSource","type":"Class"},{"name":"ImageType","href":"AnthropicClient.Models.ImageType.html","topicHref":"AnthropicClient.Models.ImageType.html","topicUid":"AnthropicClient.Models.ImageType","type":"Class"},{"name":"InputProperty","href":"AnthropicClient.Models.InputProperty.html","topicHref":"AnthropicClient.Models.InputProperty.html","topicUid":"AnthropicClient.Models.InputProperty","type":"Class"},{"name":"InputSchema","href":"AnthropicClient.Models.InputSchema.html","topicHref":"AnthropicClient.Models.InputSchema.html","topicUid":"AnthropicClient.Models.InputSchema","type":"Class"},{"name":"InvalidRequestError","href":"AnthropicClient.Models.InvalidRequestError.html","topicHref":"AnthropicClient.Models.InvalidRequestError.html","topicUid":"AnthropicClient.Models.InvalidRequestError","type":"Class"},{"name":"JsonDelta","href":"AnthropicClient.Models.JsonDelta.html","topicHref":"AnthropicClient.Models.JsonDelta.html","topicUid":"AnthropicClient.Models.JsonDelta","type":"Class"},{"name":"Message","href":"AnthropicClient.Models.Message.html","topicHref":"AnthropicClient.Models.Message.html","topicUid":"AnthropicClient.Models.Message","type":"Class"},{"name":"MessageCompleteEventData","href":"AnthropicClient.Models.MessageCompleteEventData.html","topicHref":"AnthropicClient.Models.MessageCompleteEventData.html","topicUid":"AnthropicClient.Models.MessageCompleteEventData","type":"Class"},{"name":"MessageDelta","href":"AnthropicClient.Models.MessageDelta.html","topicHref":"AnthropicClient.Models.MessageDelta.html","topicUid":"AnthropicClient.Models.MessageDelta","type":"Class"},{"name":"MessageDeltaEventData","href":"AnthropicClient.Models.MessageDeltaEventData.html","topicHref":"AnthropicClient.Models.MessageDeltaEventData.html","topicUid":"AnthropicClient.Models.MessageDeltaEventData","type":"Class"},{"name":"MessageRequest","href":"AnthropicClient.Models.MessageRequest.html","topicHref":"AnthropicClient.Models.MessageRequest.html","topicUid":"AnthropicClient.Models.MessageRequest","type":"Class"},{"name":"MessageResponse","href":"AnthropicClient.Models.MessageResponse.html","topicHref":"AnthropicClient.Models.MessageResponse.html","topicUid":"AnthropicClient.Models.MessageResponse","type":"Class"},{"name":"MessageRole","href":"AnthropicClient.Models.MessageRole.html","topicHref":"AnthropicClient.Models.MessageRole.html","topicUid":"AnthropicClient.Models.MessageRole","type":"Class"},{"name":"MessageStartEventData","href":"AnthropicClient.Models.MessageStartEventData.html","topicHref":"AnthropicClient.Models.MessageStartEventData.html","topicUid":"AnthropicClient.Models.MessageStartEventData","type":"Class"},{"name":"MessageStopEventData","href":"AnthropicClient.Models.MessageStopEventData.html","topicHref":"AnthropicClient.Models.MessageStopEventData.html","topicUid":"AnthropicClient.Models.MessageStopEventData","type":"Class"},{"name":"NotFoundError","href":"AnthropicClient.Models.NotFoundError.html","topicHref":"AnthropicClient.Models.NotFoundError.html","topicUid":"AnthropicClient.Models.NotFoundError","type":"Class"},{"name":"OverloadedError","href":"AnthropicClient.Models.OverloadedError.html","topicHref":"AnthropicClient.Models.OverloadedError.html","topicUid":"AnthropicClient.Models.OverloadedError","type":"Class"},{"name":"PermissionError","href":"AnthropicClient.Models.PermissionError.html","topicHref":"AnthropicClient.Models.PermissionError.html","topicUid":"AnthropicClient.Models.PermissionError","type":"Class"},{"name":"PingEventData","href":"AnthropicClient.Models.PingEventData.html","topicHref":"AnthropicClient.Models.PingEventData.html","topicUid":"AnthropicClient.Models.PingEventData","type":"Class"},{"name":"RateLimitError","href":"AnthropicClient.Models.RateLimitError.html","topicHref":"AnthropicClient.Models.RateLimitError.html","topicUid":"AnthropicClient.Models.RateLimitError","type":"Class"},{"name":"SpecificToolChoice","href":"AnthropicClient.Models.SpecificToolChoice.html","topicHref":"AnthropicClient.Models.SpecificToolChoice.html","topicUid":"AnthropicClient.Models.SpecificToolChoice","type":"Class"},{"name":"StopReasonType","href":"AnthropicClient.Models.StopReasonType.html","topicHref":"AnthropicClient.Models.StopReasonType.html","topicUid":"AnthropicClient.Models.StopReasonType","type":"Class"},{"name":"StreamMessageRequest","href":"AnthropicClient.Models.StreamMessageRequest.html","topicHref":"AnthropicClient.Models.StreamMessageRequest.html","topicUid":"AnthropicClient.Models.StreamMessageRequest","type":"Class"},{"name":"TextContent","href":"AnthropicClient.Models.TextContent.html","topicHref":"AnthropicClient.Models.TextContent.html","topicUid":"AnthropicClient.Models.TextContent","type":"Class"},{"name":"TextDelta","href":"AnthropicClient.Models.TextDelta.html","topicHref":"AnthropicClient.Models.TextDelta.html","topicUid":"AnthropicClient.Models.TextDelta","type":"Class"},{"name":"Tool","href":"AnthropicClient.Models.Tool.html","topicHref":"AnthropicClient.Models.Tool.html","topicUid":"AnthropicClient.Models.Tool","type":"Class"},{"name":"ToolCall","href":"AnthropicClient.Models.ToolCall.html","topicHref":"AnthropicClient.Models.ToolCall.html","topicUid":"AnthropicClient.Models.ToolCall","type":"Class"},{"name":"ToolCallResult","href":"AnthropicClient.Models.ToolCallResult-1.html","topicHref":"AnthropicClient.Models.ToolCallResult-1.html","topicUid":"AnthropicClient.Models.ToolCallResult`1","type":"Class"},{"name":"ToolChoice","href":"AnthropicClient.Models.ToolChoice.html","topicHref":"AnthropicClient.Models.ToolChoice.html","topicUid":"AnthropicClient.Models.ToolChoice","type":"Class"},{"name":"ToolChoiceType","href":"AnthropicClient.Models.ToolChoiceType.html","topicHref":"AnthropicClient.Models.ToolChoiceType.html","topicUid":"AnthropicClient.Models.ToolChoiceType","type":"Class"},{"name":"ToolResultContent","href":"AnthropicClient.Models.ToolResultContent.html","topicHref":"AnthropicClient.Models.ToolResultContent.html","topicUid":"AnthropicClient.Models.ToolResultContent","type":"Class"},{"name":"ToolUseContent","href":"AnthropicClient.Models.ToolUseContent.html","topicHref":"AnthropicClient.Models.ToolUseContent.html","topicUid":"AnthropicClient.Models.ToolUseContent","type":"Class"},{"name":"Usage","href":"AnthropicClient.Models.Usage.html","topicHref":"AnthropicClient.Models.Usage.html","topicUid":"AnthropicClient.Models.Usage","type":"Class"}]}],"memberLayout":"SamePage"} +{"items":[{"name":"AnthropicClient","href":"AnthropicClient.html","topicHref":"AnthropicClient.html","topicUid":"AnthropicClient","type":"Namespace","items":[{"name":"AnthropicApiClient","href":"AnthropicClient.AnthropicApiClient.html","topicHref":"AnthropicClient.AnthropicApiClient.html","topicUid":"AnthropicClient.AnthropicApiClient","type":"Class"},{"name":"IAnthropicApiClient","href":"AnthropicClient.IAnthropicApiClient.html","topicHref":"AnthropicClient.IAnthropicApiClient.html","topicUid":"AnthropicClient.IAnthropicApiClient","type":"Interface"}]},{"name":"AnthropicClient.Models","href":"AnthropicClient.Models.html","topicHref":"AnthropicClient.Models.html","topicUid":"AnthropicClient.Models","type":"Namespace","items":[{"name":"AnthropicError","href":"AnthropicClient.Models.AnthropicError.html","topicHref":"AnthropicClient.Models.AnthropicError.html","topicUid":"AnthropicClient.Models.AnthropicError","type":"Class"},{"name":"AnthropicEvent","href":"AnthropicClient.Models.AnthropicEvent.html","topicHref":"AnthropicClient.Models.AnthropicEvent.html","topicUid":"AnthropicClient.Models.AnthropicEvent","type":"Class"},{"name":"AnthropicFunction","href":"AnthropicClient.Models.AnthropicFunction.html","topicHref":"AnthropicClient.Models.AnthropicFunction.html","topicUid":"AnthropicClient.Models.AnthropicFunction","type":"Class"},{"name":"AnthropicHeaders","href":"AnthropicClient.Models.AnthropicHeaders.html","topicHref":"AnthropicClient.Models.AnthropicHeaders.html","topicUid":"AnthropicClient.Models.AnthropicHeaders","type":"Class"},{"name":"AnthropicModels","href":"AnthropicClient.Models.AnthropicModels.html","topicHref":"AnthropicClient.Models.AnthropicModels.html","topicUid":"AnthropicClient.Models.AnthropicModels","type":"Class"},{"name":"AnyToolChoice","href":"AnthropicClient.Models.AnyToolChoice.html","topicHref":"AnthropicClient.Models.AnyToolChoice.html","topicUid":"AnthropicClient.Models.AnyToolChoice","type":"Class"},{"name":"ApiError","href":"AnthropicClient.Models.ApiError.html","topicHref":"AnthropicClient.Models.ApiError.html","topicUid":"AnthropicClient.Models.ApiError","type":"Class"},{"name":"AuthenticationError","href":"AnthropicClient.Models.AuthenticationError.html","topicHref":"AnthropicClient.Models.AuthenticationError.html","topicUid":"AnthropicClient.Models.AuthenticationError","type":"Class"},{"name":"AutoToolChoice","href":"AnthropicClient.Models.AutoToolChoice.html","topicHref":"AnthropicClient.Models.AutoToolChoice.html","topicUid":"AnthropicClient.Models.AutoToolChoice","type":"Class"},{"name":"BaseMessageRequest","href":"AnthropicClient.Models.BaseMessageRequest.html","topicHref":"AnthropicClient.Models.BaseMessageRequest.html","topicUid":"AnthropicClient.Models.BaseMessageRequest","type":"Class"},{"name":"CacheControl","href":"AnthropicClient.Models.CacheControl.html","topicHref":"AnthropicClient.Models.CacheControl.html","topicUid":"AnthropicClient.Models.CacheControl","type":"Class"},{"name":"CacheControlType","href":"AnthropicClient.Models.CacheControlType.html","topicHref":"AnthropicClient.Models.CacheControlType.html","topicUid":"AnthropicClient.Models.CacheControlType","type":"Class"},{"name":"Content","href":"AnthropicClient.Models.Content.html","topicHref":"AnthropicClient.Models.Content.html","topicUid":"AnthropicClient.Models.Content","type":"Class"},{"name":"ContentDelta","href":"AnthropicClient.Models.ContentDelta.html","topicHref":"AnthropicClient.Models.ContentDelta.html","topicUid":"AnthropicClient.Models.ContentDelta","type":"Class"},{"name":"ContentDeltaEventData","href":"AnthropicClient.Models.ContentDeltaEventData.html","topicHref":"AnthropicClient.Models.ContentDeltaEventData.html","topicUid":"AnthropicClient.Models.ContentDeltaEventData","type":"Class"},{"name":"ContentDeltaType","href":"AnthropicClient.Models.ContentDeltaType.html","topicHref":"AnthropicClient.Models.ContentDeltaType.html","topicUid":"AnthropicClient.Models.ContentDeltaType","type":"Class"},{"name":"ContentStartEventData","href":"AnthropicClient.Models.ContentStartEventData.html","topicHref":"AnthropicClient.Models.ContentStartEventData.html","topicUid":"AnthropicClient.Models.ContentStartEventData","type":"Class"},{"name":"ContentStopEventData","href":"AnthropicClient.Models.ContentStopEventData.html","topicHref":"AnthropicClient.Models.ContentStopEventData.html","topicUid":"AnthropicClient.Models.ContentStopEventData","type":"Class"},{"name":"ContentType","href":"AnthropicClient.Models.ContentType.html","topicHref":"AnthropicClient.Models.ContentType.html","topicUid":"AnthropicClient.Models.ContentType","type":"Class"},{"name":"CountMessageTokensRequest","href":"AnthropicClient.Models.CountMessageTokensRequest.html","topicHref":"AnthropicClient.Models.CountMessageTokensRequest.html","topicUid":"AnthropicClient.Models.CountMessageTokensRequest","type":"Class"},{"name":"DocumentContent","href":"AnthropicClient.Models.DocumentContent.html","topicHref":"AnthropicClient.Models.DocumentContent.html","topicUid":"AnthropicClient.Models.DocumentContent","type":"Class"},{"name":"DocumentSource","href":"AnthropicClient.Models.DocumentSource.html","topicHref":"AnthropicClient.Models.DocumentSource.html","topicUid":"AnthropicClient.Models.DocumentSource","type":"Class"},{"name":"EphemeralCacheControl","href":"AnthropicClient.Models.EphemeralCacheControl.html","topicHref":"AnthropicClient.Models.EphemeralCacheControl.html","topicUid":"AnthropicClient.Models.EphemeralCacheControl","type":"Class"},{"name":"Error","href":"AnthropicClient.Models.Error.html","topicHref":"AnthropicClient.Models.Error.html","topicUid":"AnthropicClient.Models.Error","type":"Class"},{"name":"ErrorEventData","href":"AnthropicClient.Models.ErrorEventData.html","topicHref":"AnthropicClient.Models.ErrorEventData.html","topicUid":"AnthropicClient.Models.ErrorEventData","type":"Class"},{"name":"ErrorType","href":"AnthropicClient.Models.ErrorType.html","topicHref":"AnthropicClient.Models.ErrorType.html","topicUid":"AnthropicClient.Models.ErrorType","type":"Class"},{"name":"EventData","href":"AnthropicClient.Models.EventData.html","topicHref":"AnthropicClient.Models.EventData.html","topicUid":"AnthropicClient.Models.EventData","type":"Class"},{"name":"EventType","href":"AnthropicClient.Models.EventType.html","topicHref":"AnthropicClient.Models.EventType.html","topicUid":"AnthropicClient.Models.EventType","type":"Class"},{"name":"FunctionParameterAttribute","href":"AnthropicClient.Models.FunctionParameterAttribute.html","topicHref":"AnthropicClient.Models.FunctionParameterAttribute.html","topicUid":"AnthropicClient.Models.FunctionParameterAttribute","type":"Class"},{"name":"FunctionPropertyAttribute","href":"AnthropicClient.Models.FunctionPropertyAttribute.html","topicHref":"AnthropicClient.Models.FunctionPropertyAttribute.html","topicUid":"AnthropicClient.Models.FunctionPropertyAttribute","type":"Class"},{"name":"ITool","href":"AnthropicClient.Models.ITool.html","topicHref":"AnthropicClient.Models.ITool.html","topicUid":"AnthropicClient.Models.ITool","type":"Interface"},{"name":"ImageContent","href":"AnthropicClient.Models.ImageContent.html","topicHref":"AnthropicClient.Models.ImageContent.html","topicUid":"AnthropicClient.Models.ImageContent","type":"Class"},{"name":"ImageSource","href":"AnthropicClient.Models.ImageSource.html","topicHref":"AnthropicClient.Models.ImageSource.html","topicUid":"AnthropicClient.Models.ImageSource","type":"Class"},{"name":"ImageType","href":"AnthropicClient.Models.ImageType.html","topicHref":"AnthropicClient.Models.ImageType.html","topicUid":"AnthropicClient.Models.ImageType","type":"Class"},{"name":"InputProperty","href":"AnthropicClient.Models.InputProperty.html","topicHref":"AnthropicClient.Models.InputProperty.html","topicUid":"AnthropicClient.Models.InputProperty","type":"Class"},{"name":"InputSchema","href":"AnthropicClient.Models.InputSchema.html","topicHref":"AnthropicClient.Models.InputSchema.html","topicUid":"AnthropicClient.Models.InputSchema","type":"Class"},{"name":"InvalidRequestError","href":"AnthropicClient.Models.InvalidRequestError.html","topicHref":"AnthropicClient.Models.InvalidRequestError.html","topicUid":"AnthropicClient.Models.InvalidRequestError","type":"Class"},{"name":"JsonDelta","href":"AnthropicClient.Models.JsonDelta.html","topicHref":"AnthropicClient.Models.JsonDelta.html","topicUid":"AnthropicClient.Models.JsonDelta","type":"Class"},{"name":"Message","href":"AnthropicClient.Models.Message.html","topicHref":"AnthropicClient.Models.Message.html","topicUid":"AnthropicClient.Models.Message","type":"Class"},{"name":"MessageCompleteEventData","href":"AnthropicClient.Models.MessageCompleteEventData.html","topicHref":"AnthropicClient.Models.MessageCompleteEventData.html","topicUid":"AnthropicClient.Models.MessageCompleteEventData","type":"Class"},{"name":"MessageDelta","href":"AnthropicClient.Models.MessageDelta.html","topicHref":"AnthropicClient.Models.MessageDelta.html","topicUid":"AnthropicClient.Models.MessageDelta","type":"Class"},{"name":"MessageDeltaEventData","href":"AnthropicClient.Models.MessageDeltaEventData.html","topicHref":"AnthropicClient.Models.MessageDeltaEventData.html","topicUid":"AnthropicClient.Models.MessageDeltaEventData","type":"Class"},{"name":"MessageRequest","href":"AnthropicClient.Models.MessageRequest.html","topicHref":"AnthropicClient.Models.MessageRequest.html","topicUid":"AnthropicClient.Models.MessageRequest","type":"Class"},{"name":"MessageResponse","href":"AnthropicClient.Models.MessageResponse.html","topicHref":"AnthropicClient.Models.MessageResponse.html","topicUid":"AnthropicClient.Models.MessageResponse","type":"Class"},{"name":"MessageRole","href":"AnthropicClient.Models.MessageRole.html","topicHref":"AnthropicClient.Models.MessageRole.html","topicUid":"AnthropicClient.Models.MessageRole","type":"Class"},{"name":"MessageStartEventData","href":"AnthropicClient.Models.MessageStartEventData.html","topicHref":"AnthropicClient.Models.MessageStartEventData.html","topicUid":"AnthropicClient.Models.MessageStartEventData","type":"Class"},{"name":"MessageStopEventData","href":"AnthropicClient.Models.MessageStopEventData.html","topicHref":"AnthropicClient.Models.MessageStopEventData.html","topicUid":"AnthropicClient.Models.MessageStopEventData","type":"Class"},{"name":"NotFoundError","href":"AnthropicClient.Models.NotFoundError.html","topicHref":"AnthropicClient.Models.NotFoundError.html","topicUid":"AnthropicClient.Models.NotFoundError","type":"Class"},{"name":"OverloadedError","href":"AnthropicClient.Models.OverloadedError.html","topicHref":"AnthropicClient.Models.OverloadedError.html","topicUid":"AnthropicClient.Models.OverloadedError","type":"Class"},{"name":"PermissionError","href":"AnthropicClient.Models.PermissionError.html","topicHref":"AnthropicClient.Models.PermissionError.html","topicUid":"AnthropicClient.Models.PermissionError","type":"Class"},{"name":"PingEventData","href":"AnthropicClient.Models.PingEventData.html","topicHref":"AnthropicClient.Models.PingEventData.html","topicUid":"AnthropicClient.Models.PingEventData","type":"Class"},{"name":"RateLimitError","href":"AnthropicClient.Models.RateLimitError.html","topicHref":"AnthropicClient.Models.RateLimitError.html","topicUid":"AnthropicClient.Models.RateLimitError","type":"Class"},{"name":"SpecificToolChoice","href":"AnthropicClient.Models.SpecificToolChoice.html","topicHref":"AnthropicClient.Models.SpecificToolChoice.html","topicUid":"AnthropicClient.Models.SpecificToolChoice","type":"Class"},{"name":"StopReasonType","href":"AnthropicClient.Models.StopReasonType.html","topicHref":"AnthropicClient.Models.StopReasonType.html","topicUid":"AnthropicClient.Models.StopReasonType","type":"Class"},{"name":"StreamMessageRequest","href":"AnthropicClient.Models.StreamMessageRequest.html","topicHref":"AnthropicClient.Models.StreamMessageRequest.html","topicUid":"AnthropicClient.Models.StreamMessageRequest","type":"Class"},{"name":"TextContent","href":"AnthropicClient.Models.TextContent.html","topicHref":"AnthropicClient.Models.TextContent.html","topicUid":"AnthropicClient.Models.TextContent","type":"Class"},{"name":"TextDelta","href":"AnthropicClient.Models.TextDelta.html","topicHref":"AnthropicClient.Models.TextDelta.html","topicUid":"AnthropicClient.Models.TextDelta","type":"Class"},{"name":"TokenCountResponse","href":"AnthropicClient.Models.TokenCountResponse.html","topicHref":"AnthropicClient.Models.TokenCountResponse.html","topicUid":"AnthropicClient.Models.TokenCountResponse","type":"Class"},{"name":"Tool","href":"AnthropicClient.Models.Tool.html","topicHref":"AnthropicClient.Models.Tool.html","topicUid":"AnthropicClient.Models.Tool","type":"Class"},{"name":"ToolCall","href":"AnthropicClient.Models.ToolCall.html","topicHref":"AnthropicClient.Models.ToolCall.html","topicUid":"AnthropicClient.Models.ToolCall","type":"Class"},{"name":"ToolCallResult","href":"AnthropicClient.Models.ToolCallResult-1.html","topicHref":"AnthropicClient.Models.ToolCallResult-1.html","topicUid":"AnthropicClient.Models.ToolCallResult`1","type":"Class"},{"name":"ToolChoice","href":"AnthropicClient.Models.ToolChoice.html","topicHref":"AnthropicClient.Models.ToolChoice.html","topicUid":"AnthropicClient.Models.ToolChoice","type":"Class"},{"name":"ToolChoiceType","href":"AnthropicClient.Models.ToolChoiceType.html","topicHref":"AnthropicClient.Models.ToolChoiceType.html","topicUid":"AnthropicClient.Models.ToolChoiceType","type":"Class"},{"name":"ToolResultContent","href":"AnthropicClient.Models.ToolResultContent.html","topicHref":"AnthropicClient.Models.ToolResultContent.html","topicUid":"AnthropicClient.Models.ToolResultContent","type":"Class"},{"name":"ToolUseContent","href":"AnthropicClient.Models.ToolUseContent.html","topicHref":"AnthropicClient.Models.ToolUseContent.html","topicUid":"AnthropicClient.Models.ToolUseContent","type":"Class"},{"name":"Usage","href":"AnthropicClient.Models.Usage.html","topicHref":"AnthropicClient.Models.Usage.html","topicUid":"AnthropicClient.Models.Usage","type":"Class"}]}],"memberLayout":"SamePage"} diff --git a/docs/index.html b/docs/index.html index 34fbc9d..5551758 100644 --- a/docs/index.html +++ b/docs/index.html @@ -146,8 +146,33 @@ var client = new AnthropicApiClient(apiKey, new HttpClient());
    Note

    The following examples assume that you have already created an instance of the AnthropicApiClient class named client. You can also find these snippets in the examples directory.

    +

    Count Message Tokens

    +

    The AnthropicApiClient exposes a method named CountMessageTokensAsync that can be used to count the number of tokens in a message. The method requires a CountMessageTokensRequest instance as a parameter.

    +
    using AnthropicClient;
    +using AnthropicClient.Models;
    +
    +var response = await client.CountMessageTokensAsync(new CountMessageTokensRequest(
    +  AnthropicModels.Claude3Haiku,
    +  [
    +    new(
    +      MessageRole.User, 
    +      [new TextContent("Please write a haiku about the ocean.")]
    +    )
    +  ]
    +));
    +
    +if (response.IsFailure)
    +{
    +  Console.WriteLine("Failed to count message tokens");
    +  Console.WriteLine("Error Type: {0}", response.Error.Error.Type);
    +  Console.WriteLine("Error Message: {0}", response.Error.Error.Message);
    +  return;
    +}
    +
    +Console.WriteLine("Token Count: {0}", response.Value.InputTokens);
    +

    Create a message

    -

    The AnthropicApiClient exposes a single method named CreateMessageAsync that can be used to create a message. The method requires a MessageRequest or a StreamMessageRequest instance as a parameter. The MessageRequest class is used to create a message whose response is not streamed and the StreamMessageRequest class is used to create a message whose response is streamed. The MessageRequest instance's properties can be set to configure how the message is created.

    +

    The AnthropicApiClient exposes a method named CreateMessageAsync that can be used to create a message. The method requires a MessageRequest or a StreamMessageRequest instance as a parameter. The MessageRequest class is used to create a message whose response is not streamed and the StreamMessageRequest class is used to create a message whose response is streamed. The MessageRequest instance's properties can be set to configure how the message is created.

    Non-Streaming

    using AnthropicClient;
     using AnthropicClient.Models;
    @@ -674,20 +699,7 @@ foreach (var content in response.Value.Content)
     }
     

    Prompt Caching

    -

    Anthropic has recently introduced a feature called Prompt Caching that allows you to cache all or part of the prompt you send to the model. This can be used to improve the performance of your application by reducing latency and token usage. This feature is covered in depth in Anthropic's API Documentation.

    -
    -
    Note
    -

    This feature is in beta and requires you to set an anthropic-beta header on your requests to use it. -The value of the header should be prompt-caching-2024-07-31.

    -
    -

    When using this library you can opt-in to prompt caching by adding the required header to the HttpClient instance you provide to the AnthropicApiClient constructor.

    -
    using AnthropicClient;
    -
    -var httpClient = new HttpClient();
    -httpClient.DefaultRequestHeaders.Add("anthropic-beta", "prompt-caching-2024-07-31");
    -
    -var client = new AnthropicApiClient(apiKey, httpClient);
    -
    +

    Anthropic provides a feature called Prompt Caching that allows you to cache all or part of the prompt you send to the model. This can be used to improve the performance of your application by reducing latency and token usage. This feature is covered in depth in Anthropic's API Documentation.

    Prompt caching can be used to cache all parts of the prompt including system messages, user messages, and tools. You should refer to the Anthropic API Documentation for specifics on limitations and requirements for using prompt caching. This library aims to make using prompt caching convenient and give you complete control over what parts of the prompt are cached. Currently there is only one type of cache control available - EphemeralCacheControl.

    Caching System Messages

    System messages can be cached by providing a List<TextContent> as the systemMessages parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the TextContent instances have the CacheControl property set.

    @@ -813,20 +825,7 @@ foreach (var content in response.Value.Content) }

    PDF Support

    -

    Anthropic has recently introduced a feature called PDF Support that allows Claude to support PDF input and understand both text and visual content within documents. . This feature is covered in depth in Anthropic's API Documentation.

    -
    -
    Note
    -

    This feature is in beta and requires you to set an anthropic-beta header on your requests to use it. -The value of the header should be pdfs-2024-09-25.

    -
    -

    When using this library you can opt-in to PDF support by adding the required header to the HttpClient instance you provide to the AnthropicApiClient constructor.

    -
    using AnthropicClient;
    -
    -var httpClient = new HttpClient();
    -httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25");
    -
    -var client = new AnthropicApiClient(apiKey, httpClient);
    -
    +

    Anthropic provides a feature called PDF Support that allows Claude to support PDF input and understand both text and visual content within documents. This feature is covered in depth in Anthropic's API Documentation.

    PDF support can be used to provide a PDF document as input to the model. This can be used to provide additional context to the model or to ask for additional information from the model. This library aims to make using PDF support convenient by allowing you to provide the PDF document you want Anthropic's models to consider for use when creating a message.

    PDF Document

    You can provide a PDF document by providing its base64 encoded content as a DocumentContent instance in the list of messages in the MessageRequest or StreamMessageRequest constructor.

    @@ -841,11 +840,6 @@ var request = new MessageRequest( ] ); -var httpClient = new HttpClient(); -httpClient.DefaultRequestHeaders.Add("anthropic-beta", "pdfs-2024-09-25"); - -var client = new AnthropicApiClient(apiKey, httpClient); - var response = await client.CreateMessageAsync(request); if (response.IsSuccess is false) diff --git a/docs/index.json b/docs/index.json index 092a5fa..f5aad9e 100644 --- a/docs/index.json +++ b/docs/index.json @@ -2,12 +2,12 @@ "api/AnthropicClient.AnthropicApiClient.html": { "href": "api/AnthropicClient.AnthropicApiClient.html", "title": "Class AnthropicApiClient | AnthropicClient", - "keywords": "Class AnthropicApiClient Namespace AnthropicClient Assembly AnthropicClient.dll Represents a client for interacting with the Anthropic API. public class AnthropicApiClient : IAnthropicApiClient Inheritance object AnthropicApiClient Implements IAnthropicApiClient Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors AnthropicApiClient(string, HttpClient) Initializes a new instance of the AnthropicApiClient class. public AnthropicApiClient(string apiKey, HttpClient httpClient) Parameters apiKey string The API key to use for the client. httpClient HttpClient The HTTP client to use for the client. Exceptions ArgumentNullException Thrown when the API key or HTTP client is null. Methods CreateMessageAsync(MessageRequest) Creates a message asynchronously. public Task> CreateMessageAsync(MessageRequest request) Parameters request MessageRequest The message request to create. Returns Task> A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult. CreateMessageAsync(StreamMessageRequest) Creates a message asynchronously and streams the response. public IAsyncEnumerable CreateMessageAsync(StreamMessageRequest request) Parameters request StreamMessageRequest The message request to create. Returns IAsyncEnumerable An asynchronous enumerable that yields the response event by event." + "keywords": "Class AnthropicApiClient Namespace AnthropicClient Assembly AnthropicClient.dll Represents a client for interacting with the Anthropic API. public class AnthropicApiClient : IAnthropicApiClient Inheritance object AnthropicApiClient Implements IAnthropicApiClient Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors AnthropicApiClient(string, HttpClient) Initializes a new instance of the AnthropicApiClient class. public AnthropicApiClient(string apiKey, HttpClient httpClient) Parameters apiKey string The API key to use for the client. httpClient HttpClient The 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> CountMessageTokensAsync(CountMessageTokensRequest request) Parameters request CountMessageTokensRequest The count message tokens request. Returns Task> A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult where T is TokenCountResponse. CreateMessageAsync(MessageRequest) Creates a message asynchronously. public Task> CreateMessageAsync(MessageRequest request) Parameters request MessageRequest The message request to create. Returns Task> A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult. CreateMessageAsync(StreamMessageRequest) Creates a message asynchronously and streams the response. public IAsyncEnumerable CreateMessageAsync(StreamMessageRequest request) Parameters request StreamMessageRequest The message request to create. Returns IAsyncEnumerable An asynchronous enumerable that yields the response event by event." }, "api/AnthropicClient.IAnthropicApiClient.html": { "href": "api/AnthropicClient.IAnthropicApiClient.html", "title": "Interface IAnthropicApiClient | AnthropicClient", - "keywords": "Interface IAnthropicApiClient Namespace AnthropicClient Assembly AnthropicClient.dll Represents a client for interacting with the Anthropic API. public interface IAnthropicApiClient Methods CreateMessageAsync(MessageRequest) Creates a message asynchronously. Task> CreateMessageAsync(MessageRequest request) Parameters request MessageRequest The message request to create. Returns Task> A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult. CreateMessageAsync(StreamMessageRequest) Creates a message asynchronously and streams the response. IAsyncEnumerable CreateMessageAsync(StreamMessageRequest request) Parameters request StreamMessageRequest The message request to create. Returns IAsyncEnumerable An asynchronous enumerable that yields the response event by event." + "keywords": "Interface IAnthropicApiClient Namespace AnthropicClient Assembly AnthropicClient.dll Represents a client for interacting with the Anthropic API. public interface IAnthropicApiClient Methods CountMessageTokensAsync(CountMessageTokensRequest) Counts the tokens in a message asynchronously. Task> CountMessageTokensAsync(CountMessageTokensRequest request) Parameters request CountMessageTokensRequest The count message tokens request. Returns Task> A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult where T is TokenCountResponse. CreateMessageAsync(MessageRequest) Creates a message asynchronously. Task> CreateMessageAsync(MessageRequest request) Parameters request MessageRequest The message request to create. Returns Task> A task that represents the asynchronous operation. The task result contains the response as an AnthropicResult. CreateMessageAsync(StreamMessageRequest) Creates a message asynchronously and streams the response. IAsyncEnumerable CreateMessageAsync(StreamMessageRequest request) Parameters request StreamMessageRequest The message request to create. Returns IAsyncEnumerable An asynchronous enumerable that yields the response event by event." }, "api/AnthropicClient.Models.AnthropicError.html": { "href": "api/AnthropicClient.Models.AnthropicError.html", @@ -57,7 +57,7 @@ "api/AnthropicClient.Models.BaseMessageRequest.html": { "href": "api/AnthropicClient.Models.BaseMessageRequest.html", "title": "Class BaseMessageRequest | AnthropicClient", - "keywords": "Class BaseMessageRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a message request. public abstract class BaseMessageRequest Inheritance object BaseMessageRequest Derived MessageRequest StreamMessageRequest Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors BaseMessageRequest(string, List, int, string?, Dictionary?, decimal, int?, decimal?, ToolChoice?, List?, bool, List?, List?) Initializes a new instance of the BaseMessageRequest class. protected BaseMessageRequest(string model, List messages, int maxTokens, string? system, Dictionary? metadata, decimal temperature, int? topK, decimal? topP, ToolChoice? toolChoice, List? tools, bool stream, List? stopSequences, List? systemMessages) Parameters model string The model ID to use for the request. messages List The messages to send to the model. maxTokens int The maximum number of tokens to generate. system string The system prompt to use for the request. metadata Dictionary The metadata to include with the request. temperature decimal The temperature to use for the request. topK int? The top-K value to use for the request. topP decimal? The top-P value to use for the request. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. stream bool A value indicating whether the message should be streamed. stopSequences List The prompt stop sequences. systemMessages List The system messages to use for the request. Exceptions ArgumentException Thrown when the model ID is invalid. ArgumentNullException Thrown when the model or messages is null. ArgumentException Thrown when the messages contain no messages. ArgumentException Thrown when the max tokens is less than one. ArgumentException Thrown when the temperature is less than zero or greater than one. Properties MaxTokens Gets the maximum number of tokens to generate. [JsonPropertyName(\"max_tokens\")] public int MaxTokens { get; init; } Property Value int Messages Gets the messages to send to the model. public List Messages { get; init; } Property Value List Metadata Gets the metadata to include with the request. public Dictionary? Metadata { get; init; } Property Value Dictionary Model Gets the model ID to use for the request. public string Model { get; init; } Property Value string StopSequences Gets the prompt stop sequences. [JsonPropertyName(\"stop_sequences\")] public List StopSequences { get; init; } Property Value List Stream Gets a value indicating whether the message should be streamed. public bool Stream { get; init; } Property Value bool System Gets the system message that will be used as the system prompt if no system messages are provided. [JsonIgnore] public string? System { get; init; } Property Value string SystemMessages Gets the system messages to send to the model to be used as the system prompt. [JsonIgnore] public List? SystemMessages { get; init; } Property Value List SystemPrompt Gets the system prompt that will be used for the request. If will return the system messages if they are provided, otherwise it will return the system message. If neither are provided, it will return null. [JsonPropertyName(\"system\")] public List? SystemPrompt { get; } Property Value List Temperature Gets the temperature to use for the request. public decimal Temperature { get; init; } Property Value decimal ToolChoice Gets the tool choice mode to use for the request. [JsonPropertyName(\"tool_choice\")] public ToolChoice? ToolChoice { get; init; } Property Value ToolChoice Tools Gets the tools to use for the request. public List? Tools { get; init; } Property Value List TopK Gets the top-K value to use for the request. public int? TopK { get; init; } Property Value int? TopP Gets the top-P value to use for the request. public decimal? TopP { get; init; } Property Value decimal?" + "keywords": "Class BaseMessageRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a message request. public abstract class BaseMessageRequest Inheritance object BaseMessageRequest Derived MessageRequest StreamMessageRequest Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors BaseMessageRequest(string, List, int, string?, Dictionary?, decimal, int?, decimal?, ToolChoice?, List?, bool, List?, List?) Initializes a new instance of the BaseMessageRequest class. protected BaseMessageRequest(string model, List messages, int maxTokens, string? system, Dictionary? metadata, decimal temperature, int? topK, decimal? topP, ToolChoice? toolChoice, List? tools, bool stream, List? stopSequences, List? systemMessages) Parameters model string The model ID to use for the request. messages List The messages to send to the model. maxTokens int The maximum number of tokens to generate. system string The system prompt to use for the request. metadata Dictionary The metadata to include with the request. temperature decimal The temperature to use for the request. topK int? The top-K value to use for the request. topP decimal? The top-P value to use for the request. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. stream bool A value indicating whether the message should be streamed. stopSequences List The prompt stop sequences. systemMessages List The system messages to use for the request. Exceptions ArgumentNullException Thrown when the model or messages is null. ArgumentException Thrown when the messages contain no messages. ArgumentException Thrown when the max tokens is less than one. ArgumentException Thrown when the temperature is less than zero or greater than one. Properties MaxTokens Gets the maximum number of tokens to generate. [JsonPropertyName(\"max_tokens\")] public int MaxTokens { get; init; } Property Value int Messages Gets the messages to send to the model. public List Messages { get; init; } Property Value List Metadata Gets the metadata to include with the request. public Dictionary? Metadata { get; init; } Property Value Dictionary Model Gets the model ID to use for the request. public string Model { get; init; } Property Value string StopSequences Gets the prompt stop sequences. [JsonPropertyName(\"stop_sequences\")] public List StopSequences { get; init; } Property Value List Stream Gets a value indicating whether the message should be streamed. public bool Stream { get; init; } Property Value bool System Gets the system message that will be used as the system prompt if no system messages are provided. [JsonIgnore] public string? System { get; init; } Property Value string SystemMessages Gets the system messages to send to the model to be used as the system prompt. [JsonIgnore] public List? SystemMessages { get; init; } Property Value List SystemPrompt Gets the system prompt that will be used for the request. If will return the system messages if they are provided, otherwise it will return the system message. If neither are provided, it will return null. [JsonPropertyName(\"system\")] public List? SystemPrompt { get; } Property Value List Temperature Gets the temperature to use for the request. public decimal Temperature { get; init; } Property Value decimal ToolChoice Gets the tool choice mode to use for the request. [JsonPropertyName(\"tool_choice\")] public ToolChoice? ToolChoice { get; init; } Property Value ToolChoice Tools Gets the tools to use for the request. public List? Tools { get; init; } Property Value List TopK Gets the top-K value to use for the request. public int? TopK { get; init; } Property Value int? TopP Gets the top-P value to use for the request. public decimal? TopP { get; init; } Property Value decimal?" }, "api/AnthropicClient.Models.CacheControl.html": { "href": "api/AnthropicClient.Models.CacheControl.html", @@ -104,6 +104,11 @@ "title": "Class ContentType | AnthropicClient", "keywords": "Class ContentType Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents the content type. public static class ContentType Inheritance object ContentType Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Fields Document Represents the document content type. public const string Document = \"document\" Field Value string Image Represents the image content type. public const string Image = \"image\" Field Value string Text Represents the text content type. public const string Text = \"text\" Field Value string ToolResult Represents the tool result content type. public const string ToolResult = \"tool_result\" Field Value string ToolUse Represents the tool use content type. public const string ToolUse = \"tool_use\" Field Value string" }, + "api/AnthropicClient.Models.CountMessageTokensRequest.html": { + "href": "api/AnthropicClient.Models.CountMessageTokensRequest.html", + "title": "Class CountMessageTokensRequest | AnthropicClient", + "keywords": "Class CountMessageTokensRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a request to count the number of tokens in a message. public class CountMessageTokensRequest Inheritance object CountMessageTokensRequest Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors CountMessageTokensRequest(string, List, ToolChoice?, List?, List?) Initializes a new instance of the CountMessageTokensRequest class. public CountMessageTokensRequest(string model, List messages, ToolChoice? toolChoice = null, List? tools = null, List? systemPrompt = null) Parameters model string The model ID to use for the request. messages List The messages to count the number of tokens in. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. systemPrompt List The system prompt to use for the request. Exceptions ArgumentNullException Thrown when model or messages is null. ArgumentException Thrown when messages is empty. Properties Messages Gets the messages to count the number of tokens in. public List Messages { get; init; } Property Value List Model Gets the model ID to be used for the request. public string Model { get; init; } Property Value string SystemPrompt Gets the system prompt to use for the request. [JsonPropertyName(\"system\")] public List? SystemPrompt { get; init; } Property Value List ToolChoice Gets the tool choice mode to use for the request. [JsonPropertyName(\"tool_choice\")] public ToolChoice? ToolChoice { get; init; } Property Value ToolChoice Tools Gets the tools to use for the request. public List? Tools { get; init; } Property Value List" + }, "api/AnthropicClient.Models.DocumentContent.html": { "href": "api/AnthropicClient.Models.DocumentContent.html", "title": "Class DocumentContent | AnthropicClient", @@ -217,7 +222,7 @@ "api/AnthropicClient.Models.MessageRequest.html": { "href": "api/AnthropicClient.Models.MessageRequest.html", "title": "Class MessageRequest | AnthropicClient", - "keywords": "Class MessageRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a message request. public class MessageRequest : BaseMessageRequest Inheritance object BaseMessageRequest MessageRequest Inherited Members BaseMessageRequest.Model BaseMessageRequest.System BaseMessageRequest.SystemMessages BaseMessageRequest.SystemPrompt BaseMessageRequest.Messages BaseMessageRequest.MaxTokens BaseMessageRequest.Metadata BaseMessageRequest.StopSequences BaseMessageRequest.Temperature BaseMessageRequest.TopK BaseMessageRequest.TopP BaseMessageRequest.ToolChoice BaseMessageRequest.Tools BaseMessageRequest.Stream object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors MessageRequest(string, List, int, string?, Dictionary?, decimal, int?, decimal?, ToolChoice?, List?, List?, List?) Initializes a new instance of the MessageRequest class. public MessageRequest(string model, List messages, int maxTokens = 1024, string? system = null, Dictionary? metadata = null, decimal temperature = 0.0, int? topK = null, decimal? topP = null, ToolChoice? toolChoice = null, List? tools = null, List? stopSequences = null, List? systemMessages = null) Parameters model string The model ID to use for the request. messages List The messages to send to the model. maxTokens int The maximum number of tokens to generate. system string The system prompt to use for the request. metadata Dictionary The metadata to include with the request. temperature decimal The temperature to use for the request. topK int? The top-K value to use for the request. topP decimal? The top-P value to use for the request. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. stopSequences List The prompt stop sequences. systemMessages List The system messages to include with the request. Exceptions ArgumentException Thrown when the model ID is invalid. ArgumentNullException Thrown when the model or messages is null. ArgumentException Thrown when the messages contain no messages. ArgumentException Thrown when the max tokens is less than one. ArgumentException Thrown when the temperature is less than zero or greater than one." + "keywords": "Class MessageRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a message request. public class MessageRequest : BaseMessageRequest Inheritance object BaseMessageRequest MessageRequest Inherited Members BaseMessageRequest.Model BaseMessageRequest.System BaseMessageRequest.SystemMessages BaseMessageRequest.SystemPrompt BaseMessageRequest.Messages BaseMessageRequest.MaxTokens BaseMessageRequest.Metadata BaseMessageRequest.StopSequences BaseMessageRequest.Temperature BaseMessageRequest.TopK BaseMessageRequest.TopP BaseMessageRequest.ToolChoice BaseMessageRequest.Tools BaseMessageRequest.Stream object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors MessageRequest(string, List, int, string?, Dictionary?, decimal, int?, decimal?, ToolChoice?, List?, List?, List?) Initializes a new instance of the MessageRequest class. public MessageRequest(string model, List messages, int maxTokens = 1024, string? system = null, Dictionary? metadata = null, decimal temperature = 0.0, int? topK = null, decimal? topP = null, ToolChoice? toolChoice = null, List? tools = null, List? stopSequences = null, List? systemMessages = null) Parameters model string The model ID to use for the request. messages List The messages to send to the model. maxTokens int The maximum number of tokens to generate. system string The system prompt to use for the request. metadata Dictionary The metadata to include with the request. temperature decimal The temperature to use for the request. topK int? The top-K value to use for the request. topP decimal? The top-P value to use for the request. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. stopSequences List The prompt stop sequences. systemMessages List The system messages to include with the request. Exceptions ArgumentNullException Thrown when the model or messages is null. ArgumentException Thrown when the messages contain no messages. ArgumentException Thrown when the max tokens is less than one. ArgumentException Thrown when the temperature is less than zero or greater than one." }, "api/AnthropicClient.Models.MessageResponse.html": { "href": "api/AnthropicClient.Models.MessageResponse.html", @@ -277,7 +282,7 @@ "api/AnthropicClient.Models.StreamMessageRequest.html": { "href": "api/AnthropicClient.Models.StreamMessageRequest.html", "title": "Class StreamMessageRequest | AnthropicClient", - "keywords": "Class StreamMessageRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a message request. public class StreamMessageRequest : BaseMessageRequest Inheritance object BaseMessageRequest StreamMessageRequest Inherited Members BaseMessageRequest.Model BaseMessageRequest.System BaseMessageRequest.SystemMessages BaseMessageRequest.SystemPrompt BaseMessageRequest.Messages BaseMessageRequest.MaxTokens BaseMessageRequest.Metadata BaseMessageRequest.StopSequences BaseMessageRequest.Temperature BaseMessageRequest.TopK BaseMessageRequest.TopP BaseMessageRequest.ToolChoice BaseMessageRequest.Tools BaseMessageRequest.Stream object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors StreamMessageRequest(string, List, int, string?, Dictionary?, decimal, int?, decimal?, ToolChoice?, List?, List?, List?) Initializes a new instance of the StreamMessageRequest class. public StreamMessageRequest(string model, List messages, int maxTokens = 1024, string? system = null, Dictionary? metadata = null, decimal temperature = 0.0, int? topK = null, decimal? topP = null, ToolChoice? toolChoice = null, List? tools = null, List? stopSequences = null, List? systemMessages = null) Parameters model string The model ID to use for the request. messages List The messages to send to the model. maxTokens int The maximum number of tokens to generate. system string The system prompt to use for the request. metadata Dictionary The metadata to include with the request. temperature decimal The temperature to use for the request. topK int? The top-K value to use for the request. topP decimal? The top-P value to use for the request. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. stopSequences List The prompt stop sequences. systemMessages List The system messages to include with the request. Exceptions ArgumentException Thrown when the model ID is invalid. ArgumentNullException Thrown when the model or messages is null. ArgumentException Thrown when the messages contain no messages. ArgumentException Thrown when the max tokens is less than one. ArgumentException Thrown when the temperature is less than zero or greater than one." + "keywords": "Class StreamMessageRequest Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a message request. public class StreamMessageRequest : BaseMessageRequest Inheritance object BaseMessageRequest StreamMessageRequest Inherited Members BaseMessageRequest.Model BaseMessageRequest.System BaseMessageRequest.SystemMessages BaseMessageRequest.SystemPrompt BaseMessageRequest.Messages BaseMessageRequest.MaxTokens BaseMessageRequest.Metadata BaseMessageRequest.StopSequences BaseMessageRequest.Temperature BaseMessageRequest.TopK BaseMessageRequest.TopP BaseMessageRequest.ToolChoice BaseMessageRequest.Tools BaseMessageRequest.Stream object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors StreamMessageRequest(string, List, int, string?, Dictionary?, decimal, int?, decimal?, ToolChoice?, List?, List?, List?) Initializes a new instance of the StreamMessageRequest class. public StreamMessageRequest(string model, List messages, int maxTokens = 1024, string? system = null, Dictionary? metadata = null, decimal temperature = 0.0, int? topK = null, decimal? topP = null, ToolChoice? toolChoice = null, List? tools = null, List? stopSequences = null, List? systemMessages = null) Parameters model string The model ID to use for the request. messages List The messages to send to the model. maxTokens int The maximum number of tokens to generate. system string The system prompt to use for the request. metadata Dictionary The metadata to include with the request. temperature decimal The temperature to use for the request. topK int? The top-K value to use for the request. topP decimal? The top-P value to use for the request. toolChoice ToolChoice The tool choice mode to use for the request. tools List The tools to use for the request. stopSequences List The prompt stop sequences. systemMessages List The system messages to include with the request. Exceptions ArgumentNullException Thrown when the model or messages is null. ArgumentException Thrown when the messages contain no messages. ArgumentException Thrown when the max tokens is less than one. ArgumentException Thrown when the temperature is less than zero or greater than one." }, "api/AnthropicClient.Models.TextContent.html": { "href": "api/AnthropicClient.Models.TextContent.html", @@ -289,6 +294,11 @@ "title": "Class TextDelta | AnthropicClient", "keywords": "Class TextDelta Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a text delta. public class TextDelta : ContentDelta Inheritance object ContentDelta TextDelta Inherited Members ContentDelta.Type object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Constructors TextDelta(string) Initializes a new instance of the TextDelta class. public TextDelta(string text) Parameters text string The text. Properties Text Gets the text. public string Text { get; set; } Property Value string" }, + "api/AnthropicClient.Models.TokenCountResponse.html": { + "href": "api/AnthropicClient.Models.TokenCountResponse.html", + "title": "Class TokenCountResponse | AnthropicClient", + "keywords": "Class TokenCountResponse Namespace AnthropicClient.Models Assembly AnthropicClient.dll Represents a response to a token count request. public class TokenCountResponse Inheritance object TokenCountResponse Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Properties InputTokens The number of input tokens counted. [JsonPropertyName(\"input_tokens\")] public int InputTokens { get; init; } Property Value int" + }, "api/AnthropicClient.Models.Tool.html": { "href": "api/AnthropicClient.Models.Tool.html", "title": "Class Tool | AnthropicClient", @@ -332,7 +342,7 @@ "api/AnthropicClient.Models.html": { "href": "api/AnthropicClient.Models.html", "title": "Namespace AnthropicClient.Models | AnthropicClient", - "keywords": "Namespace AnthropicClient.Models Classes AnthropicError Represents an error response from the Anthropic API. AnthropicEvent Represents an event from the Anthropic API. AnthropicFunction Represents a function that can be provided as a tool. AnthropicHeaders Represents headers included in Anthropic API responses. AnthropicModels Provides constants for the Anthropic models. AnyToolChoice Represents the any tool choice mode. ApiError Represents an api_error response from the Anthropic API. AuthenticationError Represents an authentication_error response from the Anthropic API. AutoToolChoice Represents the auto tool choice mode. BaseMessageRequest Represents a message request. CacheControl Represents the cache control to be used for content. CacheControlType Provides constants for cache control types. Content Represents part of the content of a message. ContentDelta Represents a content delta. ContentDeltaEventData Represents data for a content_block_delta event. ContentDeltaType Provides constants for content delta types. ContentStartEventData Represents data for a content_block_start event. ContentStopEventData Represents data for a content_block_stop event. ContentType Represents the content type. DocumentContent Represents content from a document that is part of a message. DocumentSource Represents a document source. EphemeralCacheControl Represents the cache control to be used for content. Error Represents an error. ErrorEventData Represents data for an error event. ErrorType Represents the error type. EventData Represents data for an event. EventType Provides constants for event types. FunctionParameterAttribute Attribute to describe a function parameter. FunctionPropertyAttribute Attribute to describe a property of a type that is used as a function parameter. ImageContent Represents image content that is part of a message. ImageSource Represents an image source. ImageType Represents the image type. InputProperty Represents an input property. InputSchema Represents an input schema. InvalidRequestError Represents an invalid_request error. JsonDelta Represents a JSON delta. Message Represents a message. MessageCompleteEventData Represents data for the message_complete event. MessageDelta Represents a message delta. MessageDeltaEventData Represents data for a message_delta event. MessageRequest Represents a message request. MessageResponse Represents a response. MessageRole Represents the message role. MessageStartEventData Represents data for a message_start event. MessageStopEventData Represents data for a message_stop event. NotFoundError Represents a not_found error. OverloadedError Represents an overloaded error. PermissionError Represents a permission error. PingEventData Represents data for a ping event. RateLimitError Represents a rate_limit error. SpecificToolChoice Represents the specific tool choice mode. StopReasonType Represents the stop reason type. StreamMessageRequest Represents a message request. TextContent Represents text content that is part of a message. TextDelta Represents a text delta. Tool Represents a tool that can be used. ToolCall Represents a tool call. ToolCallResult Represents a tool call result. ToolChoice Represents a tool choice mode. ToolChoiceType Represents the tool choice type. ToolResultContent Represents tool result content that is part of a message. ToolUseContent Represents tool use content that is part of a message. Usage Represents the usage of a response. Interfaces ITool Interface that a class can implement to be used to create a tool." + "keywords": "Namespace AnthropicClient.Models Classes AnthropicError Represents an error response from the Anthropic API. AnthropicEvent Represents an event from the Anthropic API. AnthropicFunction Represents a function that can be provided as a tool. AnthropicHeaders Represents headers included in Anthropic API responses. AnthropicModels Provides constants for the Anthropic models. AnyToolChoice Represents the any tool choice mode. ApiError Represents an api_error response from the Anthropic API. AuthenticationError Represents an authentication_error response from the Anthropic API. AutoToolChoice Represents the auto tool choice mode. BaseMessageRequest Represents a message request. CacheControl Represents the cache control to be used for content. CacheControlType Provides constants for cache control types. Content Represents part of the content of a message. ContentDelta Represents a content delta. ContentDeltaEventData Represents data for a content_block_delta event. ContentDeltaType Provides constants for content delta types. ContentStartEventData Represents data for a content_block_start event. ContentStopEventData Represents data for a content_block_stop event. ContentType Represents the content type. CountMessageTokensRequest Represents a request to count the number of tokens in a message. DocumentContent Represents content from a document that is part of a message. DocumentSource Represents a document source. EphemeralCacheControl Represents the cache control to be used for content. Error Represents an error. ErrorEventData Represents data for an error event. ErrorType Represents the error type. EventData Represents data for an event. EventType Provides constants for event types. FunctionParameterAttribute Attribute to describe a function parameter. FunctionPropertyAttribute Attribute to describe a property of a type that is used as a function parameter. ImageContent Represents image content that is part of a message. ImageSource Represents an image source. ImageType Represents the image type. InputProperty Represents an input property. InputSchema Represents an input schema. InvalidRequestError Represents an invalid_request error. JsonDelta Represents a JSON delta. Message Represents a message. MessageCompleteEventData Represents data for the message_complete event. MessageDelta Represents a message delta. MessageDeltaEventData Represents data for a message_delta event. MessageRequest Represents a message request. MessageResponse Represents a response. MessageRole Represents the message role. MessageStartEventData Represents data for a message_start event. MessageStopEventData Represents data for a message_stop event. NotFoundError Represents a not_found error. OverloadedError Represents an overloaded error. PermissionError Represents a permission error. PingEventData Represents data for a ping event. RateLimitError Represents a rate_limit error. SpecificToolChoice Represents the specific tool choice mode. StopReasonType Represents the stop reason type. StreamMessageRequest Represents a message request. TextContent Represents text content that is part of a message. TextDelta Represents a text delta. TokenCountResponse Represents a response to a token count request. Tool Represents a tool that can be used. ToolCall Represents a tool call. ToolCallResult Represents a tool call result. ToolChoice Represents a tool choice mode. ToolChoiceType Represents the tool choice type. ToolResultContent Represents tool result content that is part of a message. ToolUseContent Represents tool use content that is part of a message. Usage Represents the usage of a response. Interfaces ITool Interface that a class can implement to be used to create a tool." }, "api/AnthropicClient.html": { "href": "api/AnthropicClient.html", @@ -342,6 +352,6 @@ "index.html": { "href": "index.html", "title": "AnthropicClient | AnthropicClient", - "keywords": "AnthropicClient This library for the Anthropic API is meant to simplify development in C# for Anthropic users. Note This is an unofficial SDK for the Anthropic API. It was not built in consultation with Anthropic or any member of their organization. This SDK was developed independently using existing libraries and the Anthropic API documentation as the starting point with the intention of making development of integrations done in C# with Anthropic quicker and more convenient. Note This client library is heavily inspired by the Anthropic.SDK library. I chose to create a new library because I wanted to handle streaming and tool calling differently as well as have control over the client library as I plan to use it to build a connector for SemanticKernel. However if you are looking for a client library the Anthropic.SDK is a great place to start. \uD83D\uDCDD Issues If you encounter any issues while using this library please open an issue here. \uD83D\uDCDC License This library is licensed under the MIT License and is free to use and modify. \uD83D\uDCDD Contributing If you would like to contribute to this library please open a pull request here. \uD83D\uDEE0️ Dependencies Microsoft.Bcl.AsyncInterfaces Used to support async interfaces when streaming messages System.Text.Json Used for JSON serialization and deserialization \uD83D\uDCBE Installation Install the package from NuGet using the following command: dotnet add package AnthropicClient \uD83D\uDD11 API Key In order to use the Anthropic API you will need an API key. You can get one by signing up at Anthropic. Please keep your API key secure and do not share it with others. Be mindful of where you store your API key and do not commit it to a public repository. \uD83D\uDC68\uD83C\uDFFB‍\uD83D\uDCBB Start Coding AnthropicApiClient The most common way to use the SDK is to create an AnthropicApiClient instance and call its methods. Its constructor requires two parameters: apiKey - your Anthropic API key httpClient - an HttpClient instance. You can configure and customize the HttpClient instance as needed. This library however will perform the necessary configuration to work with the Anthropic API. Such as setting the base address and adding the proper headers. Note This library does not manage the lifecycle of the HttpClient instance. You should create and manage the lifecycle of the HttpClient instance in your application. It is best practice to read the API key from a secure location such as a configuration file or environment variable. For example using the appsettings.json file: { \"AnthropicApiKey\": \"YOUR_API\" } Example constructing an AnthropicApiClient instance: using AnthropicClient; using Microsoft.Extensions.Configuration; var configuration = new ConfigurationBuilder() .AddJsonFile(\"appsettings.json\") .Build(); var apiKey = configuration[\"AnthropicApiKey\"]; var client = new AnthropicApiClient(apiKey, new HttpClient()); IAnthropicApiClient The library does expose an interface IAnthropicApiClient that can be used for dependency injection and testing. The interface is implemented by the AnthropicApiClient class. Full API Documentation This library was developed to make using the Anthropic API easier within a .NET application. If you are looking for the full API documentation you can find it at Anthropic API Documentation. Usage The primary use case for working with the Anthropic API is to create a message in response to a request that includes one or more other messages. The created message can then be received either as a complete response or a stream of events. This can be used to create a conversation between the caller and Anthropic's AI models and/or to use Anthropic's AI models to perform a task. Note The following examples assume that you have already created an instance of the AnthropicApiClient class named client. You can also find these snippets in the examples directory. Create a message The AnthropicApiClient exposes a single method named CreateMessageAsync that can be used to create a message. The method requires a MessageRequest or a StreamMessageRequest instance as a parameter. The MessageRequest class is used to create a message whose response is not streamed and the StreamMessageRequest class is used to create a message whose response is streamed. The MessageRequest instance's properties can be set to configure how the message is created. Non-Streaming using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Streaming Anthropic uses Server-Sent Events (SSE) to stream messages. The possible events and the format of those events are documented in the Anthropic API Documentation. This library provides a way to consume them after they have been deserialized into strongly-typed C# objects that are returned in an IAsyncEnumerable collection. This allows you to consume the events as they are received and process them in the way that best fits your use case. The following example demonstrates how to consume the streamed events and build up the complete text response from the model. using AnthropicClient; using AnthropicClient.Models; var events = client.CreateMessageAsync(new StreamMessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); var msgBuilder = new StringBuilder(); await foreach (var e in events) { switch (e.Data) { case var data when data is ContentDeltaEventData contentData: switch (contentData.Delta) { case var delta when delta is TextDelta textDelta: msgBuilder.Append(textDelta.Text); break; } break; } } Console.WriteLine(msgBuilder.ToString()); Message Complete Event This library also provides a custom message_complete event that is yielded when all the message's events have been received. This event is not part of Anthropic's SSE events but is provided to allow for easier consumption of the entire message response if desired and make it easier to implement built-in tool calling. using AnthropicClient; using AnthropicClient.Models; var events = client.CreateMessageAsync(new StreamMessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); MessageResponse? response = null; await foreach (var e in events) { switch (e.Data) { case var data when data is MessageCompleteEventData msgData: response = msgData.Message; break; } } var textContent = response?.Content .OfType() .Aggregate(new StringBuilder(), (sb, c) => sb.Append(c.Text)) .ToString(); Console.WriteLine(textContent); Tool Use Anthropic's models support the use of tools to perform tasks. This allows the models to interact with external client-side tools that can perform actions the models cannot do natively. This gives you the ability to further extend the model's abilities with your own custom tools. This feature is covered in depth in Anthropic's API Documentation. This library aims to make using tools convenient by allowing you to create, provide, and call tools from within your application by leveraging the reflection capabilities of C#. Note All tools are user provided. The models do no not have access to any built-in server-side tools. Create a tool You can create a tool in 4 different ways and then provide that tool when creating a message. Create a tool from a class Create a tool from a static method Create a tool from an instance method Create a tool from a delegate Create a tool from a class When creating a tool from a class the class must implement the ITool interface. using AnthropicClient.Models; class GetWeatherTool : ITool { public string Name => \"Get Weather\"; public string Description => \"Get the weather for a location in the specified units\"; public MethodInfo Function => typeof(GetWeatherTool).GetMethod(nameof(GetWeather))!; public static string GetWeather(string location, string units) { return $\"The weather in {location} is 72 degrees {units}\"; } } var getWeatherTool = Tool.CreateFromClass(); Create a tool from a static method When creating a tool from a static method the method must be public and static. using AnthropicClient.Models; class GetWeatherTool { public static string GetWeather(string location) { return $\"The weather in {location} is 72 degrees Fahrenheit\"; } } var getWeatherTool = Tool.CreateFromStaticMethod( \"Get Weather\", \"Get the weather for a location in the specified units\", typeof(GetWeatherTool), nameof(GetWeatherTool.GetWeather) ); Create a tool from an instance method When creating a tool from an instance method the method must be public and non-static. using AnthropicClient.Models; class GetWeatherTool { public string GetWeather(string location) { return $\"The weather in {location} is 72 degrees Fahrenheit\"; } } var toolInstance = new GetWeatherTool(); var getWeatherTool = Tool.CreateFromInstanceMethod( \"Get Weather\", \"Get the weather for a location in the specified units\", toolInstance, nameof(toolInstance.GetWeather) ); Create a tool from a delegate When creating a tool from a delegate the delegate must be a Func, Func, or Func. If you need to create a tool from a delegate that takes more than 2 parameters you should create a complex type and pass that as the parameter. using AnthropicClient.Models; var tool = (string location, string units) => $\"The weather in {location} is 72 degrees {units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool ); Function Parameter Attribute When you create a tool from one of the methods above and send it to Anthropic in your request a JSON representation of the tool is provided in the message. This JSON representation includes the name, description, and input schema of the tool. This information is used by Anthropic's models to discern if and when it should use a tool. This library provides a FunctionParameterAttribute that can be used to provide additional information about the parameters of the tool. This information is used to provide a more detailed input schema for the tool. using AnthropicClient.Models; var tool = ( [FunctionParameter(description: \"The location of the weather being got\", name: \"Location\", required: true)] string location, string units ) => $\"The weather in {location} is 72 degrees {units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool ); Function Property Attribute This library also provides a FunctionPropertyAttribute that can be used to provide additional information about the members of complex types used as parameters in the tool. This information is used to provide a more detailed input schema for the tool. using AnthropicClient.Models; class GetWeatherInput { [FunctionProperty( description: \"The location of the weather being got\", required: true )] public string Location { get; } = string.Empty; [FunctionProperty( description: \"The units to get the weather in\", required: false, defaultValue: \"Fahrenheit\", possibleValues: [\"Fahrenheit\", \"Celsius\"] )] public string Units { get; } = \"Fahrenheit\"; } var tool = (GetWeatherInput input) => $\"The weather in {input.Location} is 72 degrees {input.Units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool ); Call a tool It is important to remember that while Anthropic's models do support tool use they don't actually have access to any built-in server-side tools. All tools are user provided. This means that while Anthropic's models can respond to a request to create a message with a request to use a tool that is all it is - a request. It is still up to the client to handle the tool request by calling the tool with the input provided by the model and then providing the result of that call back to the model. This library aims to make this process convenient by allowing you to simply provide the tools you want Anthropic's models to consider for use when creating a message, receive the response, check if the response contains a tool call, and if it does invoke the tool to get the result. Note Anthropic's API expects requests to contain messages that alternate between the user and the assistant. In addition if you receive a tool use from the model the API expects you to respond with a message that contains the result of the tool call. The tool use content will always be from the assistant while the tool result will always be from the user. using AnthropicClient; using AnthropicClient.Models; class GetWeatherTool : ITool { public string Name => \"Get Weather\"; public string Description => \"Get the weather for a location in the specified units\"; public MethodInfo Function => typeof(GetWeatherTool).GetMethod(nameof(GetWeather))!; public static string GetWeather(string location, string units) { return $\"The weather in {location} is 72 degrees {units}\"; } } List messages = [ new( MessageRole.User, [new TextContent(\"What is the weather in New York?\")] ) ]; List tools = [Tool.CreateFromClass()]; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } messages.Add(new(MessageRole.Assistant, response.Content)); foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; case ToolUseContent toolUseContent: Console.WriteLine(toolUseContent.Name); break; } } if (response.Value.ToolCall is not null) { var toolCallResult = await response.Value.ToolCall.InvokeAsync(); string toolResultContent; if (toolCallResult.IsSuccess && toolCallResult.Value is not null) { Console.WriteLine(toolCallResult.Value); toolResultContent = toolCallResult.Value; } else { Console.WriteLine(toolCallResult.Error.Message); toolResultContent = toolCallResult.Error.Message; } messages.Add( new( MessageRole.User, [ new ToolResultContent( response.Value.ToolCall.ToolUse.Id, toolResultContent ) ] ) ); } var finalResponse = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); if (finalResponse.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", finalResponse.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", finalResponse.Error.Error.Message); return; } foreach (var content in finalResponse.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } If an exception is thrown while invoking the tool the InvokeAsync method will return a ToolCallResult with the exception contained in the Error property. Note The InvokeAsync method does accept a generic type parameter that can be used to specify the type of the Value property of the ToolCallResult. If it is not specified it will be an object. Call a tool in streamed message Tool calling is also supported when streaming the message response. The following example demonstrates how you can handle a tool call in a streamed message response. using AnthropicClient; using AnthropicClient.Models; var tool = (string location, string units) => $\"The weather in {location} is 72 degrees {units}\"; var messages = [ new( MessageRole.User, [new TextContent(\"What is the weather in New York?\")] ) ]; var tools = [Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool )]; var events = client.CreateMessageAsync(new StreamMessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); MessageResponse? response = null; await foreach (var e in events) { switch (e.Data) { case var data when data is MessageCompleteEventData msgData: response = msgData.Message; break; } } if (response is null) { Console.WriteLine(\"Failed to get message response\"); return; } messages.Add(new(MessageRole.Assistant, response.Content)); if (response?.ToolCall is not null) { var toolCallResult = await response.ToolCall.InvokeAsync(); string toolResultContent; if (toolCallResult.IsSuccess && toolCallResult.Value is not null) { toolResultContent = toolCallResult.Value; } else { toolResultContent = toolCallResult.Error.Message; } messages.Add( new( MessageRole.User, [ new ToolResultContent( response.ToolCall.ToolUse.Id, toolResultContent ) ] ) ); } var finalResponse = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); if (finalResponse.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", finalResponse.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", finalResponse.Error.Error.Message); return; } foreach (var content in finalResponse.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } If you do find that you need more control over how exactly provided tools are called and how the result of those tools are returned you can avoid using the InvokeAsync method and instead use the Tool and ToolUse properties of the ToolCall instance to implement your own solution. System Prompt Anthropic's models support the use of system prompts to provide additional context to the user. This can be used to provide additional information to the user or to ask for additional information from the user. This feature is covered in depth in Anthropic's API Documentation. This library aims to make using system prompts convenient by allowing you to provide the system prompts you want Anthropic's models to consider for use when creating a message. System Message You can create a system prompt by providing a string as the system parameter in the MessageRequest or StreamMessageRequest constructor. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ], system: \"You are a internationally renowned poet. You excel at writing haikus. )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } System Messages You can create a more complex system prompt by providing a List as the systemMessages parameter in the MessageRequest or StreamMessageRequest constructor. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ], systemMessages: [ new TextContent(\"You are a internationally renowned poet. You excel at writing haikus.\"), new TextContent(\"You have been asked to write a haiku about the ocean.\") ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Prompt Caching Anthropic has recently introduced a feature called Prompt Caching that allows you to cache all or part of the prompt you send to the model. This can be used to improve the performance of your application by reducing latency and token usage. This feature is covered in depth in Anthropic's API Documentation. Note This feature is in beta and requires you to set an anthropic-beta header on your requests to use it. The value of the header should be prompt-caching-2024-07-31. When using this library you can opt-in to prompt caching by adding the required header to the HttpClient instance you provide to the AnthropicApiClient constructor. using AnthropicClient; var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add(\"anthropic-beta\", \"prompt-caching-2024-07-31\"); var client = new AnthropicApiClient(apiKey, httpClient); Prompt caching can be used to cache all parts of the prompt including system messages, user messages, and tools. You should refer to the Anthropic API Documentation for specifics on limitations and requirements for using prompt caching. This library aims to make using prompt caching convenient and give you complete control over what parts of the prompt are cached. Currently there is only one type of cache control available - EphemeralCacheControl. Caching System Messages System messages can be cached by providing a List as the systemMessages parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the TextContent instances have the CacheControl property set. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ], systemMessages: [ new TextContent(\"You are a internationally renowned poet. You excel at writing haikus. Please use the following as examples.\"), new TextContent(exampleHaikus, new EphemeralCacheControl()) ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Caching User Messages User messages can be cached by providing a List as the messages parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the Content instances have the CacheControl property set. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [ new TextContent(\"Please write a haiku about the ocean. Here are some examples of haikus I like.\"), new TextContent(exampleHaikus, new EphemeralCacheControl()) ] ), ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Caching Tools Tools can be cached by providing a List as the tools parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the Tool instances have the CacheControl property set. This property can be set after the tool is created manually or by using one of the static methods on the Tool class. using AnthropicClient; using AnthropicClient.Models; var tool = (string location, string units) => $\"The weather in {location} is 72 degrees {units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool, new EphemeralCacheControl() ); var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"What is the weather in New York?\")] ) ], tools: [ // Lots of other tools // ... getWeatherTool ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; case ToolUseContent toolUseContent: Console.WriteLine(toolUseContent.Name); break; } } PDF Support Anthropic has recently introduced a feature called PDF Support that allows Claude to support PDF input and understand both text and visual content within documents. . This feature is covered in depth in Anthropic's API Documentation. Note This feature is in beta and requires you to set an anthropic-beta header on your requests to use it. The value of the header should be pdfs-2024-09-25. When using this library you can opt-in to PDF support by adding the required header to the HttpClient instance you provide to the AnthropicApiClient constructor. using AnthropicClient; var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add(\"anthropic-beta\", \"pdfs-2024-09-25\"); var client = new AnthropicApiClient(apiKey, httpClient); PDF support can be used to provide a PDF document as input to the model. This can be used to provide additional context to the model or to ask for additional information from the model. This library aims to make using PDF support convenient by allowing you to provide the PDF document you want Anthropic's models to consider for use when creating a message. PDF Document You can provide a PDF document by providing its base64 encoded content as a DocumentContent instance in the list of messages in the MessageRequest or StreamMessageRequest constructor. using AnthropicClient; using AnthropicClient.Models; var request = new MessageRequest( model: AnthropicModels.Claude35Sonnet, messages: [ new(MessageRole.User, [new TextContent(\"What is the title of this paper?\")]), new(MessageRole.User, [new DocumentContent(\"application/pdf\", base64Data)]) ] ); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add(\"anthropic-beta\", \"pdfs-2024-09-25\"); var client = new AnthropicApiClient(apiKey, httpClient); var response = await client.CreateMessageAsync(request); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } }" + "keywords": "AnthropicClient This library for the Anthropic API is meant to simplify development in C# for Anthropic users. Note This is an unofficial SDK for the Anthropic API. It was not built in consultation with Anthropic or any member of their organization. This SDK was developed independently using existing libraries and the Anthropic API documentation as the starting point with the intention of making development of integrations done in C# with Anthropic quicker and more convenient. Note This client library is heavily inspired by the Anthropic.SDK library. I chose to create a new library because I wanted to handle streaming and tool calling differently as well as have control over the client library as I plan to use it to build a connector for SemanticKernel. However if you are looking for a client library the Anthropic.SDK is a great place to start. \uD83D\uDCDD Issues If you encounter any issues while using this library please open an issue here. \uD83D\uDCDC License This library is licensed under the MIT License and is free to use and modify. \uD83D\uDCDD Contributing If you would like to contribute to this library please open a pull request here. \uD83D\uDEE0️ Dependencies Microsoft.Bcl.AsyncInterfaces Used to support async interfaces when streaming messages System.Text.Json Used for JSON serialization and deserialization \uD83D\uDCBE Installation Install the package from NuGet using the following command: dotnet add package AnthropicClient \uD83D\uDD11 API Key In order to use the Anthropic API you will need an API key. You can get one by signing up at Anthropic. Please keep your API key secure and do not share it with others. Be mindful of where you store your API key and do not commit it to a public repository. \uD83D\uDC68\uD83C\uDFFB‍\uD83D\uDCBB Start Coding AnthropicApiClient The most common way to use the SDK is to create an AnthropicApiClient instance and call its methods. Its constructor requires two parameters: apiKey - your Anthropic API key httpClient - an HttpClient instance. You can configure and customize the HttpClient instance as needed. This library however will perform the necessary configuration to work with the Anthropic API. Such as setting the base address and adding the proper headers. Note This library does not manage the lifecycle of the HttpClient instance. You should create and manage the lifecycle of the HttpClient instance in your application. It is best practice to read the API key from a secure location such as a configuration file or environment variable. For example using the appsettings.json file: { \"AnthropicApiKey\": \"YOUR_API\" } Example constructing an AnthropicApiClient instance: using AnthropicClient; using Microsoft.Extensions.Configuration; var configuration = new ConfigurationBuilder() .AddJsonFile(\"appsettings.json\") .Build(); var apiKey = configuration[\"AnthropicApiKey\"]; var client = new AnthropicApiClient(apiKey, new HttpClient()); IAnthropicApiClient The library does expose an interface IAnthropicApiClient that can be used for dependency injection and testing. The interface is implemented by the AnthropicApiClient class. Full API Documentation This library was developed to make using the Anthropic API easier within a .NET application. If you are looking for the full API documentation you can find it at Anthropic API Documentation. Usage The primary use case for working with the Anthropic API is to create a message in response to a request that includes one or more other messages. The created message can then be received either as a complete response or a stream of events. This can be used to create a conversation between the caller and Anthropic's AI models and/or to use Anthropic's AI models to perform a task. Note The following examples assume that you have already created an instance of the AnthropicApiClient class named client. You can also find these snippets in the examples directory. Count Message Tokens The AnthropicApiClient exposes a method named CountMessageTokensAsync that can be used to count the number of tokens in a message. The method requires a CountMessageTokensRequest instance as a parameter. using AnthropicClient; using AnthropicClient.Models; var response = await client.CountMessageTokensAsync(new CountMessageTokensRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); if (response.IsFailure) { Console.WriteLine(\"Failed to count message tokens\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } Console.WriteLine(\"Token Count: {0}\", response.Value.InputTokens); Create a message The AnthropicApiClient exposes a method named CreateMessageAsync that can be used to create a message. The method requires a MessageRequest or a StreamMessageRequest instance as a parameter. The MessageRequest class is used to create a message whose response is not streamed and the StreamMessageRequest class is used to create a message whose response is streamed. The MessageRequest instance's properties can be set to configure how the message is created. Non-Streaming using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Streaming Anthropic uses Server-Sent Events (SSE) to stream messages. The possible events and the format of those events are documented in the Anthropic API Documentation. This library provides a way to consume them after they have been deserialized into strongly-typed C# objects that are returned in an IAsyncEnumerable collection. This allows you to consume the events as they are received and process them in the way that best fits your use case. The following example demonstrates how to consume the streamed events and build up the complete text response from the model. using AnthropicClient; using AnthropicClient.Models; var events = client.CreateMessageAsync(new StreamMessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); var msgBuilder = new StringBuilder(); await foreach (var e in events) { switch (e.Data) { case var data when data is ContentDeltaEventData contentData: switch (contentData.Delta) { case var delta when delta is TextDelta textDelta: msgBuilder.Append(textDelta.Text); break; } break; } } Console.WriteLine(msgBuilder.ToString()); Message Complete Event This library also provides a custom message_complete event that is yielded when all the message's events have been received. This event is not part of Anthropic's SSE events but is provided to allow for easier consumption of the entire message response if desired and make it easier to implement built-in tool calling. using AnthropicClient; using AnthropicClient.Models; var events = client.CreateMessageAsync(new StreamMessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ] )); MessageResponse? response = null; await foreach (var e in events) { switch (e.Data) { case var data when data is MessageCompleteEventData msgData: response = msgData.Message; break; } } var textContent = response?.Content .OfType() .Aggregate(new StringBuilder(), (sb, c) => sb.Append(c.Text)) .ToString(); Console.WriteLine(textContent); Tool Use Anthropic's models support the use of tools to perform tasks. This allows the models to interact with external client-side tools that can perform actions the models cannot do natively. This gives you the ability to further extend the model's abilities with your own custom tools. This feature is covered in depth in Anthropic's API Documentation. This library aims to make using tools convenient by allowing you to create, provide, and call tools from within your application by leveraging the reflection capabilities of C#. Note All tools are user provided. The models do no not have access to any built-in server-side tools. Create a tool You can create a tool in 4 different ways and then provide that tool when creating a message. Create a tool from a class Create a tool from a static method Create a tool from an instance method Create a tool from a delegate Create a tool from a class When creating a tool from a class the class must implement the ITool interface. using AnthropicClient.Models; class GetWeatherTool : ITool { public string Name => \"Get Weather\"; public string Description => \"Get the weather for a location in the specified units\"; public MethodInfo Function => typeof(GetWeatherTool).GetMethod(nameof(GetWeather))!; public static string GetWeather(string location, string units) { return $\"The weather in {location} is 72 degrees {units}\"; } } var getWeatherTool = Tool.CreateFromClass(); Create a tool from a static method When creating a tool from a static method the method must be public and static. using AnthropicClient.Models; class GetWeatherTool { public static string GetWeather(string location) { return $\"The weather in {location} is 72 degrees Fahrenheit\"; } } var getWeatherTool = Tool.CreateFromStaticMethod( \"Get Weather\", \"Get the weather for a location in the specified units\", typeof(GetWeatherTool), nameof(GetWeatherTool.GetWeather) ); Create a tool from an instance method When creating a tool from an instance method the method must be public and non-static. using AnthropicClient.Models; class GetWeatherTool { public string GetWeather(string location) { return $\"The weather in {location} is 72 degrees Fahrenheit\"; } } var toolInstance = new GetWeatherTool(); var getWeatherTool = Tool.CreateFromInstanceMethod( \"Get Weather\", \"Get the weather for a location in the specified units\", toolInstance, nameof(toolInstance.GetWeather) ); Create a tool from a delegate When creating a tool from a delegate the delegate must be a Func, Func, or Func. If you need to create a tool from a delegate that takes more than 2 parameters you should create a complex type and pass that as the parameter. using AnthropicClient.Models; var tool = (string location, string units) => $\"The weather in {location} is 72 degrees {units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool ); Function Parameter Attribute When you create a tool from one of the methods above and send it to Anthropic in your request a JSON representation of the tool is provided in the message. This JSON representation includes the name, description, and input schema of the tool. This information is used by Anthropic's models to discern if and when it should use a tool. This library provides a FunctionParameterAttribute that can be used to provide additional information about the parameters of the tool. This information is used to provide a more detailed input schema for the tool. using AnthropicClient.Models; var tool = ( [FunctionParameter(description: \"The location of the weather being got\", name: \"Location\", required: true)] string location, string units ) => $\"The weather in {location} is 72 degrees {units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool ); Function Property Attribute This library also provides a FunctionPropertyAttribute that can be used to provide additional information about the members of complex types used as parameters in the tool. This information is used to provide a more detailed input schema for the tool. using AnthropicClient.Models; class GetWeatherInput { [FunctionProperty( description: \"The location of the weather being got\", required: true )] public string Location { get; } = string.Empty; [FunctionProperty( description: \"The units to get the weather in\", required: false, defaultValue: \"Fahrenheit\", possibleValues: [\"Fahrenheit\", \"Celsius\"] )] public string Units { get; } = \"Fahrenheit\"; } var tool = (GetWeatherInput input) => $\"The weather in {input.Location} is 72 degrees {input.Units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool ); Call a tool It is important to remember that while Anthropic's models do support tool use they don't actually have access to any built-in server-side tools. All tools are user provided. This means that while Anthropic's models can respond to a request to create a message with a request to use a tool that is all it is - a request. It is still up to the client to handle the tool request by calling the tool with the input provided by the model and then providing the result of that call back to the model. This library aims to make this process convenient by allowing you to simply provide the tools you want Anthropic's models to consider for use when creating a message, receive the response, check if the response contains a tool call, and if it does invoke the tool to get the result. Note Anthropic's API expects requests to contain messages that alternate between the user and the assistant. In addition if you receive a tool use from the model the API expects you to respond with a message that contains the result of the tool call. The tool use content will always be from the assistant while the tool result will always be from the user. using AnthropicClient; using AnthropicClient.Models; class GetWeatherTool : ITool { public string Name => \"Get Weather\"; public string Description => \"Get the weather for a location in the specified units\"; public MethodInfo Function => typeof(GetWeatherTool).GetMethod(nameof(GetWeather))!; public static string GetWeather(string location, string units) { return $\"The weather in {location} is 72 degrees {units}\"; } } List messages = [ new( MessageRole.User, [new TextContent(\"What is the weather in New York?\")] ) ]; List tools = [Tool.CreateFromClass()]; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } messages.Add(new(MessageRole.Assistant, response.Content)); foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; case ToolUseContent toolUseContent: Console.WriteLine(toolUseContent.Name); break; } } if (response.Value.ToolCall is not null) { var toolCallResult = await response.Value.ToolCall.InvokeAsync(); string toolResultContent; if (toolCallResult.IsSuccess && toolCallResult.Value is not null) { Console.WriteLine(toolCallResult.Value); toolResultContent = toolCallResult.Value; } else { Console.WriteLine(toolCallResult.Error.Message); toolResultContent = toolCallResult.Error.Message; } messages.Add( new( MessageRole.User, [ new ToolResultContent( response.Value.ToolCall.ToolUse.Id, toolResultContent ) ] ) ); } var finalResponse = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); if (finalResponse.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", finalResponse.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", finalResponse.Error.Error.Message); return; } foreach (var content in finalResponse.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } If an exception is thrown while invoking the tool the InvokeAsync method will return a ToolCallResult with the exception contained in the Error property. Note The InvokeAsync method does accept a generic type parameter that can be used to specify the type of the Value property of the ToolCallResult. If it is not specified it will be an object. Call a tool in streamed message Tool calling is also supported when streaming the message response. The following example demonstrates how you can handle a tool call in a streamed message response. using AnthropicClient; using AnthropicClient.Models; var tool = (string location, string units) => $\"The weather in {location} is 72 degrees {units}\"; var messages = [ new( MessageRole.User, [new TextContent(\"What is the weather in New York?\")] ) ]; var tools = [Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool )]; var events = client.CreateMessageAsync(new StreamMessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); MessageResponse? response = null; await foreach (var e in events) { switch (e.Data) { case var data when data is MessageCompleteEventData msgData: response = msgData.Message; break; } } if (response is null) { Console.WriteLine(\"Failed to get message response\"); return; } messages.Add(new(MessageRole.Assistant, response.Content)); if (response?.ToolCall is not null) { var toolCallResult = await response.ToolCall.InvokeAsync(); string toolResultContent; if (toolCallResult.IsSuccess && toolCallResult.Value is not null) { toolResultContent = toolCallResult.Value; } else { toolResultContent = toolCallResult.Error.Message; } messages.Add( new( MessageRole.User, [ new ToolResultContent( response.ToolCall.ToolUse.Id, toolResultContent ) ] ) ); } var finalResponse = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, messages, tools: tools )); if (finalResponse.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", finalResponse.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", finalResponse.Error.Error.Message); return; } foreach (var content in finalResponse.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } If you do find that you need more control over how exactly provided tools are called and how the result of those tools are returned you can avoid using the InvokeAsync method and instead use the Tool and ToolUse properties of the ToolCall instance to implement your own solution. System Prompt Anthropic's models support the use of system prompts to provide additional context to the user. This can be used to provide additional information to the user or to ask for additional information from the user. This feature is covered in depth in Anthropic's API Documentation. This library aims to make using system prompts convenient by allowing you to provide the system prompts you want Anthropic's models to consider for use when creating a message. System Message You can create a system prompt by providing a string as the system parameter in the MessageRequest or StreamMessageRequest constructor. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ], system: \"You are a internationally renowned poet. You excel at writing haikus. )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } System Messages You can create a more complex system prompt by providing a List as the systemMessages parameter in the MessageRequest or StreamMessageRequest constructor. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ], systemMessages: [ new TextContent(\"You are a internationally renowned poet. You excel at writing haikus.\"), new TextContent(\"You have been asked to write a haiku about the ocean.\") ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Prompt Caching Anthropic provides a feature called Prompt Caching that allows you to cache all or part of the prompt you send to the model. This can be used to improve the performance of your application by reducing latency and token usage. This feature is covered in depth in Anthropic's API Documentation. Prompt caching can be used to cache all parts of the prompt including system messages, user messages, and tools. You should refer to the Anthropic API Documentation for specifics on limitations and requirements for using prompt caching. This library aims to make using prompt caching convenient and give you complete control over what parts of the prompt are cached. Currently there is only one type of cache control available - EphemeralCacheControl. Caching System Messages System messages can be cached by providing a List as the systemMessages parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the TextContent instances have the CacheControl property set. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"Please write a haiku about the ocean.\")] ) ], systemMessages: [ new TextContent(\"You are a internationally renowned poet. You excel at writing haikus. Please use the following as examples.\"), new TextContent(exampleHaikus, new EphemeralCacheControl()) ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Caching User Messages User messages can be cached by providing a List as the messages parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the Content instances have the CacheControl property set. using AnthropicClient; using AnthropicClient.Models; var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [ new TextContent(\"Please write a haiku about the ocean. Here are some examples of haikus I like.\"), new TextContent(exampleHaikus, new EphemeralCacheControl()) ] ), ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } } Caching Tools Tools can be cached by providing a List as the tools parameter in the MessageRequest or StreamMessageRequest constructor and having one or more of the Tool instances have the CacheControl property set. This property can be set after the tool is created manually or by using one of the static methods on the Tool class. using AnthropicClient; using AnthropicClient.Models; var tool = (string location, string units) => $\"The weather in {location} is 72 degrees {units}\"; var getWeatherTool = Tool.CreateFromFunction( \"Get Weather\", \"Get the weather for a location in the specified units\", tool, new EphemeralCacheControl() ); var response = await client.CreateMessageAsync(new MessageRequest( AnthropicModels.Claude3Haiku, [ new( MessageRole.User, [new TextContent(\"What is the weather in New York?\")] ) ], tools: [ // Lots of other tools // ... getWeatherTool ] )); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; case ToolUseContent toolUseContent: Console.WriteLine(toolUseContent.Name); break; } } PDF Support Anthropic provides a feature called PDF Support that allows Claude to support PDF input and understand both text and visual content within documents. This feature is covered in depth in Anthropic's API Documentation. PDF support can be used to provide a PDF document as input to the model. This can be used to provide additional context to the model or to ask for additional information from the model. This library aims to make using PDF support convenient by allowing you to provide the PDF document you want Anthropic's models to consider for use when creating a message. PDF Document You can provide a PDF document by providing its base64 encoded content as a DocumentContent instance in the list of messages in the MessageRequest or StreamMessageRequest constructor. using AnthropicClient; using AnthropicClient.Models; var request = new MessageRequest( model: AnthropicModels.Claude35Sonnet, messages: [ new(MessageRole.User, [new TextContent(\"What is the title of this paper?\")]), new(MessageRole.User, [new DocumentContent(\"application/pdf\", base64Data)]) ] ); var response = await client.CreateMessageAsync(request); if (response.IsSuccess is false) { Console.WriteLine(\"Failed to create message\"); Console.WriteLine(\"Error Type: {0}\", response.Error.Error.Type); Console.WriteLine(\"Error Message: {0}\", response.Error.Error.Message); return; } foreach (var content in response.Value.Content) { switch (content) { case TextContent textContent: Console.WriteLine(textContent.Text); break; } }" } } \ No newline at end of file diff --git a/docs/manifest.json b/docs/manifest.json index aff15a0..f90c380 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -220,6 +220,16 @@ }, "version": "" }, + { + "type": "ManagedReference", + "source_relative_path": "api/AnthropicClient.Models.CountMessageTokensRequest.yml", + "output": { + ".html": { + "relative_path": "api/AnthropicClient.Models.CountMessageTokensRequest.html" + } + }, + "version": "" + }, { "type": "ManagedReference", "source_relative_path": "api/AnthropicClient.Models.DocumentContent.yml", @@ -590,6 +600,16 @@ }, "version": "" }, + { + "type": "ManagedReference", + "source_relative_path": "api/AnthropicClient.Models.TokenCountResponse.yml", + "output": { + ".html": { + "relative_path": "api/AnthropicClient.Models.TokenCountResponse.html" + } + }, + "version": "" + }, { "type": "ManagedReference", "source_relative_path": "api/AnthropicClient.Models.Tool.yml", diff --git a/docs/xrefmap.yml b/docs/xrefmap.yml index faee5da..45fd26f 100644 --- a/docs/xrefmap.yml +++ b/docs/xrefmap.yml @@ -32,6 +32,19 @@ references: fullName.vb: AnthropicClient.AnthropicApiClient.New nameWithType: AnthropicApiClient.AnthropicApiClient nameWithType.vb: AnthropicApiClient.New +- uid: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest) + name: CountMessageTokensAsync(CountMessageTokensRequest) + href: api/AnthropicClient.AnthropicApiClient.html#AnthropicClient_AnthropicApiClient_CountMessageTokensAsync_AnthropicClient_Models_CountMessageTokensRequest_ + commentId: M:AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest) + fullName: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest) + nameWithType: AnthropicApiClient.CountMessageTokensAsync(CountMessageTokensRequest) +- uid: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync* + name: CountMessageTokensAsync + href: api/AnthropicClient.AnthropicApiClient.html#AnthropicClient_AnthropicApiClient_CountMessageTokensAsync_ + commentId: Overload:AnthropicClient.AnthropicApiClient.CountMessageTokensAsync + isSpec: "True" + fullName: AnthropicClient.AnthropicApiClient.CountMessageTokensAsync + nameWithType: AnthropicApiClient.CountMessageTokensAsync - uid: AnthropicClient.AnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.MessageRequest) name: CreateMessageAsync(MessageRequest) href: api/AnthropicClient.AnthropicApiClient.html#AnthropicClient_AnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_MessageRequest_ @@ -57,6 +70,19 @@ references: commentId: T:AnthropicClient.IAnthropicApiClient fullName: AnthropicClient.IAnthropicApiClient nameWithType: IAnthropicApiClient +- uid: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest) + name: CountMessageTokensAsync(CountMessageTokensRequest) + href: api/AnthropicClient.IAnthropicApiClient.html#AnthropicClient_IAnthropicApiClient_CountMessageTokensAsync_AnthropicClient_Models_CountMessageTokensRequest_ + commentId: M:AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest) + fullName: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync(AnthropicClient.Models.CountMessageTokensRequest) + nameWithType: IAnthropicApiClient.CountMessageTokensAsync(CountMessageTokensRequest) +- uid: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync* + name: CountMessageTokensAsync + href: api/AnthropicClient.IAnthropicApiClient.html#AnthropicClient_IAnthropicApiClient_CountMessageTokensAsync_ + commentId: Overload:AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync + isSpec: "True" + fullName: AnthropicClient.IAnthropicApiClient.CountMessageTokensAsync + nameWithType: IAnthropicApiClient.CountMessageTokensAsync - uid: AnthropicClient.IAnthropicApiClient.CreateMessageAsync(AnthropicClient.Models.MessageRequest) name: CreateMessageAsync(MessageRequest) href: api/AnthropicClient.IAnthropicApiClient.html#AnthropicClient_IAnthropicApiClient_CreateMessageAsync_AnthropicClient_Models_MessageRequest_ @@ -1078,6 +1104,96 @@ references: commentId: F:AnthropicClient.Models.ContentType.ToolUse fullName: AnthropicClient.Models.ContentType.ToolUse nameWithType: ContentType.ToolUse +- uid: AnthropicClient.Models.CountMessageTokensRequest + name: CountMessageTokensRequest + href: api/AnthropicClient.Models.CountMessageTokensRequest.html + commentId: T:AnthropicClient.Models.CountMessageTokensRequest + fullName: AnthropicClient.Models.CountMessageTokensRequest + nameWithType: CountMessageTokensRequest +- uid: AnthropicClient.Models.CountMessageTokensRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{AnthropicClient.Models.TextContent}) + name: CountMessageTokensRequest(string, List, ToolChoice?, List?, List?) + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest__ctor_System_String_System_Collections_Generic_List_AnthropicClient_Models_Message__AnthropicClient_Models_ToolChoice_System_Collections_Generic_List_AnthropicClient_Models_Tool__System_Collections_Generic_List_AnthropicClient_Models_TextContent__ + commentId: M:AnthropicClient.Models.CountMessageTokensRequest.#ctor(System.String,System.Collections.Generic.List{AnthropicClient.Models.Message},AnthropicClient.Models.ToolChoice,System.Collections.Generic.List{AnthropicClient.Models.Tool},System.Collections.Generic.List{AnthropicClient.Models.TextContent}) + name.vb: New(String, List(Of Message), ToolChoice, List(Of Tool), List(Of TextContent)) + fullName: AnthropicClient.Models.CountMessageTokensRequest.CountMessageTokensRequest(string, System.Collections.Generic.List, AnthropicClient.Models.ToolChoice?, System.Collections.Generic.List?, System.Collections.Generic.List?) + fullName.vb: AnthropicClient.Models.CountMessageTokensRequest.New(String, System.Collections.Generic.List(Of AnthropicClient.Models.Message), AnthropicClient.Models.ToolChoice, System.Collections.Generic.List(Of AnthropicClient.Models.Tool), System.Collections.Generic.List(Of AnthropicClient.Models.TextContent)) + nameWithType: CountMessageTokensRequest.CountMessageTokensRequest(string, List, ToolChoice?, List?, List?) + nameWithType.vb: CountMessageTokensRequest.New(String, List(Of Message), ToolChoice, List(Of Tool), List(Of TextContent)) +- uid: AnthropicClient.Models.CountMessageTokensRequest.#ctor* + name: CountMessageTokensRequest + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest__ctor_ + commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.#ctor + isSpec: "True" + name.vb: New + fullName: AnthropicClient.Models.CountMessageTokensRequest.CountMessageTokensRequest + fullName.vb: AnthropicClient.Models.CountMessageTokensRequest.New + nameWithType: CountMessageTokensRequest.CountMessageTokensRequest + nameWithType.vb: CountMessageTokensRequest.New +- uid: AnthropicClient.Models.CountMessageTokensRequest.Messages + name: Messages + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Messages + commentId: P:AnthropicClient.Models.CountMessageTokensRequest.Messages + fullName: AnthropicClient.Models.CountMessageTokensRequest.Messages + nameWithType: CountMessageTokensRequest.Messages +- uid: AnthropicClient.Models.CountMessageTokensRequest.Messages* + name: Messages + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Messages_ + commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.Messages + isSpec: "True" + fullName: AnthropicClient.Models.CountMessageTokensRequest.Messages + nameWithType: CountMessageTokensRequest.Messages +- uid: AnthropicClient.Models.CountMessageTokensRequest.Model + name: Model + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Model + commentId: P:AnthropicClient.Models.CountMessageTokensRequest.Model + fullName: AnthropicClient.Models.CountMessageTokensRequest.Model + nameWithType: CountMessageTokensRequest.Model +- uid: AnthropicClient.Models.CountMessageTokensRequest.Model* + name: Model + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Model_ + commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.Model + isSpec: "True" + fullName: AnthropicClient.Models.CountMessageTokensRequest.Model + nameWithType: CountMessageTokensRequest.Model +- uid: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt + name: SystemPrompt + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_SystemPrompt + commentId: P:AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt + fullName: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt + nameWithType: CountMessageTokensRequest.SystemPrompt +- uid: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt* + name: SystemPrompt + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_SystemPrompt_ + commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt + isSpec: "True" + fullName: AnthropicClient.Models.CountMessageTokensRequest.SystemPrompt + nameWithType: CountMessageTokensRequest.SystemPrompt +- uid: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice + name: ToolChoice + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_ToolChoice + commentId: P:AnthropicClient.Models.CountMessageTokensRequest.ToolChoice + fullName: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice + nameWithType: CountMessageTokensRequest.ToolChoice +- uid: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice* + name: ToolChoice + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_ToolChoice_ + commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.ToolChoice + isSpec: "True" + fullName: AnthropicClient.Models.CountMessageTokensRequest.ToolChoice + nameWithType: CountMessageTokensRequest.ToolChoice +- uid: AnthropicClient.Models.CountMessageTokensRequest.Tools + name: Tools + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Tools + commentId: P:AnthropicClient.Models.CountMessageTokensRequest.Tools + fullName: AnthropicClient.Models.CountMessageTokensRequest.Tools + nameWithType: CountMessageTokensRequest.Tools +- uid: AnthropicClient.Models.CountMessageTokensRequest.Tools* + name: Tools + href: api/AnthropicClient.Models.CountMessageTokensRequest.html#AnthropicClient_Models_CountMessageTokensRequest_Tools_ + commentId: Overload:AnthropicClient.Models.CountMessageTokensRequest.Tools + isSpec: "True" + fullName: AnthropicClient.Models.CountMessageTokensRequest.Tools + nameWithType: CountMessageTokensRequest.Tools - uid: AnthropicClient.Models.DocumentContent name: DocumentContent href: api/AnthropicClient.Models.DocumentContent.html @@ -2690,6 +2806,25 @@ references: isSpec: "True" fullName: AnthropicClient.Models.TextDelta.Text nameWithType: TextDelta.Text +- uid: AnthropicClient.Models.TokenCountResponse + name: TokenCountResponse + href: api/AnthropicClient.Models.TokenCountResponse.html + commentId: T:AnthropicClient.Models.TokenCountResponse + fullName: AnthropicClient.Models.TokenCountResponse + nameWithType: TokenCountResponse +- uid: AnthropicClient.Models.TokenCountResponse.InputTokens + name: InputTokens + href: api/AnthropicClient.Models.TokenCountResponse.html#AnthropicClient_Models_TokenCountResponse_InputTokens + commentId: P:AnthropicClient.Models.TokenCountResponse.InputTokens + fullName: AnthropicClient.Models.TokenCountResponse.InputTokens + nameWithType: TokenCountResponse.InputTokens +- uid: AnthropicClient.Models.TokenCountResponse.InputTokens* + name: InputTokens + href: api/AnthropicClient.Models.TokenCountResponse.html#AnthropicClient_Models_TokenCountResponse_InputTokens_ + commentId: Overload:AnthropicClient.Models.TokenCountResponse.InputTokens + isSpec: "True" + fullName: AnthropicClient.Models.TokenCountResponse.InputTokens + nameWithType: TokenCountResponse.InputTokens - uid: AnthropicClient.Models.Tool name: Tool href: api/AnthropicClient.Models.Tool.html