clade-model-inference

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".

1,868 stars

Best use case

clade-model-inference is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

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".

Teams using clade-model-inference should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/clade-model-inference/SKILL.md --create-dirs "https://raw.githubusercontent.com/jeremylongshore/claude-code-plugins-plus-skills/main/plugins/saas-packs/claude-pack/skills/clade-model-inference/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/clade-model-inference/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How clade-model-inference Compares

Feature / Agentclade-model-inferenceStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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".

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# 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
```typescript
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);
```

### Step 2: Vision — Sending Images
```typescript
const message = await client.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  messages: [{
    role: 'user',
    content: [
      {
        type: 'image',
        source: {
          type: 'base64',
          media_type: 'image/png',
          data: fs.readFileSync('screenshot.png').toString('base64'),
        },
      },
      { type: 'text', text: 'Describe what you see in this image.' },
    ],
  }],
});
```

### Step 3: JSON / Structured Output
```typescript
const message = await client.messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  system: `Respond with valid JSON only. Schema: { "summary": string, "sentiment": "positive"|"negative"|"neutral", "confidence": number }`,
  messages: [{ role: 'user', content: 'Analyze: "This product exceeded my expectations!"' }],
});

const result = JSON.parse(message.content[0].text);
// { summary: "Very positive review", sentiment: "positive", confidence: 0.95 }
```

## Python Streaming
```python
import anthropic

client = anthropic.Anthropic()

with client.messages.stream(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a haiku about Python."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

print(f"\nTokens: {stream.get_final_message().usage}")
```

## Output
- **Non-streaming:** Full `Message` object with `content`, `usage`, `stop_reason`
- **Streaming events:**
  - `message_start` — message metadata
  - `content_block_start` — new content block beginning
  - `content_block_delta` — incremental text (`text_delta`) or tool input (`input_json_delta`)
  - `message_delta` — final `stop_reason` and usage
  - `message_stop` — stream complete

## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| `overloaded_error` (529) | Anthropic API temporarily overloaded | Retry with exponential backoff; use `client.messages.create` with built-in retries |
| `rate_limit_error` (429) | Exceeded RPM or TPM | Check `retry-after` header. See `clade-rate-limits` |
| `invalid_request_error` | Image too large or bad format | Max 20 images per request. Supported: PNG, JPEG, GIF, WebP. Max 5MB each |

## Key Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `model` | string | Required. Model ID (e.g. `claude-sonnet-4-20250514`) |
| `max_tokens` | int | Required. Maximum output tokens (1–8192 typical) |
| `messages` | array | Required. Alternating user/assistant messages |
| `system` | string | Optional. System prompt for behavior/persona |
| `temperature` | float | Optional. 0.0–1.0, default 1.0 |
| `top_p` | float | Optional. Nucleus sampling threshold |
| `stop_sequences` | string[] | Optional. Custom stop strings |
| `stream` | boolean | Optional. Enable SSE streaming |

## Examples
See Step 1 (streaming), Step 2 (vision with base64 images), and Step 3 (structured JSON output) above. Python streaming example included.

## Resources
- [Messages API](https://docs.anthropic.com/en/api/messages)
- [Streaming](https://docs.anthropic.com/en/api/messages-streaming)
- [Vision](https://docs.anthropic.com/en/docs/build-with-claude/vision)

## Next Steps
See `clade-embeddings-search` for tool use and function calling patterns.

Related Skills

openrouter-model-routing

1868
from jeremylongshore/claude-code-plugins-plus-skills

Implement intelligent model routing to optimize cost, quality, and latency on OpenRouter. Use when building multi-model systems or optimizing spend across task types. Triggers: 'openrouter routing', 'model routing', 'route to model', 'model selection openrouter'.

openrouter-model-catalog

1868
from jeremylongshore/claude-code-plugins-plus-skills

Query, filter, and select from OpenRouter's 400+ model catalog. Use when choosing models, comparing pricing, or checking capabilities. Triggers: 'openrouter models', 'list models', 'model catalog', 'compare models', 'available models'.

openrouter-model-availability

1868
from jeremylongshore/claude-code-plugins-plus-skills

Monitor OpenRouter model availability and implement health checks. Use when building systems that depend on specific models being online. Triggers: 'openrouter model status', 'is model available', 'openrouter health check', 'model availability'.

klingai-model-catalog

1868
from jeremylongshore/claude-code-plugins-plus-skills

Explore Kling AI models, versions, and capabilities for video and image generation. Use when selecting models or comparing features. Trigger with phrases like 'kling ai models', 'klingai capabilities', 'kling video models', 'klingai features'.

cursor-model-selection

1868
from jeremylongshore/claude-code-plugins-plus-skills

Configure and select AI models in Cursor for Chat, Composer, and Agent mode. Triggers on "cursor model", "cursor gpt", "cursor claude", "change cursor model", "cursor ai model", "cursor auto mode".

clade-webhooks-events

1868
from jeremylongshore/claude-code-plugins-plus-skills

Use Anthropic Message Batches for async bulk processing and event handling. Use when working with webhooks-events patterns. Trigger with "anthropic batches", "claude batch api", "anthropic async", "bulk claude processing", "anthropic webhook".

clade-upgrade-migration

1868
from jeremylongshore/claude-code-plugins-plus-skills

Upgrade Anthropic SDK versions and migrate between Claude model generations. Use when working with upgrade-migration patterns. Trigger with "upgrade anthropic sdk", "migrate claude model", "anthropic breaking changes", "new claude model".

clade-security-basics

1868
from jeremylongshore/claude-code-plugins-plus-skills

Secure your Anthropic integration — API key management, input validation, Use when working with security-basics patterns. prompt injection defense, and data privacy. Trigger with "anthropic security", "claude api key security", "anthropic prompt injection", "secure claude integration".

clade-sdk-patterns

1868
from jeremylongshore/claude-code-plugins-plus-skills

Production-ready Anthropic SDK patterns — client config, retries, timeouts, Use when working with sdk-patterns patterns. error handling, TypeScript types, and async patterns. Trigger with "anthropic sdk", "claude client setup", "anthropic typescript", "anthropic python patterns".

clade-reliability-patterns

1868
from jeremylongshore/claude-code-plugins-plus-skills

Build fault-tolerant Claude integrations — retries, circuit breakers, Use when working with reliability-patterns patterns. fallbacks, timeouts, and graceful degradation. Trigger with "anthropic reliability", "claude fault tolerance", "anthropic circuit breaker", "claude fallback".

clade-reference-architecture

1868
from jeremylongshore/claude-code-plugins-plus-skills

Build Claude Code plugins — skills, agents, MCP servers, hooks, and slash commands. Use when working with reference-architecture patterns. The complete guide to extending Claude Code with the Anthropic plugin system. Trigger with "claude code plugin", "build a skill", "create mcp server", "anthropic plugin architecture", "claude code hooks".

clade-rate-limits

1868
from jeremylongshore/claude-code-plugins-plus-skills

Handle Anthropic rate limits — understand tiers, implement backoff, Use when working with rate-limits patterns. optimize throughput, and monitor usage. Trigger with "anthropic rate limit", "claude 429", "anthropic throttling", "anthropic usage limits", "claude tokens per minute".