| name | clade-model-inference |
| description | Stream Claude responses, use system prompts, handle multi-turn conversations,
Use when working with model-inference patterns.
and process structured output with the Messages API.
Trigger with "anthropic streaming", "claude messages api", "claude inference",
"stream claude response".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Grep |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","anthropic","claude","streaming","messages-api"] |
| compatibility | Designed for Claude Code |
Anthropic Messages API — Streaming & Advanced Patterns
Overview
The Messages API is the only inference endpoint. Every Claude interaction goes through client.messages.create(). This skill covers streaming, system prompts, vision, and structured output.
Prerequisites
- Completed
clade-install-auth
- Familiarity with
clade-hello-world
Instructions
Step 1: Streaming Responses
import Anthropic from '@claude-ai/sdk';
const client = new Anthropic();
const stream = client.messages.stream({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Write a haiku about TypeScript.' }],
});
for await (const event of stream) {
if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
process.stdout.write(event.delta.text);
}
}
const finalMessage = await stream.finalMessage();
console.log('\n\nTokens:', finalMessage.usage);