Skip to main content
The Responses API provides a unified interface for interacting with large language models from various providers. It offers fine-grained control over request parameters and supports features like tool calling, image generation, reasoning, structured output, and streaming.

Request Configuration

The responses.Request struct allows you to fine-tune your LLM calls with several parameters:

Parameters

The Parameters struct contains additional configuration options: You can use ExtraFields to attach custom per-request HTTP headers via the reserved additional_headers key:

Reasoning Parameters

The ReasoningParam struct configures reasoning behavior:

Text Format (Structured Output)

The TextFormat struct enables structured output using JSON schema:
See the Structured Output documentation for detailed examples.

Response Format

The Responses API returns data in two formats depending on whether streaming is enabled:

Non-Streaming Response

When Stream is false or not set, the API returns a complete Response object:

Output Message Types

The Output field contains an array of OutputMessageUnion, which can be one of the following types:
  • OutputMessage: Standard text message with content
    • ID: Unique message identifier
    • Type: Always "message"
    • Role: Message role ("user", "system", or "developer")
    • Content: Array of content parts (typically text)
  • FunctionCallMessage: Function/tool call from the model
    • Type: Always "function_call"
    • ID: Unique function call identifier
    • CallID: Call identifier for tracking
    • Name: Name of the function to call
    • Arguments: JSON string containing function arguments
  • ReasoningMessage: Reasoning content from models that support chain-of-thought
    • Type: Always "reasoning"
    • ID: Unique reasoning identifier
    • Summary: Array of summary text content
    • EncryptedContent: Optional encrypted reasoning content (when requested via Include)
  • ImageGenerationCallMessage: Image generation request
    • Type: Always "image_generation_call"
    • ID: Unique image generation identifier
    • Status: Generation status
    • Result: Base64-encoded image data
  • WebSearchCallMessage: Web search request
    • Type: Always "web_search_call"
    • ID: Unique web search identifier
    • Action: Search action details

Usage Information

The Usage object provides token consumption details:

Error Handling

If an error occurs, the Error field contains:

Streaming Response

When Stream is true, the API returns a stream of ResponseChunk objects via Server-Sent Events (SSE). Each chunk represents a part of the response as it’s generated.

Chunk Types

The ResponseChunk union type can contain various chunk types that indicate different stages of the response: Response Lifecycle Chunks:
  • response.created: Initial response object created
  • response.in_progress: Response generation in progress
  • response.completed: Response generation completed
Output Item Chunks:
  • response.output_item.added: A new output item (message, function call, etc.) was added
  • response.output_item.done: An output item is complete
Text Content Chunks:
  • response.content_part.added: A new content part was added to a message
  • response.content_part.done: A content part is complete
  • response.output_text.delta: Incremental text delta (new text fragment)
  • response.output_text.annotation.added: A text annotation was added
  • response.output_text.done: Text generation is complete (includes full accumulated text)
Function Call Chunks:
  • response.function_call_arguments.delta: Incremental function call arguments
  • response.function_call_arguments.done: Function call arguments are complete
Reasoning Chunks:
  • response.reasoning_summary_part.added: A new reasoning summary part was added
  • response.reasoning_summary_part.done: A reasoning summary part is complete
  • response.reasoning_summary_text.delta: Incremental reasoning summary text
  • response.reasoning_summary_text.done: Reasoning summary text is complete
Image Generation Chunks:
  • response.image_generation_call.in_progress: Image generation started
  • response.image_generation_call.generating: Image is being generated
  • response.image_generation_call.partial_image: Partial image data available
Web Search Chunks:
  • response.web_search_call.in_progress: Web search started
  • response.web_search_call.searching: Search in progress
  • response.web_search_call.completed: Search completed

Streaming Example

When streaming, chunks are delivered in this general order:
  1. response.created - Response object initialized
  2. response.output_item.added - First output item (e.g., a message) added
  3. response.content_part.added - Content part added to the message
  4. response.output_text.delta - Text deltas streamed incrementally (multiple chunks)
  5. response.output_text.done - Text generation complete (contains full text)
  6. response.content_part.done - Content part complete
  7. response.output_item.done - Output item complete
  8. response.completed - Response generation finished (includes final usage stats)
Each chunk includes:
  • type: The chunk type identifier
  • sequence_number: Ordering number for the chunk
  • Relevant data fields for that chunk type

Processing Streaming Responses

To process streaming responses, you’ll receive chunks via a channel (Go) or SSE stream (HTTP). Each chunk should be handled based on its type:
  • Text deltas: Accumulate response.output_text.delta chunks to build the complete text
  • Function calls: Accumulate response.function_call_arguments.delta chunks to build complete arguments
  • Usage stats: Available in response.completed chunk
  • Final text: Available in response.output_text.done chunk’s text field

Supported Providers

The Responses API supports the following LLM providers: