Get started with Claude 3.7 Sonnet
Get started with Claude 3.7 Sonnet using the AI TOOLKIT.
With the release of Claude 3.7 Sonnet, there has never been a better time to start building AI applications, particularly those that require complex reasoning capabilities. The AI TOOLKIT is a powerful TypeScript toolkit for building AI applications with large language models (LLMs) like Claude 3.7 Sonnet alongside popular frameworks like React, Next.js, Vue, Svelte, Node.js, and more.
Run it locally
$ npm install aiClaude 3.7 Sonnet
Claude 3.7 Sonnet is Anthropic's most intelligent model to date and the first Claude model to offer extended thinking—the ability to solve complex problems with careful, step-by-step reasoning. With Claude 3.7 Sonnet, you can balance speed and quality by choosing between standard thinking for near-instant responses or extended thinking or advanced reasoning. Claude 3.7 Sonnet is state-of-the-art for coding, and delivers advancements in computer use, agentic capabilities, complex reasoning, and content generation. With frontier performance and more control over speed, Claude 3.7 Sonnet is a great choice for powering AI agents, especially customer-facing agents, and complex AI workflows.
Getting Started with the AI TOOLKIT
The AI TOOLKIT is the TypeScript toolkit designed to help developers build AI-powered applications with React, Next.js, Vue, Svelte, Node.js, and more. Integrating LLMs into applications is complicated and heavily dependent on the specific model provider you use.
The AI TOOLKIT abstracts away the differences between model providers, eliminates boilerplate code for building chatbots, and allows you to go beyond text output to generate rich, interactive components.
At the center of the AI TOOLKIT is AI TOOLKIT Core, which provides a unified API to call any LLM. The code snippet below is all you need to call Claude 3.7 Sonnet with the AI TOOLKIT:
import { anthropic } from '@ai-toolkit/anthropic';
import { generateText } from 'ai-toolkit';
const { text, reasoningText, reasoning } = await generateText({
model: anthropic('claude-3-7-sonnet-20250219'),
prompt: 'How many people will live in the world in 2040?',
});
console.log(text); // text response
The unified interface also means that you can easily switch between providers by changing just two lines of code. For example, to use Claude 3.7 Sonnet via Amazon Bedrock:
import { bedrock } from '@ai-toolkit/amazon-bedrock';
import { generateText } from 'ai-toolkit';
const { reasoning, text } = await generateText({
model: bedrock('anthropic.claude-3-7-sonnet-20250219-v1:0'),
prompt: 'How many people will live in the world in 2040?',
});
### Reasoning Ability
Claude 3.7 Sonnet introduces a new extended thinking—the ability to solve complex problems with careful, step-by-step reasoning. You can enable it using the thinking provider option and specifying a thinking budget in tokens:
import { anthropic, AnthropicProviderOptions } from '@ai-toolkit/anthropic';
import { generateText } from 'ai-toolkit';
const { text, reasoningText, reasoning } = await generateText({
model: anthropic('claude-3-7-sonnet-20250219'),
prompt: 'How many people will live in the world in 2040?',
providerOptions: {
anthropic: {
thinking: { type: 'enabled', budgetTokens: 12000 },
} satisfies AnthropicProviderOptions,
},
});
console.log(reasoningText); // reasoning text
console.log(reasoning); // reasoning details including redacted reasoning
console.log(text); // text response
### Building Interactive Interfaces
AI TOOLKIT Core can be paired with AI TOOLKIT UI, another powerful component of the AI TOOLKIT, to streamline the process of building chat, completion, and assistant interfaces with popular frameworks like Next.js, Nuxt, and SvelteKit.
AI TOOLKIT UI provides robust abstractions that simplify the complex tasks of managing chat streams and UI updates on the frontend, enabling you to develop dynamic AI-driven interfaces more efficiently.
With four main hooks — `useChat`, `useCompletion`, and `useObject` — you can incorporate real-time chat capabilities, text completions, streamed JSON, and interactive assistant features into your app.
Let's explore building a chatbot with Next.js, the AI TOOLKIT, and Claude 3.7 Sonnet:
In a new Next.js application, first install the AI TOOLKIT and the Anthropic provider:
<Snippet text="pnpm install ai @ai-toolkit/anthropic" />
Then, create a route handler for the chat endpoint:
import { anthropic, AnthropicProviderOptions } from '@ai-toolkit/anthropic';
import { streamText, convertToModelMessages, type UIMessage } from 'ai-toolkit';
export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: anthropic('claude-3-7-sonnet-20250219'),
messages: await convertToModelMessages(messages),
providerOptions: {
anthropic: {
thinking: { type: 'enabled', budgetTokens: 12000 },
} satisfies AnthropicProviderOptions,
},
});
return result.toUIMessageStreamResponse({
sendReasoning: true,
});
}
<Note>
You can forward the model's reasoning tokens to the client with
sendReasoning: true in the toUIMessageStreamResponse method.
</Note>
Finally, update the root page (app/page.tsx) to use the useChat hook:
'use client';
import { useChat } from '@ai-toolkit/react';
import { DefaultChatTransport } from 'ai-toolkit';
import { useState } from 'react';
export default function Page() {
const [input, setInput] = useState('');
const { messages, sendMessage } = useChat({
transport: new DefaultChatTransport({ api: '/api/chat' }),
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (input.trim()) {
sendMessage({ text: input });
setInput('');
}
};
return (
<>
{messages.map(message => (
<div key={message.id}>
{message.role === 'user' ? 'User: ' : 'AI: '}
{message.parts.map((part, index) => {
// text parts:
if (part.type === 'text') {
return <div key={index}>{part.text}</div>;
}
// reasoning parts:
if (part.type === 'reasoning') {
return <pre key={index}>{part.text}</pre>;
}
})}
</div>
))}
<form onSubmit={handleSubmit}>
<input
name="prompt"
value={input}
onChange={e => setInput(e.target.value)}
/>
<button type="submit">Send</button>
</form>
</>
);
}
<Note>
You can access the model's reasoning tokens with the reasoning part on the
message parts.
</Note>
The useChat hook on your root page (app/page.tsx) will make a request to your LLM provider endpoint (app/api/chat/route.ts) whenever the user submits a message. The messages are then displayed in the chat UI.
- 1import { anthropic } from '@ai-toolkit/anthropic';
- 2import { generateText } from 'ai-toolkit';
- 3const { text, reasoningText, reasoning } = await generateText({
- 4 model: anthropic('claude-3-7-sonnet-20250219'),
- 5 prompt: 'How many people will live in the world in 2040?',
- 6});
- 7console.log(text); // text response
- 1import { bedrock } from '@ai-toolkit/amazon-bedrock';
- 2import { generateText } from 'ai-toolkit';
- 3const { reasoning, text } = await generateText({
- 4 model: bedrock('anthropic.claude-3-7-sonnet-20250219-v1:0'),
- 5 prompt: 'How many people will live in the world in 2040?',
- 6});
- 1import { anthropic, AnthropicProviderOptions } from '@ai-toolkit/anthropic';
- 2import { generateText } from 'ai-toolkit';
- 3const { text, reasoningText, reasoning } = await generateText({
- 4 model: anthropic('claude-3-7-sonnet-20250219'),
- 5 prompt: 'How many people will live in the world in 2040?',
- 6 providerOptions: {
- 7 anthropic: {
- 8 thinking: { type: 'enabled', budgetTokens: 12000 },
- 9 } satisfies AnthropicProviderOptions,
- 10 },
- 11});
- 12console.log(reasoningText); // reasoning text
- 13console.log(reasoning); // reasoning details including redacted reasoning
- 14console.log(text); // text response
- 1import { anthropic, AnthropicProviderOptions } from '@ai-toolkit/anthropic';
- 2import { streamText, convertToModelMessages, type UIMessage } from 'ai-toolkit';
- 3export async function POST(req: Request) {
- 4 const { messages }: { messages: UIMessage[] } = await req.json();
- 5 const result = streamText({
- 6 model: anthropic('claude-3-7-sonnet-20250219'),
- 7 messages: await convertToModelMessages(messages),
- 8 providerOptions: {
- 9 anthropic: {
- 10 thinking: { type: 'enabled', budgetTokens: 12000 },
- 11 } satisfies AnthropicProviderOptions,
- 12 },
- 13 });
- 14 return result.toUIMessageStreamResponse({
- 15 sendReasoning: true,
- 16 });
- 17}
- 1'use client';
- 2import { useChat } from '@ai-toolkit/react';
- 3import { DefaultChatTransport } from 'ai-toolkit';
- 4import { useState } from 'react';
- 5export default function Page() {
- 6 const [input, setInput] = useState('');
- 7 const { messages, sendMessage } = useChat({
- 8 transport: new DefaultChatTransport({ api: '/api/chat' }),
- 9 });
- 10 const handleSubmit = (e: React.FormEvent) => {
- 11 e.preventDefault();
- 12 if (input.trim()) {
- 13 sendMessage({ text: input });
- 14 setInput('');
- 15 }
- 16 };
- 17 return (
- 18 <>
- 19 {messages.map(message => (
- 20 <div key={message.id}>
- 21 {message.role === 'user' ? 'User: ' : 'AI: '}
- 22 {message.parts.map((part, index) => {
- 23 // text parts:
- 24 if (part.type === 'text') {
- 25 return <div key={index}>{part.text}</div>;
- 26 }
- 27 // reasoning parts:
- 28 if (part.type === 'reasoning') {
- 29 return <pre key={index}>{part.text}</pre>;
- 30 }
- 31 })}
- 32 </div>
- 33 ))}
- 34 <form onSubmit={handleSubmit}>
- 35 <input
- 36 name="prompt"
- 37 value={input}
- 38 onChange={e => setInput(e.target.value)}
- 39 />
- 40 <button type="submit">Send</button>
- 41 </form>
- 42 </>
- 43 );
- 44}
Get Started
Ready to dive in? Here's how you can begin:
1. Explore the documentation at studio.khulnasoft.com/docs to understand the capabilities of the AI TOOLKIT.
2. Check out practical examples at studio.khulnasoft.com/examples to see the SDK in action.
3. Dive deeper with advanced guides on topics like Retrieval-Augmented Generation (RAG) at studio.khulnasoft.com/docs/guides.
4. Use ready-to-deploy AI templates at vercel.com/templates?type=ai.
Claude 3.7 Sonnet opens new opportunities for reasoning-intensive AI applications. Start building today and leverage the power of advanced reasoning in your AI projects.