Note: The Anthropic API does not support streaming tool calls yet.
The Anthropic provider contains language model support for the Anthropic Messages API.
It creates language model objects that can be used with the generateText
and streamText
AI functions.
The Anthropic provider is available in the @khulnasoft/anthropic
module. You can install it with
npm i @khulnasoft/anthropic
You can import Anthropic
from ai/anthropic
and initialize a provider instance with various settings:
import { Anthropic } from '@khulnasoft/anthropic';
const anthropic = new Anthropic({
baseUrl: '', // optional base URL for proxies etc.
apiKey: '', // optional API key, default to env property ANTHROPIC_API_KEY
});
The AI SDK also provides a shorthand anthropic
import with a Anthropic provider instance that uses defaults:
import { anthropic } from '@khulnasoft/anthropic';
You can create models that call the Anthropic Messages API using the .messages()
factory method.
The first argument is the model id, e.g. claude-3-haiku-20240307
.
Some models have multi-modal capabilities.
const model = anthropic.messages('claude-3-haiku-20240307');
Anthropic Messages` models support also some model specific settings that are not part of the standard call settings. You can pass them as an options argument:
const model = anthropic.messages('claude-3-haiku-20240307', {
topK: 0.2,
});