Loading...
    • Developer Guide
    • API Reference
    • MCP
    • Resources
    • Release Notes
    Search...
    ⌘K
    Using the API
    API overviewBeta headersErrors
    Messages
    Create a Message
    Count tokens in a Message
    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
    Admin
    Completions
    Create a Text Completion
    Support & configuration
    Rate limitsService tiersVersionsIP addressesSupported regionsOpenAI SDK compatibility
    Console
    Log in

    Batches

    Create a Message Batch
    client.Messages.Batches.New(ctx, body) (*MessageBatch, error)
    POST/v1/messages/batches
    Retrieve a Message Batch
    client.Messages.Batches.Get(ctx, messageBatchID) (*MessageBatch, error)
    GET/v1/messages/batches/{message_batch_id}
    List Message Batches
    client.Messages.Batches.List(ctx, query) (*Page[MessageBatch], error)
    GET/v1/messages/batches
    Cancel a Message Batch
    client.Messages.Batches.Cancel(ctx, messageBatchID) (*MessageBatch, error)
    POST/v1/messages/batches/{message_batch_id}/cancel
    Delete a Message Batch
    client.Messages.Batches.Delete(ctx, messageBatchID) (*DeletedMessageBatch, error)
    DELETE/v1/messages/batches/{message_batch_id}
    Retrieve Message Batch results
    client.Messages.Batches.Results(ctx, messageBatchID) (*MessageBatchIndividualResponse, error)
    GET/v1/messages/batches/{message_batch_id}/results
    ModelsExpand Collapse
    type DeletedMessageBatch struct{…}
    ID string

    ID of the Message Batch.

    Type MessageBatchDeleted

    Deleted object type.

    For Message Batches, this is always "message_batch_deleted".

    type MessageBatch struct{…}
    ID string

    Unique object identifier.

    The format and length of IDs may change over time.

    ArchivedAt Time

    RFC 3339 datetime string representing the time at which the Message Batch was archived and its results became unavailable.

    CancelInitiatedAt Time

    RFC 3339 datetime string representing the time at which cancellation was initiated for the Message Batch. Specified only if cancellation was initiated.

    CreatedAt Time

    RFC 3339 datetime string representing the time at which the Message Batch was created.

    EndedAt Time

    RFC 3339 datetime string representing the time at which processing for the Message Batch ended. Specified only once processing ends.

    Processing ends when every request in a Message Batch has either succeeded, errored, canceled, or expired.

    formatdate-time
    ExpiresAt Time

    RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation.

    ProcessingStatus MessageBatchProcessingStatus

    Processing status of the Message Batch.

    Accepts one of the following:
    const MessageBatchProcessingStatusInProgress MessageBatchProcessingStatus = "in_progress"
    const MessageBatchProcessingStatusCanceling MessageBatchProcessingStatus = "canceling"
    const MessageBatchProcessingStatusEnded MessageBatchProcessingStatus = "ended"
    RequestCounts MessageBatchRequestCounts

    Tallies requests within the Message Batch, categorized by their status.

    Requests start as processing and move to one of the other statuses only once processing of the entire batch ends. The sum of all values always matches the total number of requests in the batch.

    Canceled int64

    Number of requests in the Message Batch that have been canceled.

    This is zero until processing of the entire Message Batch has ended.

    Errored int64

    Number of requests in the Message Batch that encountered an error.

    This is zero until processing of the entire Message Batch has ended.

    Expired int64

    Number of requests in the Message Batch that have expired.

    This is zero until processing of the entire Message Batch has ended.

    Processing int64

    Number of requests in the Message Batch that are processing.

    Succeeded int64

    Number of requests in the Message Batch that have completed successfully.

    This is zero until processing of the entire Message Batch has ended.

    ResultsURL string

    URL to a .jsonl file containing the results of the Message Batch requests. Specified only once processing ends.

    Results in the file are not guaranteed to be in the same order as requests. Use the custom_id field to match results to requests.

    Type MessageBatch

    Object type.

    For Message Batches, this is always "message_batch".

    type MessageBatchCanceledResult struct{…}
    Type Canceled
    type MessageBatchErroredResult struct{…}
    Error ErrorResponse
    Error ErrorObjectUnion
    Accepts one of the following:
    type InvalidRequestError struct{…}
    Message string
    Type InvalidRequestError
    type AuthenticationError struct{…}
    Message string
    Type AuthenticationError
    type BillingError struct{…}
    Message string
    Type BillingError
    type PermissionError struct{…}
    Message string
    Type PermissionError
    type NotFoundError struct{…}
    Message string
    Type NotFoundError
    type RateLimitError struct{…}
    Message string
    Type RateLimitError
    type GatewayTimeoutError struct{…}
    Message string
    Type TimeoutError
    type APIErrorObject struct{…}
    Message string
    Type APIError
    type OverloadedError struct{…}
    Message string
    Type OverloadedError
    RequestID string
    Type Error
    Type Errored
    type MessageBatchExpiredResult struct{…}
    Type Expired
    type MessageBatchIndividualResponse struct{…}

    This is a single line in the response .jsonl file and does not represent the response as a whole.

    CustomID string

    Developer-provided ID created for each request in a Message Batch. Useful for matching results to requests, as results may be given out of request order.

    Must be unique for each request within the Message Batch.

    Result MessageBatchResultUnion

    Processing result for this request.

    Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.

    Accepts one of the following:
    type MessageBatchSucceededResult struct{…}
    Message Message
    ID string

    Unique object identifier.

    The format and length of IDs may change over time.

    Container Container

    Information about the container used in the request (for the code execution tool)

    ID string

    Identifier for the container used in this request

    ExpiresAt Time

    The time at which the container will expire.

    Content []ContentBlockUnion

    Content generated by the model.

    This is an array of content blocks, each of which has a type that determines its shape.

    Example:

    [{"type": "text", "text": "Hi, I'm Claude."}]
    

    If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.

    For example, if the input messages were:

    [
      {"role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"},
      {"role": "assistant", "content": "The best answer is ("}
    ]
    

    Then the response content might be:

    [{"type": "text", "text": "B)"}]
    
    Accepts one of the following:
    type TextBlock struct{…}
    Citations []TextCitationUnion

    Citations supporting the text block.

    The type of citation returned will depend on the type of document being cited. Citing a PDF results in page_location, plain text results in char_location, and content document results in content_block_location.

    Accepts one of the following:
    type CitationCharLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndCharIndex int64
    FileID string
    StartCharIndex int64
    Type CharLocation
    type CitationPageLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndPageNumber int64
    FileID string
    StartPageNumber int64
    Type PageLocation
    type CitationContentBlockLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndBlockIndex int64
    FileID string
    StartBlockIndex int64
    Type ContentBlockLocation
    type CitationsWebSearchResultLocation struct{…}
    CitedText string
    EncryptedIndex string
    Title string
    Type WebSearchResultLocation
    URL string
    type CitationsSearchResultLocation struct{…}
    CitedText string
    EndBlockIndex int64
    SearchResultIndex int64
    Source string
    StartBlockIndex int64
    Title string
    Type SearchResultLocation
    Text string
    Type Text
    type ThinkingBlock struct{…}
    Signature string
    Thinking string
    Type Thinking
    type RedactedThinkingBlock struct{…}
    Data string
    Type RedactedThinking
    type ToolUseBlock struct{…}
    ID string
    Caller ToolUseBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Input map[string, any]
    Name string
    Type ToolUse
    type ServerToolUseBlock struct{…}
    ID string
    Caller ServerToolUseBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Input map[string, any]
    Name ServerToolUseBlockName
    Accepts one of the following:
    const ServerToolUseBlockNameWebSearch ServerToolUseBlockName = "web_search"
    const ServerToolUseBlockNameWebFetch ServerToolUseBlockName = "web_fetch"
    const ServerToolUseBlockNameCodeExecution ServerToolUseBlockName = "code_execution"
    const ServerToolUseBlockNameBashCodeExecution ServerToolUseBlockName = "bash_code_execution"
    const ServerToolUseBlockNameTextEditorCodeExecution ServerToolUseBlockName = "text_editor_code_execution"
    const ServerToolUseBlockNameToolSearchToolRegex ServerToolUseBlockName = "tool_search_tool_regex"
    const ServerToolUseBlockNameToolSearchToolBm25 ServerToolUseBlockName = "tool_search_tool_bm25"
    Type ServerToolUse
    type WebSearchToolResultBlock struct{…}
    Caller WebSearchToolResultBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Content WebSearchToolResultBlockContentUnion
    Accepts one of the following:
    type WebSearchToolResultError struct{…}
    ErrorCode WebSearchToolResultErrorCode
    Accepts one of the following:
    const WebSearchToolResultErrorCodeInvalidToolInput WebSearchToolResultErrorCode = "invalid_tool_input"
    const WebSearchToolResultErrorCodeUnavailable WebSearchToolResultErrorCode = "unavailable"
    const WebSearchToolResultErrorCodeMaxUsesExceeded WebSearchToolResultErrorCode = "max_uses_exceeded"
    const WebSearchToolResultErrorCodeTooManyRequests WebSearchToolResultErrorCode = "too_many_requests"
    const WebSearchToolResultErrorCodeQueryTooLong WebSearchToolResultErrorCode = "query_too_long"
    const WebSearchToolResultErrorCodeRequestTooLarge WebSearchToolResultErrorCode = "request_too_large"
    Type WebSearchToolResultError
    type WebSearchToolResultBlockContentArray []WebSearchResultBlock
    EncryptedContent string
    PageAge string
    Title string
    Type WebSearchResult
    URL string
    ToolUseID string
    Type WebSearchToolResult
    type WebFetchToolResultBlock struct{…}
    Caller WebFetchToolResultBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Content WebFetchToolResultBlockContentUnion
    Accepts one of the following:
    type WebFetchToolResultErrorBlock struct{…}
    ErrorCode WebFetchToolResultErrorCode
    Accepts one of the following:
    const WebFetchToolResultErrorCodeInvalidToolInput WebFetchToolResultErrorCode = "invalid_tool_input"
    const WebFetchToolResultErrorCodeURLTooLong WebFetchToolResultErrorCode = "url_too_long"
    const WebFetchToolResultErrorCodeURLNotAllowed WebFetchToolResultErrorCode = "url_not_allowed"
    const WebFetchToolResultErrorCodeURLNotAccessible WebFetchToolResultErrorCode = "url_not_accessible"
    const WebFetchToolResultErrorCodeUnsupportedContentType WebFetchToolResultErrorCode = "unsupported_content_type"
    const WebFetchToolResultErrorCodeTooManyRequests WebFetchToolResultErrorCode = "too_many_requests"
    const WebFetchToolResultErrorCodeMaxUsesExceeded WebFetchToolResultErrorCode = "max_uses_exceeded"
    const WebFetchToolResultErrorCodeUnavailable WebFetchToolResultErrorCode = "unavailable"
    Type WebFetchToolResultError
    type WebFetchBlock struct{…}
    Content DocumentBlock
    Citations CitationsConfig

    Citation configuration for the document

    Enabled bool
    Source DocumentBlockSourceUnion
    Accepts one of the following:
    type Base64PDFSource struct{…}
    Data string
    MediaType ApplicationPDF
    Type Base64
    type PlainTextSource struct{…}
    Data string
    MediaType TextPlain
    Type Text
    Title string

    The title of the document

    Type Document
    RetrievedAt string

    ISO 8601 timestamp when the content was retrieved

    Type WebFetchResult
    URL string

    Fetched content URL

    ToolUseID string
    Type WebFetchToolResult
    type CodeExecutionToolResultBlock struct{…}
    Content CodeExecutionToolResultBlockContentUnion

    Code execution result with encrypted stdout for PFC + web_search results.

    Accepts one of the following:
    type CodeExecutionToolResultError struct{…}
    ErrorCode CodeExecutionToolResultErrorCode
    Accepts one of the following:
    const CodeExecutionToolResultErrorCodeInvalidToolInput CodeExecutionToolResultErrorCode = "invalid_tool_input"
    const CodeExecutionToolResultErrorCodeUnavailable CodeExecutionToolResultErrorCode = "unavailable"
    const CodeExecutionToolResultErrorCodeTooManyRequests CodeExecutionToolResultErrorCode = "too_many_requests"
    const CodeExecutionToolResultErrorCodeExecutionTimeExceeded CodeExecutionToolResultErrorCode = "execution_time_exceeded"
    Type CodeExecutionToolResultError
    type CodeExecutionResultBlock struct{…}
    Content []CodeExecutionOutputBlock
    FileID string
    Type CodeExecutionOutput
    ReturnCode int64
    Stderr string
    Stdout string
    Type CodeExecutionResult
    type EncryptedCodeExecutionResultBlock struct{…}

    Code execution result with encrypted stdout for PFC + web_search results.

    Content []CodeExecutionOutputBlock
    FileID string
    Type CodeExecutionOutput
    EncryptedStdout string
    ReturnCode int64
    Stderr string
    Type EncryptedCodeExecutionResult
    ToolUseID string
    Type CodeExecutionToolResult
    type BashCodeExecutionToolResultBlock struct{…}
    Content BashCodeExecutionToolResultBlockContentUnion
    Accepts one of the following:
    type BashCodeExecutionToolResultError struct{…}
    ErrorCode BashCodeExecutionToolResultErrorCode
    Accepts one of the following:
    const BashCodeExecutionToolResultErrorCodeInvalidToolInput BashCodeExecutionToolResultErrorCode = "invalid_tool_input"
    const BashCodeExecutionToolResultErrorCodeUnavailable BashCodeExecutionToolResultErrorCode = "unavailable"
    const BashCodeExecutionToolResultErrorCodeTooManyRequests BashCodeExecutionToolResultErrorCode = "too_many_requests"
    const BashCodeExecutionToolResultErrorCodeExecutionTimeExceeded BashCodeExecutionToolResultErrorCode = "execution_time_exceeded"
    const BashCodeExecutionToolResultErrorCodeOutputFileTooLarge BashCodeExecutionToolResultErrorCode = "output_file_too_large"
    Type BashCodeExecutionToolResultError
    type BashCodeExecutionResultBlock struct{…}
    Content []BashCodeExecutionOutputBlock
    FileID string
    Type BashCodeExecutionOutput
    ReturnCode int64
    Stderr string
    Stdout string
    Type BashCodeExecutionResult
    ToolUseID string
    Type BashCodeExecutionToolResult
    type TextEditorCodeExecutionToolResultBlock struct{…}
    Content TextEditorCodeExecutionToolResultBlockContentUnion
    Accepts one of the following:
    type TextEditorCodeExecutionToolResultError struct{…}
    ErrorCode TextEditorCodeExecutionToolResultErrorCode
    Accepts one of the following:
    const TextEditorCodeExecutionToolResultErrorCodeInvalidToolInput TextEditorCodeExecutionToolResultErrorCode = "invalid_tool_input"
    const TextEditorCodeExecutionToolResultErrorCodeUnavailable TextEditorCodeExecutionToolResultErrorCode = "unavailable"
    const TextEditorCodeExecutionToolResultErrorCodeTooManyRequests TextEditorCodeExecutionToolResultErrorCode = "too_many_requests"
    const TextEditorCodeExecutionToolResultErrorCodeExecutionTimeExceeded TextEditorCodeExecutionToolResultErrorCode = "execution_time_exceeded"
    const TextEditorCodeExecutionToolResultErrorCodeFileNotFound TextEditorCodeExecutionToolResultErrorCode = "file_not_found"
    ErrorMessage string
    Type TextEditorCodeExecutionToolResultError
    type TextEditorCodeExecutionViewResultBlock struct{…}
    Content string
    FileType TextEditorCodeExecutionViewResultBlockFileType
    Accepts one of the following:
    const TextEditorCodeExecutionViewResultBlockFileTypeText TextEditorCodeExecutionViewResultBlockFileType = "text"
    const TextEditorCodeExecutionViewResultBlockFileTypeImage TextEditorCodeExecutionViewResultBlockFileType = "image"
    const TextEditorCodeExecutionViewResultBlockFileTypePDF TextEditorCodeExecutionViewResultBlockFileType = "pdf"
    NumLines int64
    StartLine int64
    TotalLines int64
    Type TextEditorCodeExecutionViewResult
    type TextEditorCodeExecutionCreateResultBlock struct{…}
    IsFileUpdate bool
    Type TextEditorCodeExecutionCreateResult
    type TextEditorCodeExecutionStrReplaceResultBlock struct{…}
    Lines []string
    NewLines int64
    NewStart int64
    OldLines int64
    OldStart int64
    Type TextEditorCodeExecutionStrReplaceResult
    ToolUseID string
    Type TextEditorCodeExecutionToolResult
    type ToolSearchToolResultBlock struct{…}
    Content ToolSearchToolResultBlockContentUnion
    Accepts one of the following:
    type ToolSearchToolResultError struct{…}
    ErrorCode ToolSearchToolResultErrorCode
    Accepts one of the following:
    const ToolSearchToolResultErrorCodeInvalidToolInput ToolSearchToolResultErrorCode = "invalid_tool_input"
    const ToolSearchToolResultErrorCodeUnavailable ToolSearchToolResultErrorCode = "unavailable"
    const ToolSearchToolResultErrorCodeTooManyRequests ToolSearchToolResultErrorCode = "too_many_requests"
    const ToolSearchToolResultErrorCodeExecutionTimeExceeded ToolSearchToolResultErrorCode = "execution_time_exceeded"
    ErrorMessage string
    Type ToolSearchToolResultError
    type ToolSearchToolSearchResultBlock struct{…}
    ToolReferences []ToolReferenceBlock
    ToolName string
    Type ToolReference
    Type ToolSearchToolSearchResult
    ToolUseID string
    Type ToolSearchToolResult
    type ContainerUploadBlock struct{…}

    Response model for a file uploaded to the container.

    FileID string
    Type ContainerUpload
    Model Model

    The model that will complete your prompt.

    See models for additional details and options.

    Accepts one of the following:
    type Model string

    The model that will complete your prompt.

    See models for additional details and options.

    Accepts one of the following:
    const ModelClaudeOpus4_6 Model = "claude-opus-4-6"

    Most intelligent model for building agents and coding

    const ModelClaudeSonnet4_6 Model = "claude-sonnet-4-6"

    Frontier intelligence at scale — built for coding, agents, and enterprise workflows

    const ModelClaudeOpus4_5_20251101 Model = "claude-opus-4-5-20251101"

    Premium model combining maximum intelligence with practical performance

    const ModelClaudeOpus4_5 Model = "claude-opus-4-5"

    Premium model combining maximum intelligence with practical performance

    const ModelClaude3_7SonnetLatest Model = "claude-3-7-sonnet-latest"

    High-performance model with early extended thinking

    const ModelClaude3_7Sonnet20250219 Model = "claude-3-7-sonnet-20250219"

    High-performance model with early extended thinking

    const ModelClaude3_5HaikuLatest Model = "claude-3-5-haiku-latest"

    Fastest and most compact model for near-instant responsiveness

    const ModelClaude3_5Haiku20241022 Model = "claude-3-5-haiku-20241022"

    Our fastest model

    const ModelClaudeHaiku4_5 Model = "claude-haiku-4-5"

    Hybrid model, capable of near-instant responses and extended thinking

    const ModelClaudeHaiku4_5_20251001 Model = "claude-haiku-4-5-20251001"

    Hybrid model, capable of near-instant responses and extended thinking

    const ModelClaudeSonnet4_20250514 Model = "claude-sonnet-4-20250514"

    High-performance model with extended thinking

    const ModelClaudeSonnet4_0 Model = "claude-sonnet-4-0"

    High-performance model with extended thinking

    const ModelClaude4Sonnet20250514 Model = "claude-4-sonnet-20250514"

    High-performance model with extended thinking

    const ModelClaudeSonnet4_5 Model = "claude-sonnet-4-5"

    Our best model for real-world agents and coding

    const ModelClaudeSonnet4_5_20250929 Model = "claude-sonnet-4-5-20250929"

    Our best model for real-world agents and coding

    const ModelClaudeOpus4_0 Model = "claude-opus-4-0"

    Our most capable model

    const ModelClaudeOpus4_20250514 Model = "claude-opus-4-20250514"

    Our most capable model

    const ModelClaude4Opus20250514 Model = "claude-4-opus-20250514"

    Our most capable model

    const ModelClaudeOpus4_1_20250805 Model = "claude-opus-4-1-20250805"

    Our most capable model

    const ModelClaude3OpusLatest Model = "claude-3-opus-latest"

    Excels at writing and complex tasks

    const ModelClaude_3_Opus_20240229 Model = "claude-3-opus-20240229"

    Excels at writing and complex tasks

    const ModelClaude_3_Haiku_20240307 Model = "claude-3-haiku-20240307"

    Our previous most fast and cost-effective

    string
    Role Assistant

    Conversational role of the generated message.

    This will always be "assistant".

    StopReason StopReason

    The reason that we stopped.

    This may be one the following values:

    • "end_turn": the model reached a natural stopping point
    • "max_tokens": we exceeded the requested max_tokens or the model's maximum
    • "stop_sequence": one of your provided custom stop_sequences was generated
    • "tool_use": the model invoked one or more tools
    • "pause_turn": we paused a long-running turn. You may provide the response back as-is in a subsequent request to let the model continue.
    • "refusal": when streaming classifiers intervene to handle potential policy violations

    In non-streaming mode this value is always non-null. In streaming mode, it is null in the message_start event and non-null otherwise.

    Accepts one of the following:
    const StopReasonEndTurn StopReason = "end_turn"
    const StopReasonMaxTokens StopReason = "max_tokens"
    const StopReasonStopSequence StopReason = "stop_sequence"
    const StopReasonToolUse StopReason = "tool_use"
    const StopReasonPauseTurn StopReason = "pause_turn"
    const StopReasonRefusal StopReason = "refusal"
    StopSequence string

    Which custom stop sequence was generated, if any.

    This value will be a non-null string if one of your custom stop sequences was generated.

    Type Message

    Object type.

    For Messages, this is always "message".

    Usage Usage

    Billing and rate-limit usage.

    Anthropic's API bills and rate-limits by token counts, as tokens represent the underlying cost to our systems.

    Under the hood, the API transforms requests into a format suitable for the model. The model's output then goes through a parsing stage before becoming an API response. As a result, the token counts in usage will not match one-to-one with the exact visible content of an API request or response.

    For example, output_tokens will be non-zero, even for an empty string response from Claude.

    Total input tokens in a request is the summation of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens.

    CacheCreation CacheCreation

    Breakdown of cached tokens by TTL

    Ephemeral1hInputTokens int64

    The number of input tokens used to create the 1 hour cache entry.

    Ephemeral5mInputTokens int64

    The number of input tokens used to create the 5 minute cache entry.

    CacheCreationInputTokens int64

    The number of input tokens used to create the cache entry.

    CacheReadInputTokens int64

    The number of input tokens read from the cache.

    InferenceGeo string

    The geographic region where inference was performed for this request.

    InputTokens int64

    The number of input tokens which were used.

    OutputTokens int64

    The number of output tokens which were used.

    ServerToolUse ServerToolUsage

    The number of server tool requests.

    WebFetchRequests int64

    The number of web fetch tool requests.

    WebSearchRequests int64

    The number of web search tool requests.

    ServiceTier UsageServiceTier

    If the request used the priority, standard, or batch tier.

    Accepts one of the following:
    const UsageServiceTierStandard UsageServiceTier = "standard"
    const UsageServiceTierPriority UsageServiceTier = "priority"
    const UsageServiceTierBatch UsageServiceTier = "batch"
    Type Succeeded
    type MessageBatchErroredResult struct{…}
    Error ErrorResponse
    Error ErrorObjectUnion
    Accepts one of the following:
    type InvalidRequestError struct{…}
    Message string
    Type InvalidRequestError
    type AuthenticationError struct{…}
    Message string
    Type AuthenticationError
    type BillingError struct{…}
    Message string
    Type BillingError
    type PermissionError struct{…}
    Message string
    Type PermissionError
    type NotFoundError struct{…}
    Message string
    Type NotFoundError
    type RateLimitError struct{…}
    Message string
    Type RateLimitError
    type GatewayTimeoutError struct{…}
    Message string
    Type TimeoutError
    type APIErrorObject struct{…}
    Message string
    Type APIError
    type OverloadedError struct{…}
    Message string
    Type OverloadedError
    RequestID string
    Type Error
    Type Errored
    type MessageBatchCanceledResult struct{…}
    Type Canceled
    type MessageBatchExpiredResult struct{…}
    Type Expired
    type MessageBatchRequestCounts struct{…}
    Canceled int64

    Number of requests in the Message Batch that have been canceled.

    This is zero until processing of the entire Message Batch has ended.

    Errored int64

    Number of requests in the Message Batch that encountered an error.

    This is zero until processing of the entire Message Batch has ended.

    Expired int64

    Number of requests in the Message Batch that have expired.

    This is zero until processing of the entire Message Batch has ended.

    Processing int64

    Number of requests in the Message Batch that are processing.

    Succeeded int64

    Number of requests in the Message Batch that have completed successfully.

    This is zero until processing of the entire Message Batch has ended.

    type MessageBatchResultUnion interface{…}

    Processing result for this request.

    Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.

    Accepts one of the following:
    type MessageBatchSucceededResult struct{…}
    Message Message
    ID string

    Unique object identifier.

    The format and length of IDs may change over time.

    Container Container

    Information about the container used in the request (for the code execution tool)

    ID string

    Identifier for the container used in this request

    ExpiresAt Time

    The time at which the container will expire.

    Content []ContentBlockUnion

    Content generated by the model.

    This is an array of content blocks, each of which has a type that determines its shape.

    Example:

    [{"type": "text", "text": "Hi, I'm Claude."}]
    

    If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.

    For example, if the input messages were:

    [
      {"role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"},
      {"role": "assistant", "content": "The best answer is ("}
    ]
    

    Then the response content might be:

    [{"type": "text", "text": "B)"}]
    
    Accepts one of the following:
    type TextBlock struct{…}
    Citations []TextCitationUnion

    Citations supporting the text block.

    The type of citation returned will depend on the type of document being cited. Citing a PDF results in page_location, plain text results in char_location, and content document results in content_block_location.

    Accepts one of the following:
    type CitationCharLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndCharIndex int64
    FileID string
    StartCharIndex int64
    Type CharLocation
    type CitationPageLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndPageNumber int64
    FileID string
    StartPageNumber int64
    Type PageLocation
    type CitationContentBlockLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndBlockIndex int64
    FileID string
    StartBlockIndex int64
    Type ContentBlockLocation
    type CitationsWebSearchResultLocation struct{…}
    CitedText string
    EncryptedIndex string
    Title string
    Type WebSearchResultLocation
    URL string
    type CitationsSearchResultLocation struct{…}
    CitedText string
    EndBlockIndex int64
    SearchResultIndex int64
    Source string
    StartBlockIndex int64
    Title string
    Type SearchResultLocation
    Text string
    Type Text
    type ThinkingBlock struct{…}
    Signature string
    Thinking string
    Type Thinking
    type RedactedThinkingBlock struct{…}
    Data string
    Type RedactedThinking
    type ToolUseBlock struct{…}
    ID string
    Caller ToolUseBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Input map[string, any]
    Name string
    Type ToolUse
    type ServerToolUseBlock struct{…}
    ID string
    Caller ServerToolUseBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Input map[string, any]
    Name ServerToolUseBlockName
    Accepts one of the following:
    const ServerToolUseBlockNameWebSearch ServerToolUseBlockName = "web_search"
    const ServerToolUseBlockNameWebFetch ServerToolUseBlockName = "web_fetch"
    const ServerToolUseBlockNameCodeExecution ServerToolUseBlockName = "code_execution"
    const ServerToolUseBlockNameBashCodeExecution ServerToolUseBlockName = "bash_code_execution"
    const ServerToolUseBlockNameTextEditorCodeExecution ServerToolUseBlockName = "text_editor_code_execution"
    const ServerToolUseBlockNameToolSearchToolRegex ServerToolUseBlockName = "tool_search_tool_regex"
    const ServerToolUseBlockNameToolSearchToolBm25 ServerToolUseBlockName = "tool_search_tool_bm25"
    Type ServerToolUse
    type WebSearchToolResultBlock struct{…}
    Caller WebSearchToolResultBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Content WebSearchToolResultBlockContentUnion
    Accepts one of the following:
    type WebSearchToolResultError struct{…}
    ErrorCode WebSearchToolResultErrorCode
    Accepts one of the following:
    const WebSearchToolResultErrorCodeInvalidToolInput WebSearchToolResultErrorCode = "invalid_tool_input"
    const WebSearchToolResultErrorCodeUnavailable WebSearchToolResultErrorCode = "unavailable"
    const WebSearchToolResultErrorCodeMaxUsesExceeded WebSearchToolResultErrorCode = "max_uses_exceeded"
    const WebSearchToolResultErrorCodeTooManyRequests WebSearchToolResultErrorCode = "too_many_requests"
    const WebSearchToolResultErrorCodeQueryTooLong WebSearchToolResultErrorCode = "query_too_long"
    const WebSearchToolResultErrorCodeRequestTooLarge WebSearchToolResultErrorCode = "request_too_large"
    Type WebSearchToolResultError
    type WebSearchToolResultBlockContentArray []WebSearchResultBlock
    EncryptedContent string
    PageAge string
    Title string
    Type WebSearchResult
    URL string
    ToolUseID string
    Type WebSearchToolResult
    type WebFetchToolResultBlock struct{…}
    Caller WebFetchToolResultBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Content WebFetchToolResultBlockContentUnion
    Accepts one of the following:
    type WebFetchToolResultErrorBlock struct{…}
    ErrorCode WebFetchToolResultErrorCode
    Accepts one of the following:
    const WebFetchToolResultErrorCodeInvalidToolInput WebFetchToolResultErrorCode = "invalid_tool_input"
    const WebFetchToolResultErrorCodeURLTooLong WebFetchToolResultErrorCode = "url_too_long"
    const WebFetchToolResultErrorCodeURLNotAllowed WebFetchToolResultErrorCode = "url_not_allowed"
    const WebFetchToolResultErrorCodeURLNotAccessible WebFetchToolResultErrorCode = "url_not_accessible"
    const WebFetchToolResultErrorCodeUnsupportedContentType WebFetchToolResultErrorCode = "unsupported_content_type"
    const WebFetchToolResultErrorCodeTooManyRequests WebFetchToolResultErrorCode = "too_many_requests"
    const WebFetchToolResultErrorCodeMaxUsesExceeded WebFetchToolResultErrorCode = "max_uses_exceeded"
    const WebFetchToolResultErrorCodeUnavailable WebFetchToolResultErrorCode = "unavailable"
    Type WebFetchToolResultError
    type WebFetchBlock struct{…}
    Content DocumentBlock
    Citations CitationsConfig

    Citation configuration for the document

    Enabled bool
    Source DocumentBlockSourceUnion
    Accepts one of the following:
    type Base64PDFSource struct{…}
    Data string
    MediaType ApplicationPDF
    Type Base64
    type PlainTextSource struct{…}
    Data string
    MediaType TextPlain
    Type Text
    Title string

    The title of the document

    Type Document
    RetrievedAt string

    ISO 8601 timestamp when the content was retrieved

    Type WebFetchResult
    URL string

    Fetched content URL

    ToolUseID string
    Type WebFetchToolResult
    type CodeExecutionToolResultBlock struct{…}
    Content CodeExecutionToolResultBlockContentUnion

    Code execution result with encrypted stdout for PFC + web_search results.

    Accepts one of the following:
    type CodeExecutionToolResultError struct{…}
    ErrorCode CodeExecutionToolResultErrorCode
    Accepts one of the following:
    const CodeExecutionToolResultErrorCodeInvalidToolInput CodeExecutionToolResultErrorCode = "invalid_tool_input"
    const CodeExecutionToolResultErrorCodeUnavailable CodeExecutionToolResultErrorCode = "unavailable"
    const CodeExecutionToolResultErrorCodeTooManyRequests CodeExecutionToolResultErrorCode = "too_many_requests"
    const CodeExecutionToolResultErrorCodeExecutionTimeExceeded CodeExecutionToolResultErrorCode = "execution_time_exceeded"
    Type CodeExecutionToolResultError
    type CodeExecutionResultBlock struct{…}
    Content []CodeExecutionOutputBlock
    FileID string
    Type CodeExecutionOutput
    ReturnCode int64
    Stderr string
    Stdout string
    Type CodeExecutionResult
    type EncryptedCodeExecutionResultBlock struct{…}

    Code execution result with encrypted stdout for PFC + web_search results.

    Content []CodeExecutionOutputBlock
    FileID string
    Type CodeExecutionOutput
    EncryptedStdout string
    ReturnCode int64
    Stderr string
    Type EncryptedCodeExecutionResult
    ToolUseID string
    Type CodeExecutionToolResult
    type BashCodeExecutionToolResultBlock struct{…}
    Content BashCodeExecutionToolResultBlockContentUnion
    Accepts one of the following:
    type BashCodeExecutionToolResultError struct{…}
    ErrorCode BashCodeExecutionToolResultErrorCode
    Accepts one of the following:
    const BashCodeExecutionToolResultErrorCodeInvalidToolInput BashCodeExecutionToolResultErrorCode = "invalid_tool_input"
    const BashCodeExecutionToolResultErrorCodeUnavailable BashCodeExecutionToolResultErrorCode = "unavailable"
    const BashCodeExecutionToolResultErrorCodeTooManyRequests BashCodeExecutionToolResultErrorCode = "too_many_requests"
    const BashCodeExecutionToolResultErrorCodeExecutionTimeExceeded BashCodeExecutionToolResultErrorCode = "execution_time_exceeded"
    const BashCodeExecutionToolResultErrorCodeOutputFileTooLarge BashCodeExecutionToolResultErrorCode = "output_file_too_large"
    Type BashCodeExecutionToolResultError
    type BashCodeExecutionResultBlock struct{…}
    Content []BashCodeExecutionOutputBlock
    FileID string
    Type BashCodeExecutionOutput
    ReturnCode int64
    Stderr string
    Stdout string
    Type BashCodeExecutionResult
    ToolUseID string
    Type BashCodeExecutionToolResult
    type TextEditorCodeExecutionToolResultBlock struct{…}
    Content TextEditorCodeExecutionToolResultBlockContentUnion
    Accepts one of the following:
    type TextEditorCodeExecutionToolResultError struct{…}
    ErrorCode TextEditorCodeExecutionToolResultErrorCode
    Accepts one of the following:
    const TextEditorCodeExecutionToolResultErrorCodeInvalidToolInput TextEditorCodeExecutionToolResultErrorCode = "invalid_tool_input"
    const TextEditorCodeExecutionToolResultErrorCodeUnavailable TextEditorCodeExecutionToolResultErrorCode = "unavailable"
    const TextEditorCodeExecutionToolResultErrorCodeTooManyRequests TextEditorCodeExecutionToolResultErrorCode = "too_many_requests"
    const TextEditorCodeExecutionToolResultErrorCodeExecutionTimeExceeded TextEditorCodeExecutionToolResultErrorCode = "execution_time_exceeded"
    const TextEditorCodeExecutionToolResultErrorCodeFileNotFound TextEditorCodeExecutionToolResultErrorCode = "file_not_found"
    ErrorMessage string
    Type TextEditorCodeExecutionToolResultError
    type TextEditorCodeExecutionViewResultBlock struct{…}
    Content string
    FileType TextEditorCodeExecutionViewResultBlockFileType
    Accepts one of the following:
    const TextEditorCodeExecutionViewResultBlockFileTypeText TextEditorCodeExecutionViewResultBlockFileType = "text"
    const TextEditorCodeExecutionViewResultBlockFileTypeImage TextEditorCodeExecutionViewResultBlockFileType = "image"
    const TextEditorCodeExecutionViewResultBlockFileTypePDF TextEditorCodeExecutionViewResultBlockFileType = "pdf"
    NumLines int64
    StartLine int64
    TotalLines int64
    Type TextEditorCodeExecutionViewResult
    type TextEditorCodeExecutionCreateResultBlock struct{…}
    IsFileUpdate bool
    Type TextEditorCodeExecutionCreateResult
    type TextEditorCodeExecutionStrReplaceResultBlock struct{…}
    Lines []string
    NewLines int64
    NewStart int64
    OldLines int64
    OldStart int64
    Type TextEditorCodeExecutionStrReplaceResult
    ToolUseID string
    Type TextEditorCodeExecutionToolResult
    type ToolSearchToolResultBlock struct{…}
    Content ToolSearchToolResultBlockContentUnion
    Accepts one of the following:
    type ToolSearchToolResultError struct{…}
    ErrorCode ToolSearchToolResultErrorCode
    Accepts one of the following:
    const ToolSearchToolResultErrorCodeInvalidToolInput ToolSearchToolResultErrorCode = "invalid_tool_input"
    const ToolSearchToolResultErrorCodeUnavailable ToolSearchToolResultErrorCode = "unavailable"
    const ToolSearchToolResultErrorCodeTooManyRequests ToolSearchToolResultErrorCode = "too_many_requests"
    const ToolSearchToolResultErrorCodeExecutionTimeExceeded ToolSearchToolResultErrorCode = "execution_time_exceeded"
    ErrorMessage string
    Type ToolSearchToolResultError
    type ToolSearchToolSearchResultBlock struct{…}
    ToolReferences []ToolReferenceBlock
    ToolName string
    Type ToolReference
    Type ToolSearchToolSearchResult
    ToolUseID string
    Type ToolSearchToolResult
    type ContainerUploadBlock struct{…}

    Response model for a file uploaded to the container.

    FileID string
    Type ContainerUpload
    Model Model

    The model that will complete your prompt.

    See models for additional details and options.

    Accepts one of the following:
    type Model string

    The model that will complete your prompt.

    See models for additional details and options.

    Accepts one of the following:
    const ModelClaudeOpus4_6 Model = "claude-opus-4-6"

    Most intelligent model for building agents and coding

    const ModelClaudeSonnet4_6 Model = "claude-sonnet-4-6"

    Frontier intelligence at scale — built for coding, agents, and enterprise workflows

    const ModelClaudeOpus4_5_20251101 Model = "claude-opus-4-5-20251101"

    Premium model combining maximum intelligence with practical performance

    const ModelClaudeOpus4_5 Model = "claude-opus-4-5"

    Premium model combining maximum intelligence with practical performance

    const ModelClaude3_7SonnetLatest Model = "claude-3-7-sonnet-latest"

    High-performance model with early extended thinking

    const ModelClaude3_7Sonnet20250219 Model = "claude-3-7-sonnet-20250219"

    High-performance model with early extended thinking

    const ModelClaude3_5HaikuLatest Model = "claude-3-5-haiku-latest"

    Fastest and most compact model for near-instant responsiveness

    const ModelClaude3_5Haiku20241022 Model = "claude-3-5-haiku-20241022"

    Our fastest model

    const ModelClaudeHaiku4_5 Model = "claude-haiku-4-5"

    Hybrid model, capable of near-instant responses and extended thinking

    const ModelClaudeHaiku4_5_20251001 Model = "claude-haiku-4-5-20251001"

    Hybrid model, capable of near-instant responses and extended thinking

    const ModelClaudeSonnet4_20250514 Model = "claude-sonnet-4-20250514"

    High-performance model with extended thinking

    const ModelClaudeSonnet4_0 Model = "claude-sonnet-4-0"

    High-performance model with extended thinking

    const ModelClaude4Sonnet20250514 Model = "claude-4-sonnet-20250514"

    High-performance model with extended thinking

    const ModelClaudeSonnet4_5 Model = "claude-sonnet-4-5"

    Our best model for real-world agents and coding

    const ModelClaudeSonnet4_5_20250929 Model = "claude-sonnet-4-5-20250929"

    Our best model for real-world agents and coding

    const ModelClaudeOpus4_0 Model = "claude-opus-4-0"

    Our most capable model

    const ModelClaudeOpus4_20250514 Model = "claude-opus-4-20250514"

    Our most capable model

    const ModelClaude4Opus20250514 Model = "claude-4-opus-20250514"

    Our most capable model

    const ModelClaudeOpus4_1_20250805 Model = "claude-opus-4-1-20250805"

    Our most capable model

    const ModelClaude3OpusLatest Model = "claude-3-opus-latest"

    Excels at writing and complex tasks

    const ModelClaude_3_Opus_20240229 Model = "claude-3-opus-20240229"

    Excels at writing and complex tasks

    const ModelClaude_3_Haiku_20240307 Model = "claude-3-haiku-20240307"

    Our previous most fast and cost-effective

    string
    Role Assistant

    Conversational role of the generated message.

    This will always be "assistant".

    StopReason StopReason

    The reason that we stopped.

    This may be one the following values:

    • "end_turn": the model reached a natural stopping point
    • "max_tokens": we exceeded the requested max_tokens or the model's maximum
    • "stop_sequence": one of your provided custom stop_sequences was generated
    • "tool_use": the model invoked one or more tools
    • "pause_turn": we paused a long-running turn. You may provide the response back as-is in a subsequent request to let the model continue.
    • "refusal": when streaming classifiers intervene to handle potential policy violations

    In non-streaming mode this value is always non-null. In streaming mode, it is null in the message_start event and non-null otherwise.

    Accepts one of the following:
    const StopReasonEndTurn StopReason = "end_turn"
    const StopReasonMaxTokens StopReason = "max_tokens"
    const StopReasonStopSequence StopReason = "stop_sequence"
    const StopReasonToolUse StopReason = "tool_use"
    const StopReasonPauseTurn StopReason = "pause_turn"
    const StopReasonRefusal StopReason = "refusal"
    StopSequence string

    Which custom stop sequence was generated, if any.

    This value will be a non-null string if one of your custom stop sequences was generated.

    Type Message

    Object type.

    For Messages, this is always "message".

    Usage Usage

    Billing and rate-limit usage.

    Anthropic's API bills and rate-limits by token counts, as tokens represent the underlying cost to our systems.

    Under the hood, the API transforms requests into a format suitable for the model. The model's output then goes through a parsing stage before becoming an API response. As a result, the token counts in usage will not match one-to-one with the exact visible content of an API request or response.

    For example, output_tokens will be non-zero, even for an empty string response from Claude.

    Total input tokens in a request is the summation of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens.

    CacheCreation CacheCreation

    Breakdown of cached tokens by TTL

    Ephemeral1hInputTokens int64

    The number of input tokens used to create the 1 hour cache entry.

    Ephemeral5mInputTokens int64

    The number of input tokens used to create the 5 minute cache entry.

    CacheCreationInputTokens int64

    The number of input tokens used to create the cache entry.

    CacheReadInputTokens int64

    The number of input tokens read from the cache.

    InferenceGeo string

    The geographic region where inference was performed for this request.

    InputTokens int64

    The number of input tokens which were used.

    OutputTokens int64

    The number of output tokens which were used.

    ServerToolUse ServerToolUsage

    The number of server tool requests.

    WebFetchRequests int64

    The number of web fetch tool requests.

    WebSearchRequests int64

    The number of web search tool requests.

    ServiceTier UsageServiceTier

    If the request used the priority, standard, or batch tier.

    Accepts one of the following:
    const UsageServiceTierStandard UsageServiceTier = "standard"
    const UsageServiceTierPriority UsageServiceTier = "priority"
    const UsageServiceTierBatch UsageServiceTier = "batch"
    Type Succeeded
    type MessageBatchErroredResult struct{…}
    Error ErrorResponse
    Error ErrorObjectUnion
    Accepts one of the following:
    type InvalidRequestError struct{…}
    Message string
    Type InvalidRequestError
    type AuthenticationError struct{…}
    Message string
    Type AuthenticationError
    type BillingError struct{…}
    Message string
    Type BillingError
    type PermissionError struct{…}
    Message string
    Type PermissionError
    type NotFoundError struct{…}
    Message string
    Type NotFoundError
    type RateLimitError struct{…}
    Message string
    Type RateLimitError
    type GatewayTimeoutError struct{…}
    Message string
    Type TimeoutError
    type APIErrorObject struct{…}
    Message string
    Type APIError
    type OverloadedError struct{…}
    Message string
    Type OverloadedError
    RequestID string
    Type Error
    Type Errored
    type MessageBatchCanceledResult struct{…}
    Type Canceled
    type MessageBatchExpiredResult struct{…}
    Type Expired
    type MessageBatchSucceededResult struct{…}
    Message Message
    ID string

    Unique object identifier.

    The format and length of IDs may change over time.

    Container Container

    Information about the container used in the request (for the code execution tool)

    ID string

    Identifier for the container used in this request

    ExpiresAt Time

    The time at which the container will expire.

    Content []ContentBlockUnion

    Content generated by the model.

    This is an array of content blocks, each of which has a type that determines its shape.

    Example:

    [{"type": "text", "text": "Hi, I'm Claude."}]
    

    If the request input messages ended with an assistant turn, then the response content will continue directly from that last turn. You can use this to constrain the model's output.

    For example, if the input messages were:

    [
      {"role": "user", "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"},
      {"role": "assistant", "content": "The best answer is ("}
    ]
    

    Then the response content might be:

    [{"type": "text", "text": "B)"}]
    
    Accepts one of the following:
    type TextBlock struct{…}
    Citations []TextCitationUnion

    Citations supporting the text block.

    The type of citation returned will depend on the type of document being cited. Citing a PDF results in page_location, plain text results in char_location, and content document results in content_block_location.

    Accepts one of the following:
    type CitationCharLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndCharIndex int64
    FileID string
    StartCharIndex int64
    Type CharLocation
    type CitationPageLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndPageNumber int64
    FileID string
    StartPageNumber int64
    Type PageLocation
    type CitationContentBlockLocation struct{…}
    CitedText string
    DocumentIndex int64
    DocumentTitle string
    EndBlockIndex int64
    FileID string
    StartBlockIndex int64
    Type ContentBlockLocation
    type CitationsWebSearchResultLocation struct{…}
    CitedText string
    EncryptedIndex string
    Title string
    Type WebSearchResultLocation
    URL string
    type CitationsSearchResultLocation struct{…}
    CitedText string
    EndBlockIndex int64
    SearchResultIndex int64
    Source string
    StartBlockIndex int64
    Title string
    Type SearchResultLocation
    Text string
    Type Text
    type ThinkingBlock struct{…}
    Signature string
    Thinking string
    Type Thinking
    type RedactedThinkingBlock struct{…}
    Data string
    Type RedactedThinking
    type ToolUseBlock struct{…}
    ID string
    Caller ToolUseBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Input map[string, any]
    Name string
    Type ToolUse
    type ServerToolUseBlock struct{…}
    ID string
    Caller ServerToolUseBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Input map[string, any]
    Name ServerToolUseBlockName
    Accepts one of the following:
    const ServerToolUseBlockNameWebSearch ServerToolUseBlockName = "web_search"
    const ServerToolUseBlockNameWebFetch ServerToolUseBlockName = "web_fetch"
    const ServerToolUseBlockNameCodeExecution ServerToolUseBlockName = "code_execution"
    const ServerToolUseBlockNameBashCodeExecution ServerToolUseBlockName = "bash_code_execution"
    const ServerToolUseBlockNameTextEditorCodeExecution ServerToolUseBlockName = "text_editor_code_execution"
    const ServerToolUseBlockNameToolSearchToolRegex ServerToolUseBlockName = "tool_search_tool_regex"
    const ServerToolUseBlockNameToolSearchToolBm25 ServerToolUseBlockName = "tool_search_tool_bm25"
    Type ServerToolUse
    type WebSearchToolResultBlock struct{…}
    Caller WebSearchToolResultBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Content WebSearchToolResultBlockContentUnion
    Accepts one of the following:
    type WebSearchToolResultError struct{…}
    ErrorCode WebSearchToolResultErrorCode
    Accepts one of the following:
    const WebSearchToolResultErrorCodeInvalidToolInput WebSearchToolResultErrorCode = "invalid_tool_input"
    const WebSearchToolResultErrorCodeUnavailable WebSearchToolResultErrorCode = "unavailable"
    const WebSearchToolResultErrorCodeMaxUsesExceeded WebSearchToolResultErrorCode = "max_uses_exceeded"
    const WebSearchToolResultErrorCodeTooManyRequests WebSearchToolResultErrorCode = "too_many_requests"
    const WebSearchToolResultErrorCodeQueryTooLong WebSearchToolResultErrorCode = "query_too_long"
    const WebSearchToolResultErrorCodeRequestTooLarge WebSearchToolResultErrorCode = "request_too_large"
    Type WebSearchToolResultError
    type WebSearchToolResultBlockContentArray []WebSearchResultBlock
    EncryptedContent string
    PageAge string
    Title string
    Type WebSearchResult
    URL string
    ToolUseID string
    Type WebSearchToolResult
    type WebFetchToolResultBlock struct{…}
    Caller WebFetchToolResultBlockCallerUnion

    Tool invocation directly from the model.

    Accepts one of the following:
    type DirectCaller struct{…}

    Tool invocation directly from the model.

    Type Direct
    type ServerToolCaller struct{…}

    Tool invocation generated by a server-side tool.

    ToolID string
    Type CodeExecution20250825
    type ServerToolCaller20260120 struct{…}
    ToolID string
    Type CodeExecution20260120
    Content WebFetchToolResultBlockContentUnion
    Accepts one of the following:
    type WebFetchToolResultErrorBlock struct{…}
    ErrorCode WebFetchToolResultErrorCode
    Accepts one of the following:
    const WebFetchToolResultErrorCodeInvalidToolInput WebFetchToolResultErrorCode = "invalid_tool_input"
    const WebFetchToolResultErrorCodeURLTooLong WebFetchToolResultErrorCode = "url_too_long"
    const WebFetchToolResultErrorCodeURLNotAllowed WebFetchToolResultErrorCode = "url_not_allowed"
    const WebFetchToolResultErrorCodeURLNotAccessible WebFetchToolResultErrorCode = "url_not_accessible"
    const WebFetchToolResultErrorCodeUnsupportedContentType WebFetchToolResultErrorCode = "unsupported_content_type"
    const WebFetchToolResultErrorCodeTooManyRequests WebFetchToolResultErrorCode = "too_many_requests"
    const WebFetchToolResultErrorCodeMaxUsesExceeded WebFetchToolResultErrorCode = "max_uses_exceeded"
    const WebFetchToolResultErrorCodeUnavailable WebFetchToolResultErrorCode = "unavailable"
    Type WebFetchToolResultError
    type WebFetchBlock struct{…}
    Content DocumentBlock
    Citations CitationsConfig

    Citation configuration for the document

    Enabled bool
    Source DocumentBlockSourceUnion
    Accepts one of the following:
    type Base64PDFSource struct{…}
    Data string
    MediaType ApplicationPDF
    Type Base64
    type PlainTextSource struct{…}
    Data string
    MediaType TextPlain
    Type Text
    Title string

    The title of the document

    Type Document
    RetrievedAt string

    ISO 8601 timestamp when the content was retrieved

    Type WebFetchResult
    URL string

    Fetched content URL

    ToolUseID string
    Type WebFetchToolResult
    type CodeExecutionToolResultBlock struct{…}
    Content CodeExecutionToolResultBlockContentUnion

    Code execution result with encrypted stdout for PFC + web_search results.

    Accepts one of the following:
    type CodeExecutionToolResultError struct{…}
    ErrorCode CodeExecutionToolResultErrorCode
    Accepts one of the following:
    const CodeExecutionToolResultErrorCodeInvalidToolInput CodeExecutionToolResultErrorCode = "invalid_tool_input"
    const CodeExecutionToolResultErrorCodeUnavailable CodeExecutionToolResultErrorCode = "unavailable"
    const CodeExecutionToolResultErrorCodeTooManyRequests CodeExecutionToolResultErrorCode = "too_many_requests"
    const CodeExecutionToolResultErrorCodeExecutionTimeExceeded CodeExecutionToolResultErrorCode = "execution_time_exceeded"
    Type CodeExecutionToolResultError
    type CodeExecutionResultBlock struct{…}
    Content []CodeExecutionOutputBlock
    FileID string
    Type CodeExecutionOutput
    ReturnCode int64
    Stderr string
    Stdout string
    Type CodeExecutionResult
    type EncryptedCodeExecutionResultBlock struct{…}

    Code execution result with encrypted stdout for PFC + web_search results.

    Content []CodeExecutionOutputBlock
    FileID string
    Type CodeExecutionOutput
    EncryptedStdout string
    ReturnCode int64
    Stderr string
    Type EncryptedCodeExecutionResult
    ToolUseID string
    Type CodeExecutionToolResult
    type BashCodeExecutionToolResultBlock struct{…}
    Content BashCodeExecutionToolResultBlockContentUnion
    Accepts one of the following:
    type BashCodeExecutionToolResultError struct{…}
    ErrorCode BashCodeExecutionToolResultErrorCode
    Accepts one of the following:
    const BashCodeExecutionToolResultErrorCodeInvalidToolInput BashCodeExecutionToolResultErrorCode = "invalid_tool_input"
    const BashCodeExecutionToolResultErrorCodeUnavailable BashCodeExecutionToolResultErrorCode = "unavailable"
    const BashCodeExecutionToolResultErrorCodeTooManyRequests BashCodeExecutionToolResultErrorCode = "too_many_requests"
    const BashCodeExecutionToolResultErrorCodeExecutionTimeExceeded BashCodeExecutionToolResultErrorCode = "execution_time_exceeded"
    const BashCodeExecutionToolResultErrorCodeOutputFileTooLarge BashCodeExecutionToolResultErrorCode = "output_file_too_large"
    Type BashCodeExecutionToolResultError
    type BashCodeExecutionResultBlock struct{…}
    Content []BashCodeExecutionOutputBlock
    FileID string
    Type BashCodeExecutionOutput
    ReturnCode int64
    Stderr string
    Stdout string
    Type BashCodeExecutionResult
    ToolUseID string
    Type BashCodeExecutionToolResult
    type TextEditorCodeExecutionToolResultBlock struct{…}
    Content TextEditorCodeExecutionToolResultBlockContentUnion
    Accepts one of the following:
    type TextEditorCodeExecutionToolResultError struct{…}
    ErrorCode TextEditorCodeExecutionToolResultErrorCode
    Accepts one of the following:
    const TextEditorCodeExecutionToolResultErrorCodeInvalidToolInput TextEditorCodeExecutionToolResultErrorCode = "invalid_tool_input"
    const TextEditorCodeExecutionToolResultErrorCodeUnavailable TextEditorCodeExecutionToolResultErrorCode = "unavailable"
    const TextEditorCodeExecutionToolResultErrorCodeTooManyRequests TextEditorCodeExecutionToolResultErrorCode = "too_many_requests"
    const TextEditorCodeExecutionToolResultErrorCodeExecutionTimeExceeded TextEditorCodeExecutionToolResultErrorCode = "execution_time_exceeded"
    const TextEditorCodeExecutionToolResultErrorCodeFileNotFound TextEditorCodeExecutionToolResultErrorCode = "file_not_found"
    ErrorMessage string
    Type TextEditorCodeExecutionToolResultError
    type TextEditorCodeExecutionViewResultBlock struct{…}
    Content string
    FileType TextEditorCodeExecutionViewResultBlockFileType
    Accepts one of the following:
    const TextEditorCodeExecutionViewResultBlockFileTypeText TextEditorCodeExecutionViewResultBlockFileType = "text"
    const TextEditorCodeExecutionViewResultBlockFileTypeImage TextEditorCodeExecutionViewResultBlockFileType = "image"
    const TextEditorCodeExecutionViewResultBlockFileTypePDF TextEditorCodeExecutionViewResultBlockFileType = "pdf"
    NumLines int64
    StartLine int64
    TotalLines int64
    Type TextEditorCodeExecutionViewResult
    type TextEditorCodeExecutionCreateResultBlock struct{…}
    IsFileUpdate bool
    Type TextEditorCodeExecutionCreateResult
    type TextEditorCodeExecutionStrReplaceResultBlock struct{…}
    Lines []string
    NewLines int64
    NewStart int64
    OldLines int64
    OldStart int64
    Type TextEditorCodeExecutionStrReplaceResult
    ToolUseID string
    Type TextEditorCodeExecutionToolResult
    type ToolSearchToolResultBlock struct{…}
    Content ToolSearchToolResultBlockContentUnion
    Accepts one of the following:
    type ToolSearchToolResultError struct{…}
    ErrorCode ToolSearchToolResultErrorCode
    Accepts one of the following:
    const ToolSearchToolResultErrorCodeInvalidToolInput ToolSearchToolResultErrorCode = "invalid_tool_input"
    const ToolSearchToolResultErrorCodeUnavailable ToolSearchToolResultErrorCode = "unavailable"
    const ToolSearchToolResultErrorCodeTooManyRequests ToolSearchToolResultErrorCode = "too_many_requests"
    const ToolSearchToolResultErrorCodeExecutionTimeExceeded ToolSearchToolResultErrorCode = "execution_time_exceeded"
    ErrorMessage string
    Type ToolSearchToolResultError
    type ToolSearchToolSearchResultBlock struct{…}
    ToolReferences []ToolReferenceBlock
    ToolName string
    Type ToolReference
    Type ToolSearchToolSearchResult
    ToolUseID string
    Type ToolSearchToolResult
    type ContainerUploadBlock struct{…}

    Response model for a file uploaded to the container.

    FileID string
    Type ContainerUpload
    Model Model

    The model that will complete your prompt.

    See models for additional details and options.

    Accepts one of the following:
    type Model string

    The model that will complete your prompt.

    See models for additional details and options.

    Accepts one of the following:
    const ModelClaudeOpus4_6 Model = "claude-opus-4-6"

    Most intelligent model for building agents and coding

    const ModelClaudeSonnet4_6 Model = "claude-sonnet-4-6"

    Frontier intelligence at scale — built for coding, agents, and enterprise workflows

    const ModelClaudeOpus4_5_20251101 Model = "claude-opus-4-5-20251101"

    Premium model combining maximum intelligence with practical performance

    const ModelClaudeOpus4_5 Model = "claude-opus-4-5"

    Premium model combining maximum intelligence with practical performance

    const ModelClaude3_7SonnetLatest Model = "claude-3-7-sonnet-latest"

    High-performance model with early extended thinking

    const ModelClaude3_7Sonnet20250219 Model = "claude-3-7-sonnet-20250219"

    High-performance model with early extended thinking

    const ModelClaude3_5HaikuLatest Model = "claude-3-5-haiku-latest"

    Fastest and most compact model for near-instant responsiveness

    const ModelClaude3_5Haiku20241022 Model = "claude-3-5-haiku-20241022"

    Our fastest model

    const ModelClaudeHaiku4_5 Model = "claude-haiku-4-5"

    Hybrid model, capable of near-instant responses and extended thinking

    const ModelClaudeHaiku4_5_20251001 Model = "claude-haiku-4-5-20251001"

    Hybrid model, capable of near-instant responses and extended thinking

    const ModelClaudeSonnet4_20250514 Model = "claude-sonnet-4-20250514"

    High-performance model with extended thinking

    const ModelClaudeSonnet4_0 Model = "claude-sonnet-4-0"

    High-performance model with extended thinking

    const ModelClaude4Sonnet20250514 Model = "claude-4-sonnet-20250514"

    High-performance model with extended thinking

    const ModelClaudeSonnet4_5 Model = "claude-sonnet-4-5"

    Our best model for real-world agents and coding

    const ModelClaudeSonnet4_5_20250929 Model = "claude-sonnet-4-5-20250929"

    Our best model for real-world agents and coding

    const ModelClaudeOpus4_0 Model = "claude-opus-4-0"

    Our most capable model

    const ModelClaudeOpus4_20250514 Model = "claude-opus-4-20250514"

    Our most capable model

    const ModelClaude4Opus20250514 Model = "claude-4-opus-20250514"

    Our most capable model

    const ModelClaudeOpus4_1_20250805 Model = "claude-opus-4-1-20250805"

    Our most capable model

    const ModelClaude3OpusLatest Model = "claude-3-opus-latest"

    Excels at writing and complex tasks

    const ModelClaude_3_Opus_20240229 Model = "claude-3-opus-20240229"

    Excels at writing and complex tasks

    const ModelClaude_3_Haiku_20240307 Model = "claude-3-haiku-20240307"

    Our previous most fast and cost-effective

    string
    Role Assistant

    Conversational role of the generated message.

    This will always be "assistant".

    StopReason StopReason

    The reason that we stopped.

    This may be one the following values:

    • "end_turn": the model reached a natural stopping point
    • "max_tokens": we exceeded the requested max_tokens or the model's maximum
    • "stop_sequence": one of your provided custom stop_sequences was generated
    • "tool_use": the model invoked one or more tools
    • "pause_turn": we paused a long-running turn. You may provide the response back as-is in a subsequent request to let the model continue.
    • "refusal": when streaming classifiers intervene to handle potential policy violations

    In non-streaming mode this value is always non-null. In streaming mode, it is null in the message_start event and non-null otherwise.

    Accepts one of the following:
    const StopReasonEndTurn StopReason = "end_turn"
    const StopReasonMaxTokens StopReason = "max_tokens"
    const StopReasonStopSequence StopReason = "stop_sequence"
    const StopReasonToolUse StopReason = "tool_use"
    const StopReasonPauseTurn StopReason = "pause_turn"
    const StopReasonRefusal StopReason = "refusal"
    StopSequence string

    Which custom stop sequence was generated, if any.

    This value will be a non-null string if one of your custom stop sequences was generated.

    Type Message

    Object type.

    For Messages, this is always "message".

    Usage Usage

    Billing and rate-limit usage.

    Anthropic's API bills and rate-limits by token counts, as tokens represent the underlying cost to our systems.

    Under the hood, the API transforms requests into a format suitable for the model. The model's output then goes through a parsing stage before becoming an API response. As a result, the token counts in usage will not match one-to-one with the exact visible content of an API request or response.

    For example, output_tokens will be non-zero, even for an empty string response from Claude.

    Total input tokens in a request is the summation of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens.

    CacheCreation CacheCreation

    Breakdown of cached tokens by TTL

    Ephemeral1hInputTokens int64

    The number of input tokens used to create the 1 hour cache entry.

    Ephemeral5mInputTokens int64

    The number of input tokens used to create the 5 minute cache entry.

    CacheCreationInputTokens int64

    The number of input tokens used to create the cache entry.

    CacheReadInputTokens int64

    The number of input tokens read from the cache.

    InferenceGeo string

    The geographic region where inference was performed for this request.

    InputTokens int64

    The number of input tokens which were used.

    OutputTokens int64

    The number of output tokens which were used.

    ServerToolUse ServerToolUsage

    The number of server tool requests.

    WebFetchRequests int64

    The number of web fetch tool requests.

    WebSearchRequests int64

    The number of web search tool requests.

    ServiceTier UsageServiceTier

    If the request used the priority, standard, or batch tier.

    Accepts one of the following:
    const UsageServiceTierStandard UsageServiceTier = "standard"
    const UsageServiceTierPriority UsageServiceTier = "priority"
    const UsageServiceTierBatch UsageServiceTier = "batch"
    Type Succeeded

    Solutions

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

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • 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

    Learn

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

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

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