Request Configuration
Theresponses.Request struct allows you to fine-tune your LLM calls with several parameters:
Parameters
TheParameters struct contains additional configuration options:
You can use
ExtraFields to attach custom per-request HTTP headers via the reserved additional_headers key:
Reasoning Parameters
TheReasoningParam struct configures reasoning behavior:
Text Format (Structured Output)
TheTextFormat struct enables structured output using JSON schema:
Response Format
The Responses API returns data in two formats depending on whether streaming is enabled:Non-Streaming Response
WhenStream is false or not set, the API returns a complete Response object:
Output Message Types
TheOutput field contains an array of OutputMessageUnion, which can be one of the following types:
-
OutputMessage: Standard text message with contentID: Unique message identifierType: Always"message"Role: Message role ("user","system", or"developer")Content: Array of content parts (typically text)
-
FunctionCallMessage: Function/tool call from the modelType: Always"function_call"ID: Unique function call identifierCallID: Call identifier for trackingName: Name of the function to callArguments: JSON string containing function arguments
-
ReasoningMessage: Reasoning content from models that support chain-of-thoughtType: Always"reasoning"ID: Unique reasoning identifierSummary: Array of summary text contentEncryptedContent: Optional encrypted reasoning content (when requested viaInclude)
-
ImageGenerationCallMessage: Image generation requestType: Always"image_generation_call"ID: Unique image generation identifierStatus: Generation statusResult: Base64-encoded image data
-
WebSearchCallMessage: Web search requestType: Always"web_search_call"ID: Unique web search identifierAction: Search action details
Usage Information
TheUsage object provides token consumption details:
Error Handling
If an error occurs, theError field contains:
Streaming Response
WhenStream 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
TheResponseChunk union type can contain various chunk types that indicate different stages of the response:
Response Lifecycle Chunks:
response.created: Initial response object createdresponse.in_progress: Response generation in progressresponse.completed: Response generation completed
response.output_item.added: A new output item (message, function call, etc.) was addedresponse.output_item.done: An output item is complete
response.content_part.added: A new content part was added to a messageresponse.content_part.done: A content part is completeresponse.output_text.delta: Incremental text delta (new text fragment)response.output_text.annotation.added: A text annotation was addedresponse.output_text.done: Text generation is complete (includes full accumulated text)
response.function_call_arguments.delta: Incremental function call argumentsresponse.function_call_arguments.done: Function call arguments are complete
response.reasoning_summary_part.added: A new reasoning summary part was addedresponse.reasoning_summary_part.done: A reasoning summary part is completeresponse.reasoning_summary_text.delta: Incremental reasoning summary textresponse.reasoning_summary_text.done: Reasoning summary text is complete
response.image_generation_call.in_progress: Image generation startedresponse.image_generation_call.generating: Image is being generatedresponse.image_generation_call.partial_image: Partial image data available
response.web_search_call.in_progress: Web search startedresponse.web_search_call.searching: Search in progressresponse.web_search_call.completed: Search completed
Streaming Example
When streaming, chunks are delivered in this general order:response.created- Response object initializedresponse.output_item.added- First output item (e.g., a message) addedresponse.content_part.added- Content part added to the messageresponse.output_text.delta- Text deltas streamed incrementally (multiple chunks)response.output_text.done- Text generation complete (contains full text)response.content_part.done- Content part completeresponse.output_item.done- Output item completeresponse.completed- Response generation finished (includes final usage stats)
type: The chunk type identifiersequence_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.deltachunks to build the complete text - Function calls: Accumulate
response.function_call_arguments.deltachunks to build complete arguments - Usage stats: Available in
response.completedchunk - Final text: Available in
response.output_text.donechunk’stextfield