Skip to content

AnthropicProvider

Namespace: Vercel.AI.Anthropic

public class AnthropicProvider : ProviderBase, IBatchProvider, IDecisionProvider, IEvaluationProvider

Anthropic Messages provider.

Inheritance: object → ProviderBase

Implements: IBatchProvider, IDecisionProvider, IEvaluationProvider

Derived: AnthropicAwsProvider, GoogleVertexAnthropicProvider

View source

AnthropicProvider(HttpClient, AnthropicOptions?)

Section titled “AnthropicProvider(HttpClient, AnthropicOptions?)”
public AnthropicProvider(HttpClient httpClient, AnthropicOptions? options = null)

Creates a provider.

Parameters

Name Type Description
httpClient HttpClient
options AnthropicOptions

View source

public const string ProviderName = "anthropic"

Provider id used for dependency injection.

Value: string

View source

public static readonly string UserAgent

User agent for the Messages API.

Value: string

View source

protected bool Aws { get; set; }

True for Claude Platform on AWS.

Value: bool

View source

protected bool ExplicitBaseUrl { get; set; }

True when the caller supplied a base URL other than the public Anthropic host.

Value: bool

View source

public ProviderHttp Http { get; }

HTTP helper.

Value: ProviderHttp

View source

public string ModelProvider { get; }

Provider id reported by language models.

Value: string

View source

public AnthropicOptions Options { get; }

Options.

Value: AnthropicOptions

View source

protected virtual IReadOnlyDictionary<string, string> SupportedUrls { get; }

URL patterns that models of this provider accept for images and PDFs.

Value: IReadOnlyDictionary<string, string>

View source

protected virtual bool SupportsNativeStructuredOutput { get; }

False when the host does not accept the native output format. Structured output then uses the JSON tool.

Value: bool

View source

protected virtual bool SupportsStrictTools { get; }

False when the host does not accept strict on tool definitions.

Value: bool

View source

public static IReadOnlyList<string> Tools { get; }

Provider tool ids, such as anthropic.web_search_20250305. Pass one as a provider tool id.

Value: IReadOnlyList<string>

View source

Create(AnthropicOptions?, HttpMessageHandler?)

Section titled “Create(AnthropicOptions?, HttpMessageHandler?)”
public static AnthropicProvider Create(AnthropicOptions? options = null, HttpMessageHandler? handler = null)

Creates a provider.

Parameters

Name Type Description
options AnthropicOptions
handler HttpMessageHandler

Returns: AnthropicProvider

View source

CreateHeaders(IReadOnlyList<string>, IReadOnlyDictionary<string, string?>?)

Section titled “CreateHeaders(IReadOnlyList<string>, IReadOnlyDictionary<string, string?>?)”
public Dictionary<string, string?> CreateHeaders(IReadOnlyList<string> betas, IReadOnlyDictionary<string, string?>? callHeaders)

Headers for a Messages call that already has an API key or auth token.

Parameters

Name Type Description
betas IReadOnlyList<string>
callHeaders IReadOnlyDictionary<string, string>

Returns: Dictionary<string, string>

View source

CreateHeadersAsync(IReadOnlyList<string>, IReadOnlyDictionary<string, string?>?, string?, CancellationToken)

Section titled “CreateHeadersAsync(IReadOnlyList<string>, IReadOnlyDictionary<string, string?>?, string?, CancellationToken)”
public virtual Task<Dictionary<string, string?>> CreateHeadersAsync(IReadOnlyList<string> betas, IReadOnlyDictionary<string, string?>? callHeaders, string? body, CancellationToken cancellationToken)

Headers for a Messages call. Signs the body when AWS credentials are used.

Parameters

Name Type Description
betas IReadOnlyList<string>
callHeaders IReadOnlyDictionary<string, string>
body string
cancellationToken CancellationToken

Returns: Task<Dictionary<string, string>>

View source

public DecisionLanguageModel DecisionModel(string modelId)

Decision model. Wraps the Messages language model with structured output. The provider id is anthropic.decision.

Parameters

Name Type Description
modelId string

Returns: DecisionLanguageModel

View source

public override IEmbeddingModel EmbeddingModel(string modelId)

Returns an embedding model.

Parameters

Name Type Description
modelId string

Returns: IEmbeddingModel

View source

[Obsolete("Use DecisionModel instead.")]
public DecisionLanguageModel EvaluationModel(string modelId)

Deprecated alias of DecisionModel(string). Maps to evaluationModel.

Parameters

Name Type Description
modelId string

Returns: DecisionLanguageModel

View source

public IBatchApi? ExperimentalBatch()

Message Batches API. Downloads batch results.

Returns: IBatchApi

View source

public AnthropicFiles Files()

Files API client.

Returns: AnthropicFiles

View source

public override IImageModel ImageModel(string modelId)

Returns an image model.

Parameters

Name Type Description
modelId string

Returns: IImageModel

View source

public override ILanguageModel LanguageModel(string modelId)

Returns a language model.

Parameters

Name Type Description
modelId string

Returns: ILanguageModel

View source

public Uri MessagesUri()

Messages URL for the resolved base.

Returns: Uri

View source

public ILanguageModel New(string modelId)

Throws because the JavaScript provider function rejects new.

Parameters

Name Type Description
modelId string

Returns: ILanguageModel

View source

public string NormalizedBase()

Resolved API origin, including /v1 when the host is the public Anthropic API or a regional AWS host.

Returns: string

View source

protected virtual Uri RequestUri(string modelId, bool streaming)

URL for one model call. Defaults to MessagesUri().

Parameters

Name Type Description
modelId string
streaming bool

Returns: Uri

View source

public override IRubricModel RubricModel(string modelId)

Returns a model that scores a candidate against a rubric.

Parameters

Name Type Description
modelId string

Returns: IRubricModel

View source

public AnthropicSkills Skills()

Skills API client.

Returns: AnthropicSkills

View source

TransformRequestBody(JsonObject, IReadOnlyList<string>)

Section titled “TransformRequestBody(JsonObject, IReadOnlyList<string>)”
protected virtual JsonObject TransformRequestBody(JsonObject body, IReadOnlyList<string> betas)

Rewrites the Messages body just before it is sent. Defaults to TransformRequestBody.

Parameters

Name Type Description
body JsonObject
betas IReadOnlyList<string>

Returns: JsonObject

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product