Anthropic
Configure Claude, system instructions, and native image tool results
Anthropic
Claude models, system instructions, and image tools
Claude models from Anthropic. Known for safety, long context, and excellent reasoning.
Setup
1. Install Packages
npm install @yourgpt/copilot-sdk @yourgpt/llm-sdk @anthropic-ai/sdk2. Get API Key
Get your API key from console.anthropic.com
3. Add Environment Variable
ANTHROPIC_API_KEY=sk-ant-...4. Usage
import { generateText } from "@yourgpt/llm-sdk";
import { anthropic } from "@yourgpt/llm-sdk/anthropic";
const result = await generateText({
model: anthropic("claude-sonnet-4-5"),
prompt: "Explain the theory of relativity.",
});
console.log(result.text);5. Streaming (API Route)
import { streamText } from "@yourgpt/llm-sdk";
import { anthropic } from "@yourgpt/llm-sdk/anthropic";
export async function POST(req: Request) {
const { messages } = await req.json();
const result = await streamText({
model: anthropic("claude-sonnet-4-5"),
system: "You are a helpful assistant.",
messages,
});
return result.toTextStreamResponse();
}Model selection
The examples use claude-sonnet-4-5, which was used for the Anthropic prompt-delivery checks. Select a model available to your account from Anthropic's model catalog. Context limits, pricing, and supported features depend on the model; these examples are not a current model ranking.
Configuration Options
import { anthropic } from "@yourgpt/llm-sdk/anthropic";
// Custom API key
const model = anthropic("claude-sonnet-4-5", {
apiKey: "sk-ant-custom-key",
});
// With generation options
const result = await generateText({
model: anthropic("claude-sonnet-4-5"),
prompt: "Hello",
temperature: 0.7, // 0-1
maxTokens: 4096, // Max response length
});Tool Calling
Claude has robust tool support:
import { generateText, tool } from "@yourgpt/llm-sdk";
import { anthropic } from "@yourgpt/llm-sdk/anthropic";
import { z } from "zod";
const result = await generateText({
model: anthropic("claude-sonnet-4-5"),
prompt: "Analyze this document for key insights",
tools: {
analyzeDocument: tool({
description: "Analyze a document",
parameters: z.object({
documentId: z.string(),
analysisType: z.enum(["summary", "sentiment", "entities"]),
}),
execute: async ({ documentId, analysisType }) => {
return await analyzeDocument(documentId, analysisType);
},
}),
},
maxSteps: 5,
});Long Context
For Runtime calls, use systemPrompt; modern generateText/streamText use
system. Existing system-role messages are also supported. The
system prompt compatibility guide
shows both forms and explains the beta.3 fix for unusual content and duplicate
instructions. Native image results from tools are covered in
Images in tool results.
Check the selected model's context limit before sending long documents:
const result = await generateText({
model: anthropic("claude-sonnet-4-5"),
system: `You are a support agent. Here is our full documentation:
${fullDocumentation}
Answer questions based on this documentation.`,
prompt: userQuestion,
});Vision (Image Input)
Claude models support image analysis:
const result = await generateText({
model: anthropic("claude-sonnet-4-5"),
messages: [
{
role: "user",
content: [
{ type: "text", text: "Analyze this screenshot" },
{ type: "image", image: base64ImageData },
],
},
],
});With Copilot UI
Use with the Copilot React components:
"use client";
import { CopilotProvider } from "@yourgpt/copilot-sdk/react";
export function Providers({ children }: { children: React.ReactNode }) {
return <CopilotProvider runtimeUrl="/api/chat">{children}</CopilotProvider>;
}Pricing
Check Anthropic pricing for current rates. The beta does not yet add unified Anthropic cache controls or normalized cache-read/write accounting.
System instructions in Runtime
Fixed in LLM SDK 2.6.0-beta.2. Runtime now moves role: 'system' messages into Anthropic's top-level system field. Previously those messages could be filtered out without reaching the model. Existing systemPrompt behavior remains supported.
import { createRuntime } from "@yourgpt/llm-sdk";
import { createAnthropic } from "@yourgpt/llm-sdk/anthropic";
const runtime = createRuntime({
provider: createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY }),
model: "claude-sonnet-4-5",
});
const result = await runtime.chat({
systemPrompt: "Classify the user message. Reply with SUPPORT or OTHER only.",
messages: [{ role: "user", content: "I cannot sign in." }],
});Use Runtime's systemPrompt or modern generateText / streamText's system for new application-owned instructions. If you also supply system-role messages, both apply: explicit/default instructions first, then distinct system instructions in their original order. Since 2.6.0-beta.3, text duplicated between the explicit/default prompt and a system message is sent once. Null and unsupported non-text content are ignored; valid text is retained.
See system prompts for precedence, streaming, migration examples, and guardrail validation limits.
Images returned by tools
The beta maps typed image tool results to native Anthropic tool_result content, preserving accompanying text and the original application result. User image inputs and tool-output images have different shapes. This support does not add image generation or speech/transcription to the Anthropic adapter.
Next Steps
- Google - Try Gemini models
- generateText() - Full API reference
- tool() - Define tools with Zod