Add your Anthropic API key in Settings
Access Claude, one of the most advanced AI models, via the Anthropic API. Claude excels at long conversations, careful instruction following, and complex reasoning tasks.
| Field | Type | Required | Description |
|---|---|---|---|
| apiKey | password | Required | Your Anthropic API key from console.anthropic.com |
Add provider:
npx webinfer provider add anthropic --key YOUR_API_KEYTest connection:
npx webinfer provider test anthropicGet your API key from https://console.anthropic.com/
Basic usage:
import { generateText } from "webinfer"
// WebInfer automatically routes to the best available provider
const result = await generateText({
prompt: "Write a haiku about programming"
})
console.log(result.text)Specify Anthropic explicitly:
import { generateText } from "webinfer"
const result = await generateText({
prompt: "Write a haiku about programming",
provider: "anthropic",
model: "claude-3-5-sonnet-20241022"
})
console.log(result.text)
console.log("Provider:", result.provider)
console.log("Model:", result.model)Streaming:
import { streamText } from "webinfer"
const { textStream } = await streamText({
prompt: "Write a story about AI",
provider: "anthropic"
})
for await (const chunk of textStream) {
process.stdout.write(chunk)
}