Loading...
    • Developer Guide
    • API Reference
    • MCP
    • Resources
    • Release Notes
    Search...
    ⌘K

    Using the API

    OverviewClient SDKsBeta headersErrors
    Messages
    Create a Message
    Count tokens in a Message
    Batches
    Create a Message Batch
    Retrieve a Message Batch
    List Message Batches
    Cancel a Message Batch
    Delete a Message Batch
    Retrieve Message Batch results
    Models
    List Models
    Get a Model
    Beta
    Models
    List Models
    Get a Model
    Messages
    Create a Message
    Count tokens in a Message
    Batches
    Create a Message Batch
    Retrieve a Message Batch
    List Message Batches
    Cancel a Message Batch
    Delete a Message Batch
    Retrieve Message Batch results
    Files
    Upload File
    List Files
    Download File
    Get File Metadata
    Delete File
    Skills
    Create Skill
    List Skills
    Get Skill
    Delete Skill
    Versions
    Create Skill Version
    List Skill Versions
    Get Skill Version
    Delete Skill Version
    Admin
    Organization
    Get Organization Me
    Invites
    Create Invite
    List Invites
    Get Invite
    Delete Invite
    Users
    Get User
    Update User
    Remove User
    List Users
    Workspaces
    Get Workspace
    List Workspaces
    Create Workspace
    Update Workspace
    Archive Workspace
    Members
    Get Workspace Member
    Create Workspace Member
    Delete Workspace Member
    List Workspace Members
    Update Workspace Member
    API Keys
    Get Api Key
    Update Api Key
    List Api Keys
    Usage And Cost
    Usage Report
    Get Messages Usage Report
    Get Claude Code Usage Report
    Cost Report
    Get Cost Report
    Completions
    Create a Text Completion

    Support & configuration

    Rate limitsService tiersVersionsIP addressesSupported regionsOpenAI SDK compatibility
    Console
    Documentation

    OpenAI SDK compatibility

    Anthropic provides a compatibility layer that enables you to use the OpenAI SDK to test the Claude API. With a few code changes, you can quickly evaluate Anthropic model capabilities.

    This compatibility layer is primarily intended to test and compare model capabilities, and is not considered a long-term or production-ready solution for most use cases. While we do intend to keep it fully functional and not make breaking changes, our priority is the reliability and effectiveness of the Claude API.

    For more information on known compatibility limitations, see Important OpenAI compatibility limitations.

    If you encounter any issues with the OpenAI SDK compatibility feature, please let us know here.

    For the best experience and access to Claude API full feature set (PDF processing, citations, extended thinking, and prompt caching), we recommend using the native Claude API.

    Getting started with the OpenAI SDK

    To use the OpenAI SDK compatibility feature, you'll need to:

    1. Use an official OpenAI SDK
    2. Change the following
      • Update your base URL to point to the Claude API
      • Replace your API key with an Claude API key
      • Update your model name to use a Claude model
    3. Review the documentation below for what features are supported

    Quick start example

    Python
    from openai import OpenAI
    
    client = OpenAI(
        api_key="ANTHROPIC_API_KEY",  # Your Claude API key
        base_url="https://api.anthropic.com/v1/"  # the Claude API endpoint
    )
    
    response = client.chat.completions.create(
        model="claude-sonnet-4-5", # Anthropic model name
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Who are you?"}
        ],
    )
    
    print(response.choices[0].message.content)
    TypeScript
    import OpenAI from 'openai';
    
    const openai = new OpenAI({
        apiKey: "ANTHROPIC_API_KEY",   // Your Claude API key
        baseURL: "https://api.anthropic.com/v1/",  // Claude API endpoint
    });
    
    const response = await openai.chat.completions.create({
        messages: [
            { role: "user", content: "Who are you?" }
        ],
        model: "claude-sonnet-4-5", // Claude model name
    });
    
    console.log(response.choices[0].message.content);

    Important OpenAI compatibility limitations

    API behavior

    Here are the most substantial differences from using OpenAI:

    • The strict parameter for function calling is ignored, which means the tool use JSON is not guaranteed to follow the supplied schema.
    • Audio input is not supported; it will simply be ignored and stripped from input
    • Prompt caching is not supported, but it is supported in the Anthropic SDK
    • System/developer messages are hoisted and concatenated to the beginning of the conversation, as Anthropic only supports a single initial system message.

    Most unsupported fields are silently ignored rather than producing errors. These are all documented below.

    Output quality considerations

    If you’ve done lots of tweaking to your prompt, it’s likely to be well-tuned to OpenAI specifically. Consider using our prompt improver in the Claude Console as a good starting point.

    System / Developer message hoisting

    Most of the inputs to the OpenAI SDK clearly map directly to Anthropic’s API parameters, but one distinct difference is the handling of system / developer prompts. These two prompts can be put throughout a chat conversation via OpenAI. Since Anthropic only supports an initial system message, we take all system/developer messages and concatenate them together with a single newline (\n) in between them. This full string is then supplied as a single system message at the start of the messages.

    Extended thinking support

    You can enable extended thinking capabilities by adding the thinking parameter. While this will improve Claude's reasoning for complex tasks, the OpenAI SDK won't return Claude's detailed thought process. For full extended thinking features, including access to Claude's step-by-step reasoning output, use the native Claude API.

    response = client.chat.completions.create(
        model="claude-sonnet-4-5",
        messages=...,
        extra_body={
            "thinking": { "type": "enabled", "budget_tokens": 2000 }
        }
    )

    Rate limits

    Rate limits follow Anthropic's standard limits for the /v1/messages endpoint.

    Detailed OpenAI Compatible API Support

    Request fields

    Simple fields

    FieldSupport status
    modelUse Claude model names
    max_tokensFully supported
    max_completion_tokensFully supported
    streamFully supported
    stream_optionsFully supported
    top_pFully supported
    parallel_tool_callsFully supported
    stopAll non-whitespace stop sequences work
    temperatureBetween 0 and 1 (inclusive). Values greater than 1 are capped at 1.
    nMust be exactly 1
    logprobsIgnored
    metadataIgnored
    response_formatIgnored
    predictionIgnored
    presence_penaltyIgnored
    frequency_penaltyIgnored
    seedIgnored
    service_tierIgnored
    audioIgnored
    logit_biasIgnored
    storeIgnored
    userIgnored
    modalitiesIgnored
    top_logprobsIgnored
    reasoning_effortIgnored

    tools / functions fields

    messages array fields

    Response fields

    FieldSupport status
    idFully supported
    choices[]Will always have a length of 1
    choices[].finish_reasonFully supported
    choices[].indexFully supported
    choices[].message.roleFully supported
    choices[].message.contentFully supported
    choices[].message.tool_callsFully supported
    objectFully supported
    createdFully supported
    modelFully supported
    finish_reasonFully supported
    contentFully supported
    usage.completion_tokensFully supported
    usage.prompt_tokensFully supported
    usage.total_tokensFully supported
    usage.completion_tokens_detailsAlways empty
    usage.prompt_tokens_detailsAlways empty
    choices[].message.refusalAlways empty
    choices[].message.audioAlways empty
    logprobsAlways empty
    service_tierAlways empty
    system_fingerprintAlways empty

    Error message compatibility

    The compatibility layer maintains consistent error formats with the OpenAI API. However, the detailed error messages will not be equivalent. We recommend only using the error messages for logging and debugging.

    Header compatibility

    While the OpenAI SDK automatically manages headers, here is the complete list of headers supported by the Claude API for developers who need to work with them directly.

    HeaderSupport Status
    x-ratelimit-limit-requestsFully supported
    x-ratelimit-limit-tokensFully supported
    x-ratelimit-remaining-requestsFully supported
    x-ratelimit-remaining-tokensFully supported
    x-ratelimit-reset-requestsFully supported
    x-ratelimit-reset-tokensFully supported
    retry-afterFully supported
    request-idFully supported
    openai-versionAlways 2020-10-01
    authorizationFully supported
    openai-processing-msAlways empty
    • Getting started with the OpenAI SDK
    • Quick start example
    • Important OpenAI compatibility limitations
    • Rate limits
    • Detailed OpenAI Compatible API Support
    • Request fields
    • Response fields
    • Error message compatibility
    • Header compatibility
    © 2025 ANTHROPIC PBC

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    © 2025 ANTHROPIC PBC