open_responses library

OpenResponses API client for Dart.

Provides a unified, type-safe interface for interacting with multiple LLM providers through the OpenResponses specification.

Getting Started

import 'package:open_responses/open_responses.dart';

final client = OpenResponsesClient(
  config: OpenResponsesConfig(
    authProvider: BearerTokenProvider('your-api-key'),
  ),
);

final response = await client.responses.create(
  CreateResponseRequest(
    model: 'gpt-4o',
    input: ResponseTextInput('Hello, world!'),
  ),
);

print(response.outputText);

client.close();

Using with Different Providers

OpenAI (Default)

final client = OpenResponsesClient(
  config: OpenResponsesConfig(
    authProvider: BearerTokenProvider(Platform.environment['OPENAI_API_KEY']!),
  ),
);

Ollama (Local)

final client = OpenResponsesClient(
  config: OpenResponsesConfig(
    baseUrl: 'http://localhost:11434/v1',
    // No auth needed for local Ollama
  ),
);

Learn More

Classes

Annotation
Annotation for output content (citations, etc.).
AssistantMessageContent
Content for an assistant message.
AssistantMessageItem
An assistant message item.
AssistantMessagePartsContent
List of output content parts for an assistant message.
AssistantMessageTextContent
Simple text content for an assistant message.
AuthCredentials
Authentication credentials returned by AuthProvider.
AuthProvider
Authentication provider interface for the OpenResponses client.
BearerTokenCredentials
Bearer token authentication credentials.
BearerTokenProvider
Simple bearer token provider with static credentials.
ContentPartAddedEvent
Event indicating a content part was added.
ContentPartDoneEvent
Event indicating a content part is done.
CreateResponseRequest
Request to create a response.
DeveloperMessageItem
A developer message item.
ErrorEvent
Error event during streaming.
ErrorPayload
Error information from a failed response.
FileCitation
File citation annotation.
FilePathAnnotation
File path annotation.
FunctionCallArgumentsDeltaEvent
Event with function call arguments delta.
FunctionCallArgumentsDoneEvent
Event indicating function call arguments are done.
FunctionCallItem
A function call item.
FunctionCallOutput
The output of a function call.
FunctionCallOutputContent
A list of content items output from a function call.
FunctionCallOutputItem
A function call output item.
FunctionCallOutputItemResponse
A function call output item in the response.
FunctionCallOutputString
A string output from a function call.
FunctionTool
A function tool.
IncompleteDetails
Details about why a response was incomplete.
InputContent
Input content for messages.
InputFileContent
File content via URL, file ID, or base64-encoded data.
InputImageContent
Image content via URL.
InputTextContent
Text content.
InputTokensDetails
Detailed breakdown of input tokens.
InputVideoContent
Video content via URL.
Item
Input item for a response request.
ItemReference
Reference to a previously created item.
JsonObjectFormat
JSON object response format.
JsonSchemaFormat
JSON schema response format.
LogProb
Log probability information for a token.
McpTool
A Model Context Protocol (MCP) tool.
MessageItem
A message item in a conversation.
MessageOutputItem
A message output item.
NoAuthCredentials
No authentication credentials.
NoAuthProvider
Provider that returns no authentication credentials.
OpenResponsesClient
Dart client for the OpenResponses API.
OpenResponsesConfig
Configuration for the OpenResponses client.
OutputContent
Output content from model.
OutputItem
Output item from a response.
OutputItemAddedEvent
Event indicating an output item was added.
OutputItemDoneEvent
Event indicating an output item is done.
OutputTextAnnotationAddedEvent
Event indicating an annotation was added.
OutputTextContent
Text output content.
OutputTextDeltaEvent
Event with a text delta.
OutputTextDoneEvent
Event indicating output text is done.
OutputTokensDetails
Detailed breakdown of output tokens.
ReasoningConfig
Configuration for reasoning models.
ReasoningDeltaEvent
Event with reasoning delta.
ReasoningDoneEvent
Event indicating reasoning is done.
ReasoningInputItem
A reasoning item used as input for multi-turn conversations.
ReasoningItem
A reasoning item from reasoning models.
ReasoningSummaryContent
Content within a reasoning summary.
ReasoningSummaryDeltaEvent
Event with reasoning summary delta.
ReasoningSummaryDoneEvent
Event indicating reasoning summary is done.
ReasoningSummaryPartAddedEvent
Event indicating a reasoning summary part was added.
ReasoningSummaryPartDoneEvent
Event indicating a reasoning summary part is done.
ReasoningTextContent
Reasoning text content from reasoning models.
RefusalContent
Refusal content when model declines to respond.
RefusalDeltaEvent
Event with a refusal delta.
RefusalDoneEvent
Event indicating refusal is done.
RequestMetadata
Metadata about the HTTP request that caused an error.
ResponseCompletedEvent
Event indicating a response completed successfully.
ResponseCreatedEvent
Event indicating a response was created.
ResponseFailedEvent
Event indicating a response failed.
ResponseIncompleteEvent
Event indicating a response was incomplete.
ResponseInProgressEvent
Event indicating a response is in progress.
ResponseInput
Type-safe input for a response request.
ResponseItemsInput
A list of items input.
ResponseMetadata
Metadata about the HTTP response that caused an error.
ResponseQueuedEvent
Event indicating a response was queued.
ResponseResource
A response resource from the API.
ResponsesResource
Resource for the Responses API.
ResponseStream
A streaming response with event-based callbacks.
ResponseTextInput
A simple text input.
RetryPolicy
Retry policy configuration.
ServiceTier
Service tier for request processing.
SpecificFunctionChoice
A specific function that can be selected.
SpecificToolChoice
A specific tool that can be selected.
StreamingEvent
Server-sent event for response streaming.
StreamingEventAccumulator
Accumulates streaming events into progressive state snapshots.
StreamingEventAccumulatorSnapshot
Accumulates streaming events into a progressive state.
StreamOptions
Options that control streamed response behavior.
SummaryTextContent
Summary text content from reasoning models.
SystemMessageItem
A system message item.
TextConfig
Configuration for text output.
TextFormat
Text output format.
TextResponseFormat
Plain text response format.
Tool
Tool definition for function calling.
ToolChoice
Tool choice specification.
ToolChoiceAllowedTools
Model can only call the specified tools.
ToolChoiceAuto
Model automatically decides whether to call tools.
ToolChoiceFunction
Model must call the specified function.
ToolChoiceNone
No tool should be called.
ToolChoiceRequired
Model must call at least one tool.
TopLogProb
Top alternative token with log probability.
UnknownEvent
An unrecognized streaming event type.
UrlCitation
URL citation annotation.
Usage
Token usage statistics.
UserMessageContent
Content for a user message.
UserMessageItem
A user message item.
UserMessagePartsContent
List of input content parts for a user message.
UserMessageTextContent
Simple text content for a user message.

Enums

AbortionStage
Stage at which request was aborted.
FunctionCallStatus
The status of a function call output.
ImageDetail
Image detail level for multimodal inputs.
Include
Additional data to include in the response.
ItemStatus
The status of an item.
MessageRole
The role of a message in a conversation.
ReasoningEffort
Reasoning effort level for reasoning models.
ReasoningSummary
Reasoning summary verbosity level.
ResponseStatus
The status of a response.
ToolChoiceMode
Tool choice mode for allowed tools.
Truncation
Truncation strategy for long inputs.
Verbosity
Verbosity level for output.

Extensions

ResponseResourceExtensions on ResponseResource
Convenience extensions for ResponseResource.
StreamingEventExtensions on StreamingEvent
Convenience extensions for StreamingEvent.
StreamingEventsExtensions on Stream<StreamingEvent>
Convenience extensions for streaming responses.

Constants

unsetCopyWithValue → const Object
Sentinel value for copyWith to distinguish null from unset.

Functions

listHash<T>(List<T>? list) int
Content-based hash code for a nullable list.
listOfMapsDeepEqual(List<Map<String, dynamic>>? a, List<Map<String, dynamic>>? b) bool
Compares two lists of maps for deep equality (handles nested maps and lists).
listOfMapsEqual<K, V>(List<Map<K, V>>? a, List<Map<K, V>>? b) bool
Compares two lists of maps for shallow equality.
listOfMapsHash<K, V>(List<Map<K, V>>? list) int
Content-based hash code for a nullable list of maps.
listOfMapsHashCode(List<Map<String, dynamic>>? list) int
Computes a deep hash code for a list of maps.
listsEqual<T>(List<T>? a, List<T>? b) bool
Compares two lists for equality.
mapDeepHashCode(Map<String, dynamic>? map) int
Computes a deep hash code for a map (handles nested maps and lists).
mapHash<K, V>(Map<K, V>? map) int
Content-based hash code for a nullable map (order-independent).
mapsDeepEqual(Map<String, dynamic>? a, Map<String, dynamic>? b) bool
Compares two maps for deep equality (handles nested maps and lists).
mapsEqual<K, V>(Map<K, V>? a, Map<K, V>? b) bool
Compares two maps for equality.

Exceptions / Errors

AbortedException
Exception thrown when a request is aborted by user.
ApiException
Exception for HTTP/API errors.
AuthenticationException
Exception for authentication errors (HTTP 401).
OpenResponsesException
Base sealed class for all OpenResponses exceptions.
RateLimitException
Exception for rate limit (429) errors.
TimeoutException
Exception for request timeouts.
ValidationException
Exception for validation errors (HTTP 400).