Claude API Documentation

website·Indexed Jun 18, 2026

https://platform.claude.com/docs/

Technical documentation for the Claude API, including administrative endpoints for usage and cost reporting, beta features for memory stores, skills, and file management, as well as message batching and CLI environments.

Tokens
163.5K
Snippets
389
Records
621
Agent score
50%

What's inside Claude API

  1. Overview of SRE MCP Server tools

    The sre_mcp_server.py acts as a tool server that the Claude Agent SDK communicates with via JSON-RPC over stdin/stdout. It provides 12 tools categorized into four functional areas:

    CategoryToolsPurpose
    Prometheusquery_metrics, list_metrics, get_service_healthQuery metrics, discover data, and get health summaries
    Infrastructureread_config_file, edit_config_file, run_shell_command, get_container_logsRead/write configs, run Docker commands, and inspect logs
    Diagnosticsget_logs, get_alerts, get_recent_deployments, execute_runbookAccess application logs, alerts, deployments, and playbooks
    Documentationwrite_postmortemWrite incident post-mortems to disk

    Note: The server also supports extensions for PagerDuty and Confluence if the corresponding API keys are provided in the environment.

  2. Overview of Claude Memory and Context Editing capabilities

    Claude 4 models support advanced context management to prevent information loss and manage token limits in long-running agent sessions.

    1. Memory Tool (memory_20250818)

    Enables cross-conversation learning by allowing Claude to write information to a file-based system (typically under a /memories directory). This allows the agent to remember patterns and preferences across different sessions.

    Supported Models:

    • Claude Opus 4.1 (claude-opus-4-1)
    • Claude Opus 4 (claude-opus-4)
    • Claude Sonnet 4.6 (claude-sonnet-4-6)
    • Claude Sonnet 4 (claude-sonnet-4)
    • Claude Haiku 4.5 (claude-haiku-4-5)

    2. Context Editing

    Automatically manages the context window using two primary strategies:

    • Tool use clearing (clear_tool_uses_20250919): Removes old tool results from the context when it becomes too large.
    • Thinking management (clear_thinking_20251015): Manages extended thinking blocks (requires thinking to be enabled).

    These tools help mitigate context limits, reduce computational costs, and prevent information loss during extended interactions.

  3. Overview of Claude Skills architecture

    Claude Skills are high-level packages containing instructions, executable code, and resources. They use a Progressive Disclosure architecture to optimize token usage:

    1. Metadata: Claude initially only sees the skill name and description (from the SKILL.md YAML frontmatter).
    2. Full Instructions: Loaded only when the skill is deemed relevant to the prompt.
    3. Linked Files: Additional resources and helper scripts are loaded only if needed.

    Skill Types

    • Anthropic-Managed: Pre-built skills like xlsx, pptx, pdf, and docx.
    • Custom: User-defined skills for specific business workflows (e.g., brand guidelines or financial models).
  4. Overview of RAG implementation workflow with Claude

    A complete RAG (Retrieval Augmented Generation) implementation involves several stages to move from a basic pipeline to an optimized production system:

    1. Basic RAG: Setting up an in-memory vector database and using embeddings (e.g., from Voyage AI) to retrieve context.
    2. Evaluation Suite: Building a robust system to measure retrieval pipeline performance (Avg Precision, Recall, MRR) and end-to-end accuracy independently of 'vibes'-based testing.
    3. Advanced Optimization: Implementing techniques like summary indexing and re-ranking with Claude to improve retrieval quality.

    Note on Rate Limits: Running full end-to-end evaluations can be token-intensive and may trigger rate limits unless using Anthropic API Tier 2 or above.

  5. Core components of an LLM evaluation (Eval)

    An evaluation (eval) system for LLMs typically consists of four distinct parts:

    1. Input Prompt: The prompt fed to the model. This often uses a template where variable inputs are injected at test time.
    2. Output: The completion generated by the model in response to the input prompt.
    3. Golden Answer: The ground truth or reference. This can be an exact match requirement or a descriptive example of a perfect answer used to guide a grader.
    4. Score: A metric generated by a grading method representing the model's performance on the specific question.
  6. Compare Programmatic Tool Calling (PTC) vs Traditional Tool Calling

    When choosing between Programmatic Tool Calling (PTC) and traditional tool calling, consider the following trade-offs:

    • API Call Count: PTC may require more API calls because it tends to write structured, sequential code (e.g., separating a data-fetching step from a data-processing step) rather than attempting to batch multiple operations into a single turn.
    • Token Efficiency: PTC is generally more token-efficient. Traditional tool calling often requires sending large amounts of raw data through the model's context window to perform operations. PTC avoids this by executing logic in a code environment and only returning the necessary results to the model.
    • Best Practice: Use PTC when working with large, metadata-rich datasets where minimizing context window usage is more critical than minimizing the number of round trips.
  7. Understand Session Memory Compaction Strategies

    When managing long-running conversations that exceed Claude's context limits, you can use session memory compaction to reduce token usage. There are two primary strategies:

    1. Traditional Compaction (Reactive): Compaction is triggered only when the context window limit is reached (e.g., during a user message). This causes a significant delay (latency) because the agent must generate the summary before responding to the user.
    2. Instant Compaction (Proactive): Session memory is proactively generated once a 'soft' token threshold is reached, before the hard limit is hit. This ensures the summary is already available when the limit is reached, providing an 'instant' experience with no user waiting time.

    Compaction works by condensing the conversation into a structured summary containing:

    • User Intent: The core goal of the conversation.
    • Completed Work: Summaries of approved ideas, drafted content, or finished tasks.
    • Errors & Corrections: Explicitly noted rejections or changes in direction.
    • Active Work: The current state of the task.
    • Pending Tasks: What needs to be done next.
    • Key References: Critical facts, addresses, or data points required for continuity.
  8. Select a hosting tier for Claude Agent SDK

    Choose a hosting strategy based on your scale and operational requirements:

    • Tier 1: Docker (Single machine/container)

      • Best for: Development loops, internal tools, single-tenant apps, or cron/batch jobs.
      • Mechanism: Uses Docker Compose for restarts and bind mounts for /data persistence.
      • Upgrade when: You need a public URL or automated high availability.
    • Tier 2: Modal (Serverless/Managed)

      • Best for: Bursty traffic, scale-to-zero requirements, or when you want a public HTTPS endpoint without managing infrastructure.
      • Mechanism: Runs the Docker image behind a public URL with remote builds.
      • Upgrade when: You require multi-tenant isolation or strict network egress control.
    • Tier 3: Kubernetes (Orchestrated Cluster)

      • Best for: Multi-tenant production, regulated environments, or existing K8s workflows.
      • Mechanism: Provides pod-per-session isolation, authenticating gateways, and tenant-scoped sessions.
      • Upgrade when: You need to tune autoscaling, multi-region routing, or durable session stores.
  9. Context Engineering Strategies for AI Agents

    When building long-horizon agents, context management is critical to prevent 'context rot' (decreased recall accuracy as token count increases) and hitting hard token limits. There are three primary strategies for managing context:

    1. Compaction: Distills the contents of a context window into a high-fidelity summary. This allows the agent to continue long conversations with minimal performance degradation. Anthropic provides server-side compaction for this.
    2. Tool-result clearing: Addresses bloat caused by large tool outputs (e.g., file reads or API responses). It drops old, re-fetchable results while maintaining a record that the tool call occurred. This is implemented via context editing.
    3. Memory: Structured note-taking where the agent writes to persistent external storage. This allows the agent to track progress across tasks and sessions without keeping everything in the active context window. Anthropic provides a memory tool for this.
  10. Implement the Orchestrator-Workers design pattern with Claude

    The Orchestrator-Workers pattern is used for complex tasks where subtasks cannot be predicted in advance. An orchestrator LLM analyzes a task, determines the most valuable subtasks/perspectives, and generates structured XML instructions. Specialized worker LLMs then execute these specific subtasks.

    When to use:

    • Tasks require multiple distinct approaches or perspectives.
    • Optimal subtasks depend on the specific input.
    • You need to compare different strategies or styles.

    When NOT to use:

    • Simple, single-output tasks.
    • Latency-critical applications (multiple LLM calls add overhead).
    • Predictable subtasks (use standard parallelization instead).

    Prerequisites:

    • Python 3.9+
    • anthropic library installed.
    • ANTHROPIC_API_KEY set as an environment variable.
  11. Strategy for Knowledge Graph construction with Claude

    A robust knowledge graph pipeline using Claude involves three main stages:

    1. Extraction: Use a high-volume, cost-effective model (like Claude Haiku) to extract typed entities and subject-predicate-object triples from unstructured text using structured outputs.
    2. Entity Resolution: Use a more capable model (like Claude Sonnet) to cluster surface-form variants (e.g., "Neil Armstrong" and "Neil Alden Armstrong") into canonical nodes. This stage uses the entity descriptions generated during extraction to disambiguate entities with similar names.
    3. Graph Assembly: Assemble the resolved entities and relations into a graph structure (e.g., using networkx) to enable multi-hop reasoning and complex relational queries.
  12. Understand Claude API citation response structure

    When using Claude's citation support, the API returns a content array where specific text blocks contain a citations field. Each citation object provides metadata about the source material used to generate that specific text segment.

    Key fields in a citation object include:

    • type: The type of citation (e.g., page_location).
    • cited_text: The exact verbatim text from the source document.
    • document_title: The name of the source document.
    • start_page_number: The starting page of the reference.
    • end_page_number: The ending page of the reference.

    { "content": [ { "type": "text", "text": "Example text from Claude.", "citations": [ { "type": "page_location", "cited_text": "Verbatim text from source.", "document_title": "Source Document Name", "start_page_number": 1, "end_page_number": 2 } ] } ] }