CC-301l · Module 2
API Fundamentals
4 min read
The Claude API is the foundation beneath Claude Code. When you interact with Claude Code, it makes API calls on your behalf — sending messages, receiving responses, invoking tools. Using the API directly gives you full control over these interactions: system prompts, message history, model selection, temperature, max tokens, and tool definitions. This control enables use cases that Claude Code does not support natively.
The API uses a messages-based interface. You send a list of messages (alternating user and assistant roles) and receive a response. The system prompt — equivalent to CLAUDE.md — sets the persistent context. The messages list is the conversation history. The response includes the model's reply and metadata (token usage, stop reason, model ID). Understanding this structure is essential for building custom integrations.
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
const response = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: 'You are a code review assistant. Be concise and specific.',
messages: [
{
role: 'user',
content: 'Review this function for bugs:\n```ts\n' + code + '\n```',
},
],
});
console.log(response.content[0].text);