claude-api

Anthropic Claude API integration for building AI-powered applications. Use when working with Anthropic's Messages API, Claude SDKs (Python or TypeScript), tool use/function calling, vision/image inputs, streaming responses, prompt caching, message batches, token counting, extended thinking, PDF processing, or any Claude API integration task.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "claude-api" with this command: npx skills add diskd-ai/claude-api/diskd-ai-claude-api-claude-api

Claude API

Build applications with Anthropic's Claude API using official Python and TypeScript SDKs.

Base URL: https://api.anthropic.com

Authentication

All requests require these headers (SDKs handle automatically):

HeaderValue
x-api-keyAPI key from Console
anthropic-version2023-06-01
content-typeapplication/json

Quick Start

Python

from anthropic import Anthropic

client = Anthropic()  # Uses ANTHROPIC_API_KEY env var

message = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello, Claude"}]
)
print(message.content[0].text)

TypeScript

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();  // Uses ANTHROPIC_API_KEY env var

const message = await client.messages.create({
  model: "claude-sonnet-4-5-20250929",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello, Claude" }],
});
console.log(message.content[0].text);

Available Models

ModelModel IDBest ForPricing
Claude Sonnet 4.5claude-sonnet-4-5-20250929Complex agents, coding (recommended)$3/$15 per MTok
Claude Haiku 4.5claude-haiku-4-5-20251001Fast, lightweight tasks$1/$5 per MTok
Claude Opus 4.5claude-opus-4-5-20251101Maximum intelligence$5/$25 per MTok

For complete model details, platform IDs (AWS Bedrock, GCP Vertex AI), and legacy models, see references/models.md.

Available APIs

APIEndpointPurpose
MessagesPOST /v1/messagesConversational interactions
Message BatchesPOST /v1/messages/batchesAsync bulk processing (50% cost reduction)
Token CountingPOST /v1/messages/count_tokensCount tokens before sending
ModelsGET /v1/modelsList available models
Files (beta)/v1/filesUpload/manage files across calls

For full API details, rate limits, and third-party platforms, see references/api-overview.md.

Core Capabilities

Messages API

Basic chat completions, multi-turn conversations, system prompts, streaming responses.

Tool Use

Define tools with JSON schemas, handle tool calls, return results to Claude.

Vision

Send images (base64 or URL), analyze multiple images, extract information.

Streaming

Real-time token streaming with event handlers or async iterators.

Token Counting

Count tokens before sending requests to manage costs and rate limits.

API & SDK References

Advanced Features

Common Patterns

Conversation Loop with Tools

messages = [{"role": "user", "content": user_input}]

while True:
    response = client.messages.create(
        model="claude-sonnet-4-5-20250929",
        max_tokens=1024,
        tools=tools,
        messages=messages
    )

    if response.stop_reason == "end_turn":
        break

    if response.stop_reason == "tool_use":
        messages.append({"role": "assistant", "content": response.content})
        tool_results = []
        for block in response.content:
            if block.type == "tool_use":
                result = execute_tool(block.name, block.input)
                tool_results.append({
                    "type": "tool_result",
                    "tool_use_id": block.id,
                    "content": result
                })
        messages.append({"role": "user", "content": tool_results})

Error Handling with Retries

from anthropic import RateLimitError
import time

def call_with_retry(fn, max_retries=3):
    for attempt in range(max_retries):
        try:
            return fn()
        except RateLimitError as e:
            if attempt == max_retries - 1:
                raise
            wait = int(e.response.headers.get("retry-after", 60))
            time.sleep(wait)

Required Parameters

Every messages.create() call requires:

ParameterDescription
modelModel ID (e.g., claude-sonnet-4-5-20250929)
max_tokensMaximum tokens in response
messagesArray of message objects with role and content

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

claude-api

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

redmine-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

code-review

No summary provided by upstream source.

Repository SourceNeeds Review