Skip to content
OpenSmartRoute
Skillv1.0.0

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

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (plugins/saas-packs/claude-pack/skills/clade-model-inference/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill clade-model-inference. Copyright stays with the author (MIT).

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);

Step 2: Vision — Sending Images

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

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

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

Next Steps

See clade-embeddings-search for tool use and function calling patterns.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-clade-model-i-a3a07c/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-clade-model-i-a3a07c.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-clade-model-i-a3a07c",
  "kind": "skill",
  "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\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "saas",
      "anthropic",
      "claude",
      "streaming",
      "messages-api",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "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\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "plugins/saas-packs/claude-pack/skills/clade-model-inference/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/plugins/saas-packs/claude-pack/skills/clade-model-inference/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/plugins/saas-packs/claude-pack/skills/clade-model-inference/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit,",
      "Bash(npm:*),",
      "Grep"
    ],
    "license": "MIT"
  },
  "instructions": "# Anthropic Messages API — Streaming & Advanced Patterns\n\n## Overview\n\nThe 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.\n\n## Prerequisites\n\n- Completed `clade-install-auth`\n- Familiarity with `clade-hello-world`\n\n## Instructions\n\n### Step 1: Streaming Responses\n\n```typescript\nimport Anthropic from '@claude-ai/sdk';\n\nconst client = new Anthropic();\n\nconst stream = client.messages.stream({\n  model: 'claude-sonnet-4-20250514',\n  max_tokens: 1024,\n  messages:",
  "cost": {
    "context_tokens": 1076
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-clade-model-i-a3a07c/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.