OpenAiClient
The OpenAiClient module defines the low-level Effect service used by the
OpenAI integration for Responses API and embedding requests. It builds a
configured HTTP client with authentication and OpenAI organization or project
headers, exposes helpers for non-streaming responses, SSE response streams,
WebSocket response streams, and embeddings, and maps transport or decoding
failures into AiError.
Constructors
Creates an OpenAI client service with the given options.
When to use
Use when you need the OpenAI client service value inside an effect.
Details
The returned service uses the current HttpClient, prepends apiUrl or
https://api.openai.com/v1, adds the bearer token and optional OpenAI
organization/project headers, accepts JSON responses, filters for successful
HTTP statuses, and applies transformClient when provided.
Gotchas
A scoped OpenAiConfig.withClientTransform is applied when request helpers
run, after the transformClient option supplied to make.
See
- layer for providing this client from explicit options
- layerConfig for loading client settings from
Config
Signature
declare const make: (...args: [options: Options]) => EffectLayers
Creates a layer for the OpenAI client with the given options.
When to use
Use when you already have explicit Options values, such as an API key or
custom API URL, and want to provide OpenAiClient as a Layer.
See
- make for constructing the client service effectfully
- layerConfig for loading client settings from
Config
Signature
declare function layer(options: Options): Layer<OpenAiClient, never, HttpClient>layerConfig
Creates a layer for the OpenAI client from provided Config values.
When to use
Use when you need client settings for OpenAI-compatible APIs to be read from
Effect Config values while providing OpenAiClient as a Layer.
Details
Only config values supplied in options are loaded. Omitted fields are
passed to make as undefined, and transformClient is forwarded as a
plain option.
See
Signature
declare function layerConfig(options?: { readonly apiKey?: Config<Redacted<string> | undefined>; readonly apiUrl?: Config<string>; readonly organizationId?: Config<Redacted<string> | undefined>; readonly projectId?: Config<Redacted<string> | undefined>; readonly transformClient?: (client: HttpClient) => HttpClient;}): Layer<OpenAiClient, ConfigError, HttpClient>layerWebSocketMode
Uses OpenAI's websocket mode for all responses that use the Layer.
When to use
Use to provide WebSocket mode through layer composition for effects that use OpenAI response streaming.
Gotchas
This only works with the following WebSocket constructor layers:
NodeSocket.layerWebSocketConstructorWSBunSocket.layerWebSocketConstructor
These constructor layers support the non-standard options needed to set the Authorization header.
See
- withWebSocketMode for enabling WebSocket mode around a single effect
Signature
declare const layerWebSocketMode: Layer.Layer<OpenAiSocket | ResponseIdTracker.ResponseIdTracker, never, OpenAiClient | Socket.WebSocketConstructor>Models
ResponseStreamEvent type
Response stream event emitted by the OpenAI Responses API.
Signature
type ResponseStreamEvent = typeof OpenAiSchema.ResponseStreamEvent.TypeOptions
Options for configuring the OpenAI client.
Signature
type Options = { readonly apiKey?: Redacted.Redacted<string>; readonly apiUrl?: string; readonly organizationId?: Redacted.Redacted<string>; readonly projectId?: Redacted.Redacted<string>; readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient;}Providing Services
withWebSocketMode
Uses OpenAI's WebSocket mode for response streams within the provided effect.
When to use
Use to enable WebSocket mode around one effect that creates OpenAI response streams.
Gotchas
This only works with the following WebSocket constructor layers:
NodeSocket.layerWebSocketConstructorWSBunSocket.layerWebSocketConstructor
These constructor layers support the non-standard options needed to set the Authorization header.
See
- layerWebSocketMode for providing WebSocket mode through a layer
- OpenAiSocket for direct access to the WebSocket-backed streaming service
Signature
declare function withWebSocketMode<A, E, R>(effect: Effect<A, E, R>): Effect<A, E, OpenAiClient | Exclude<R, OpenAiSocket | ResponseIdTracker> | WebSocketConstructor>Services
OpenAiClient
Service tag for the OpenAI client.
When to use
Use when accessing or providing the OpenAI client service through Effect's context.
See
- make for constructing an OpenAI client effectfully
- layer for providing a client from explicit options
- layerConfig for providing a client from
Config
Signature
declare class OpenAiClient extends Shape<"@effect/ai-openai/OpenAiClient", Service, this> { constructor(_: never);}OpenAiSocket
Service for creating OpenAI response streams over a WebSocket connection.
When to use
Use when you need direct access to the WebSocket-backed response streaming service rather than wrapping an effect with WebSocket mode.
Details
createResponseStream sends a response.create message over the WebSocket
connection and returns an HTTP response together with a stream of
ResponseStreamEvent values.
Gotchas
WebSocket response streams are serialized to one request at a time by the shared socket service.
See
- withWebSocketMode for enabling WebSocket mode for one effect
- layerWebSocketMode for providing WebSocket mode through a layer
Signature
declare class OpenAiSocket extends Shape<"@effect/ai-openai/OpenAiClient/OpenAiSocket", { readonly createResponseStream: (options: Omit<typeof OpenAiSchema.CreateResponse.Encoded, "stream">) => Effect<readonly [HttpClientResponse, Stream<UnknownResponseStreamEvent | { readonly response: { readonly created_at: number; readonly error?: ... | ... | ...; readonly id: string; readonly incomplete_details?: ... | ... | ...; readonly model: string; readonly object?: ... | ...; readonly output: readonly Array<...>; readonly service_tier?: ... | ...; readonly usage?: ... | ... | ...; }; readonly sequence_number?: number; readonly type: "response.created"; } | { readonly response: { readonly created_at: number; readonly error?: ... | ... | ...; readonly id: string; readonly incomplete_details?: ... | ... | ...; readonly model: string; readonly object?: ... | ...; readonly output: readonly Array<...>; readonly service_tier?: ... | ...; readonly usage?: ... | ... | ...; }; readonly sequence_number?: number; readonly type: "response.completed"; } | { readonly response: { readonly created_at: number; readonly error?: ... | ... | ...; readonly id: string; readonly incomplete_details?: ... | ... | ...; readonly model: string; readonly object?: ... | ...; readonly output: readonly Array<...>; readonly service_tier?: ... | ...; readonly usage?: ... | ... | ...; }; readonly sequence_number?: number; readonly type: "response.incomplete"; } | { readonly response: { readonly created_at: number; readonly error?: ... | ... | ...; readonly id: string; readonly incomplete_details?: ... | ... | ...; readonly model: string; readonly object?: ... | ...; readonly output: readonly Array<...>; readonly service_tier?: ... | ...; readonly usage?: ... | ... | ...; }; readonly sequence_number?: number; readonly type: "response.failed"; } | { readonly item: { readonly call_id: ...; readonly id: ...; readonly operation: ...; readonly status?: ...; readonly type: ...; } | { readonly code?: ...; readonly container_id: ...; readonly id: ...; readonly outputs?: ...; readonly status?: ...; readonly type: ...; } | { readonly id: ...; readonly status?: ...; readonly type: ...; } | { readonly id: ...; readonly queries?: ...; readonly results?: ...; readonly status?: ...; readonly type: ...; } | { readonly arguments: ...; readonly call_id: ...; readonly id?: ...; readonly name: ...; readonly status?: ...; readonly type: ...; } | { readonly id: ...; readonly result?: ...; readonly status?: ...; readonly type: ...; } | { readonly action: ...; readonly call_id: ...; readonly id?: ...; readonly status?: ...; readonly type: ...; } | { readonly approval_request_id?: ...; readonly arguments: ...; readonly error?: ...; readonly id: ...; readonly name: ...; readonly output?: ...; readonly server_label?: ...; readonly type: ...; } | { readonly id: ...; readonly type: ...; } | { readonly approval_request_id?: ...; readonly arguments: ...; readonly id: ...; readonly name: ...; readonly type: ...; } | { readonly content: ...; readonly id: ...; readonly role: ...; readonly status: ...; readonly type: ...; } | { readonly content?: ...; readonly encrypted_content?: ...; readonly id: ...; readonly status?: ...; readonly summary: ...; readonly type: ...; } | { readonly action: ...; readonly call_id: ...; readonly id?: ...; readonly status?: ...; readonly type: ...; } | { readonly action?: ...; readonly id: ...; readonly status?: ...; readonly type: ...; }; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_item.added"; } | { readonly item: { readonly call_id: ...; readonly id: ...; readonly operation: ...; readonly status?: ...; readonly type: ...; } | { readonly code?: ...; readonly container_id: ...; readonly id: ...; readonly outputs?: ...; readonly status?: ...; readonly type: ...; } | { readonly id: ...; readonly status?: ...; readonly type: ...; } | { readonly id: ...; readonly queries?: ...; readonly results?: ...; readonly status?: ...; readonly type: ...; } | { readonly arguments: ...; readonly call_id: ...; readonly id?: ...; readonly name: ...; readonly status?: ...; readonly type: ...; } | { readonly id: ...; readonly result?: ...; readonly status?: ...; readonly type: ...; } | { readonly action: ...; readonly call_id: ...; readonly id?: ...; readonly status?: ...; readonly type: ...; } | { readonly approval_request_id?: ...; readonly arguments: ...; readonly error?: ...; readonly id: ...; readonly name: ...; readonly output?: ...; readonly server_label?: ...; readonly type: ...; } | { readonly id: ...; readonly type: ...; } | { readonly approval_request_id?: ...; readonly arguments: ...; readonly id: ...; readonly name: ...; readonly type: ...; } | { readonly content: ...; readonly id: ...; readonly role: ...; readonly status: ...; readonly type: ...; } | { readonly content?: ...; readonly encrypted_content?: ...; readonly id: ...; readonly status?: ...; readonly summary: ...; readonly type: ...; } | { readonly action: ...; readonly call_id: ...; readonly id?: ...; readonly status?: ...; readonly type: ...; } | { readonly action?: ...; readonly id: ...; readonly status?: ...; readonly type: ...; }; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_item.done"; } | { readonly content_index: number; readonly delta: string; readonly item_id: string; readonly logprobs?: readonly Array<...>; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_text.delta"; } | { readonly annotation: { readonly file_id: ...; readonly filename: ...; readonly index: ...; readonly type: ...; } | { readonly end_index: ...; readonly start_index: ...; readonly title: ...; readonly type: ...; readonly url: ...; } | { readonly container_id: ...; readonly end_index: ...; readonly file_id: ...; readonly filename: ...; readonly start_index: ...; readonly type: ...; } | { readonly file_id: ...; readonly index: ...; readonly type: ...; }; readonly annotation_index: number; readonly content_index: number; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_text.annotation.added"; } | { readonly item_id: string; readonly output_index: number; readonly part: { readonly text: string; readonly type: "summary_text"; }; readonly sequence_number?: number; readonly summary_index: number; readonly type: "response.reasoning_summary_part.added"; } | { readonly item_id: string; readonly output_index: number; readonly part: { readonly text: string; readonly type: "summary_text"; }; readonly sequence_number?: number; readonly summary_index: number; readonly type: "response.reasoning_summary_part.done"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly summary_index: number; readonly type: "response.reasoning_summary_text.delta"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.function_call_arguments.delta"; } | { readonly arguments: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.function_call_arguments.done"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.code_interpreter_call_code.delta"; } | { readonly code: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.code_interpreter_call_code.done"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.apply_patch_call_operation_diff.delta"; } | { readonly delta?: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.apply_patch_call_operation_diff.done"; } | { readonly item_id: string; readonly output_index: number; readonly partial_image_b64: string; readonly sequence_number?: number; readonly type: "response.image_generation_call.partial_image"; } | { readonly code: string | null; readonly message: string; readonly param: string | null; readonly sequence_number?: number; readonly status?: number; readonly type: "error"; }, AiError, never>], AiError>;}, this> { constructor(_: never);}Effect service interface for the handwritten OpenAI client.
Details
Provides the configured HTTP client plus helpers for Responses API calls, streaming Responses events, and embeddings. Transport and schema decoding failures are mapped to AiError.
Signature
interface Service { readonly client: HttpClient; readonly createEmbedding: (options: { readonly dimensions?: number; readonly encoding_format?: "float" | "base64"; readonly input: string | readonly Array<string> | readonly Array<number> | readonly Array<readonly Array<number>>; readonly model: string; readonly user?: string; }) => Effect<{ readonly data: readonly Array<{ readonly embedding: string | readonly Array<number>; readonly index: number; readonly object?: string; }>; readonly model: string; readonly object?: "list"; readonly usage?: { readonly prompt_tokens: number; readonly total_tokens: number; }; }, AiError>; readonly createResponse: (options: { readonly background?: boolean; readonly conversation?: string; readonly include?: readonly Array<"message.input_image.image_url" | "reasoning.encrypted_content" | "message.output_text.logprobs" | "code_interpreter_call.outputs" | "web_search_call.action.sources">; readonly input?: string | readonly Array<{ readonly arguments: string; readonly call_id: string; readonly id?: string; readonly name: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "function_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "local_shell_call"; } | { readonly content: readonly Array<{ readonly prompt_cache_breakpoint?: { readonly mode: ...; }; readonly text: string; readonly type: "input_text"; } | { readonly annotations: readonly Array<... | ... | ... | ...>; readonly logprobs?: readonly Array<...>; readonly text: string; readonly type: "output_text"; } | { readonly text: string; readonly type: "text"; } | { readonly text: string; readonly type: "summary_text"; } | { readonly text: string; readonly type: "reasoning_text"; } | { readonly refusal: string; readonly type: "refusal"; } | { readonly detail?: "low" | "high" | "auto" | null; readonly file_id?: string | null; readonly image_url?: string | null; readonly type: "input_image"; } | { readonly file_id: string | null; readonly image_url: string | null; readonly type: "computer_screenshot"; } | { readonly file_data?: string; readonly file_id?: string | null; readonly file_url?: string; readonly filename?: string; readonly type: "input_file"; }>; readonly id: string; readonly role: "assistant"; readonly status: "in_progress" | "completed" | "incomplete"; readonly type: "message"; } | { readonly content?: readonly Array<{ readonly text: string; readonly type: "reasoning_text"; }>; readonly encrypted_content?: string | null; readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly summary: readonly Array<{ readonly text: string; readonly type: "summary_text"; }>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "shell_call"; } | { readonly content: string | readonly Array<{ readonly prompt_cache_breakpoint?: ... | ...; readonly text: string; readonly type: "input_text"; } | { readonly detail?: ... | ... | ... | ... | ...; readonly file_id?: ... | ... | ...; readonly image_url?: ... | ... | ...; readonly type: "input_image"; } | { readonly file_data?: ... | ...; readonly file_id?: ... | ... | ...; readonly file_url?: ... | ...; readonly filename?: ... | ...; readonly type: "input_file"; }>; readonly role: "user" | "system" | "developer" | "assistant"; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type?: "message"; } | { readonly call_id: string; readonly id?: string | null; readonly output: string | readonly Array<{ readonly prompt_cache_breakpoint?: ... | ...; readonly text: string; readonly type: "input_text"; } | { readonly detail?: ... | ... | ... | ... | ...; readonly file_id?: ... | ... | ...; readonly image_url?: ... | ... | ...; readonly type: "input_image"; } | { readonly file_data?: ... | ...; readonly file_id?: ... | ... | ...; readonly file_url?: ... | ...; readonly filename?: ... | ...; readonly type: "input_file"; }>; readonly status?: "in_progress" | "completed" | "incomplete" | null; readonly type: "function_call_output"; } | { readonly id: string; readonly type: "item_reference"; } | { readonly call_id: string; readonly id?: string; readonly output: unknown; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "local_shell_call_output"; } | { readonly call_id: string; readonly id?: string; readonly output: unknown; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "shell_call_output"; } | { readonly call_id: string; readonly id?: string; readonly output?: unknown; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "apply_patch_call_output"; } | { readonly approval_request_id: string; readonly approve: boolean; readonly type: "mcp_approval_response"; }>; readonly instructions?: string; readonly max_output_tokens?: number; readonly max_tool_calls?: number; readonly metadata?: { [key: string]: string; }; readonly modalities?: readonly Array<"text" | "audio">; readonly model?: string; readonly previous_response_id?: string; readonly prompt_cache_key?: string; readonly prompt_cache_options?: { readonly mode?: "implicit" | "explicit"; readonly ttl?: "30m"; }; readonly reasoning?: { readonly effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"; readonly generate_summary?: "auto" | "concise" | "detailed"; readonly summary?: "auto" | "concise" | "detailed"; }; readonly seed?: number; readonly service_tier?: string; readonly store?: boolean; readonly stream?: boolean; readonly temperature?: number; readonly text?: { readonly format?: { readonly type: "text"; } | { readonly description?: string; readonly name: string; readonly schema: { [key: string]: unknown; }; readonly strict?: boolean | null; readonly type: "json_schema"; } | { readonly type: "json_object"; }; readonly verbosity?: "low" | "medium" | "high"; }; readonly tool_choice?: "required" | "none" | "auto" | { readonly mode: "required" | "auto"; readonly tools: readonly Array<{ [key: string]: unknown; }>; readonly type: "allowed_tools"; } | { readonly name: string; readonly type: "function"; } | { readonly name: string; readonly type: "custom"; } | { [key: string]: unknown; readonly type: "apply_patch" | "code_interpreter" | "file_search" | "image_generation" | "local_shell" | "mcp" | "shell" | "web_search" | "web_search_preview"; }; readonly tools?: readonly Array<{ readonly description?: string | null; readonly name: string; readonly parameters?: { [key: string]: unknown; } | null; readonly strict?: boolean | null; readonly type: "function"; } | { readonly description?: string; readonly format?: unknown; readonly name: string; readonly type: "custom"; } | { [key: string]: unknown; readonly type: "apply_patch" | "code_interpreter" | "file_search" | "image_generation" | "local_shell" | "mcp" | "shell" | "web_search" | "web_search_preview"; }>; readonly top_logprobs?: number; readonly top_p?: number; readonly truncation?: "auto" | "disabled"; readonly user?: string; }) => Effect<readonly [{ readonly created_at: number; readonly error?: { readonly code: string; readonly message: string; } | null; readonly id: string; readonly incomplete_details?: { readonly reason?: "max_output_tokens" | "content_filter"; } | null; readonly model: string; readonly object?: "response"; readonly output: readonly Array<{ readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: string; readonly path: string; readonly type: string; }; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "apply_patch_call"; } | { readonly code?: string | null; readonly container_id: string; readonly id: string; readonly outputs?: readonly Array<unknown> | null; readonly status?: "in_progress" | "completed" | "incomplete" | "interpreting" | "failed"; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: readonly Array<string>; readonly results?: unknown; readonly status?: string; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: string; readonly name: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "function_call"; } | { readonly id: string; readonly result?: string | null; readonly status?: "in_progress" | "completed" | "failed" | "generating"; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "local_shell_call"; } | { readonly approval_request_id?: string | null; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: string | null; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: string; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<{ readonly prompt_cache_breakpoint?: ... | ...; readonly text: string; readonly type: "input_text"; } | { readonly annotations: readonly Array<...>; readonly logprobs?: ... | ...; readonly text: string; readonly type: "output_text"; } | { readonly text: string; readonly type: "text"; } | { readonly text: string; readonly type: "summary_text"; } | { readonly text: string; readonly type: "reasoning_text"; } | { readonly refusal: string; readonly type: "refusal"; } | { readonly detail?: ... | ... | ... | ... | ...; readonly file_id?: ... | ... | ...; readonly image_url?: ... | ... | ...; readonly type: "input_image"; } | { readonly file_id: ... | ...; readonly image_url: ... | ...; readonly type: "computer_screenshot"; } | { readonly file_data?: ... | ...; readonly file_id?: ... | ... | ...; readonly file_url?: ... | ...; readonly filename?: ... | ...; readonly type: "input_file"; }>; readonly id: string; readonly role: "assistant"; readonly status: "in_progress" | "completed" | "incomplete"; readonly type: "message"; } | { readonly content?: readonly Array<{ readonly text: string; readonly type: "reasoning_text"; }>; readonly encrypted_content?: string | null; readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly summary: readonly Array<{ readonly text: string; readonly type: "summary_text"; }>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: string; readonly type: "web_search_call"; }>; readonly service_tier?: string; readonly usage?: { [key: string]: unknown; readonly input_tokens: number; readonly input_tokens_details?: unknown; readonly output_tokens: number; readonly output_tokens_details?: unknown; readonly total_tokens: number; } | null; }, HttpClientResponse], AiError>; readonly createResponseStream: (options: Omit<typeof OpenAiSchema.CreateResponse.Encoded, "stream">) => Effect<readonly [HttpClientResponse, Stream<UnknownResponseStreamEvent | { readonly response: { readonly created_at: number; readonly error?: { readonly code: string; readonly message: string; } | null; readonly id: string; readonly incomplete_details?: { readonly reason?: "max_output_tokens" | "content_filter"; } | null; readonly model: string; readonly object?: "response"; readonly output: readonly Array<{ readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: ...; readonly path: ...; readonly type: ...; }; readonly status?: ... | ... | ... | ...; readonly type: "apply_patch_call"; } | { readonly code?: ... | ... | ...; readonly container_id: string; readonly id: string; readonly outputs?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ... | ...; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: ... | ... | ... | ...; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: ... | ...; readonly results?: unknown; readonly status?: ... | ...; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: ... | ...; readonly name: string; readonly status?: ... | ... | ... | ...; readonly type: "function_call"; } | { readonly id: string; readonly result?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ...; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "local_shell_call"; } | { readonly approval_request_id?: ... | ... | ...; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: ... | ... | ...; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: ... | ...; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<...>; readonly id: string; readonly role: "assistant"; readonly status: ... | ... | ...; readonly type: "message"; } | { readonly content?: ... | ...; readonly encrypted_content?: ... | ... | ...; readonly id: string; readonly status?: ... | ... | ... | ...; readonly summary: readonly Array<...>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: ... | ...; readonly type: "web_search_call"; }>; readonly service_tier?: string; readonly usage?: { [key: string]: unknown; readonly input_tokens: number; readonly input_tokens_details?: unknown; readonly output_tokens: number; readonly output_tokens_details?: unknown; readonly total_tokens: number; } | null; }; readonly sequence_number?: number; readonly type: "response.created"; } | { readonly response: { readonly created_at: number; readonly error?: { readonly code: string; readonly message: string; } | null; readonly id: string; readonly incomplete_details?: { readonly reason?: "max_output_tokens" | "content_filter"; } | null; readonly model: string; readonly object?: "response"; readonly output: readonly Array<{ readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: ...; readonly path: ...; readonly type: ...; }; readonly status?: ... | ... | ... | ...; readonly type: "apply_patch_call"; } | { readonly code?: ... | ... | ...; readonly container_id: string; readonly id: string; readonly outputs?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ... | ...; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: ... | ... | ... | ...; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: ... | ...; readonly results?: unknown; readonly status?: ... | ...; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: ... | ...; readonly name: string; readonly status?: ... | ... | ... | ...; readonly type: "function_call"; } | { readonly id: string; readonly result?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ...; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "local_shell_call"; } | { readonly approval_request_id?: ... | ... | ...; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: ... | ... | ...; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: ... | ...; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<...>; readonly id: string; readonly role: "assistant"; readonly status: ... | ... | ...; readonly type: "message"; } | { readonly content?: ... | ...; readonly encrypted_content?: ... | ... | ...; readonly id: string; readonly status?: ... | ... | ... | ...; readonly summary: readonly Array<...>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: ... | ...; readonly type: "web_search_call"; }>; readonly service_tier?: string; readonly usage?: { [key: string]: unknown; readonly input_tokens: number; readonly input_tokens_details?: unknown; readonly output_tokens: number; readonly output_tokens_details?: unknown; readonly total_tokens: number; } | null; }; readonly sequence_number?: number; readonly type: "response.completed"; } | { readonly response: { readonly created_at: number; readonly error?: { readonly code: string; readonly message: string; } | null; readonly id: string; readonly incomplete_details?: { readonly reason?: "max_output_tokens" | "content_filter"; } | null; readonly model: string; readonly object?: "response"; readonly output: readonly Array<{ readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: ...; readonly path: ...; readonly type: ...; }; readonly status?: ... | ... | ... | ...; readonly type: "apply_patch_call"; } | { readonly code?: ... | ... | ...; readonly container_id: string; readonly id: string; readonly outputs?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ... | ...; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: ... | ... | ... | ...; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: ... | ...; readonly results?: unknown; readonly status?: ... | ...; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: ... | ...; readonly name: string; readonly status?: ... | ... | ... | ...; readonly type: "function_call"; } | { readonly id: string; readonly result?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ...; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "local_shell_call"; } | { readonly approval_request_id?: ... | ... | ...; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: ... | ... | ...; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: ... | ...; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<...>; readonly id: string; readonly role: "assistant"; readonly status: ... | ... | ...; readonly type: "message"; } | { readonly content?: ... | ...; readonly encrypted_content?: ... | ... | ...; readonly id: string; readonly status?: ... | ... | ... | ...; readonly summary: readonly Array<...>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: ... | ...; readonly type: "web_search_call"; }>; readonly service_tier?: string; readonly usage?: { [key: string]: unknown; readonly input_tokens: number; readonly input_tokens_details?: unknown; readonly output_tokens: number; readonly output_tokens_details?: unknown; readonly total_tokens: number; } | null; }; readonly sequence_number?: number; readonly type: "response.incomplete"; } | { readonly response: { readonly created_at: number; readonly error?: { readonly code: string; readonly message: string; } | null; readonly id: string; readonly incomplete_details?: { readonly reason?: "max_output_tokens" | "content_filter"; } | null; readonly model: string; readonly object?: "response"; readonly output: readonly Array<{ readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: ...; readonly path: ...; readonly type: ...; }; readonly status?: ... | ... | ... | ...; readonly type: "apply_patch_call"; } | { readonly code?: ... | ... | ...; readonly container_id: string; readonly id: string; readonly outputs?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ... | ...; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: ... | ... | ... | ...; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: ... | ...; readonly results?: unknown; readonly status?: ... | ...; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: ... | ...; readonly name: string; readonly status?: ... | ... | ... | ...; readonly type: "function_call"; } | { readonly id: string; readonly result?: ... | ... | ...; readonly status?: ... | ... | ... | ... | ...; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "local_shell_call"; } | { readonly approval_request_id?: ... | ... | ...; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: ... | ... | ...; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: ... | ...; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<...>; readonly id: string; readonly role: "assistant"; readonly status: ... | ... | ...; readonly type: "message"; } | { readonly content?: ... | ...; readonly encrypted_content?: ... | ... | ...; readonly id: string; readonly status?: ... | ... | ... | ...; readonly summary: readonly Array<...>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: ... | ...; readonly status?: ... | ... | ... | ...; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: ... | ...; readonly type: "web_search_call"; }>; readonly service_tier?: string; readonly usage?: { [key: string]: unknown; readonly input_tokens: number; readonly input_tokens_details?: unknown; readonly output_tokens: number; readonly output_tokens_details?: unknown; readonly total_tokens: number; } | null; }; readonly sequence_number?: number; readonly type: "response.failed"; } | { readonly item: { readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: string; readonly path: string; readonly type: string; }; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "apply_patch_call"; } | { readonly code?: string | null; readonly container_id: string; readonly id: string; readonly outputs?: readonly Array<unknown> | null; readonly status?: "in_progress" | "completed" | "incomplete" | "interpreting" | "failed"; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: readonly Array<string>; readonly results?: unknown; readonly status?: string; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: string; readonly name: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "function_call"; } | { readonly id: string; readonly result?: string | null; readonly status?: "in_progress" | "completed" | "failed" | "generating"; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "local_shell_call"; } | { readonly approval_request_id?: string | null; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: string | null; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: string; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<{ readonly prompt_cache_breakpoint?: ...; readonly text: ...; readonly type: ...; } | { readonly annotations: ...; readonly logprobs?: ...; readonly text: ...; readonly type: ...; } | { readonly text: ...; readonly type: ...; } | { readonly text: ...; readonly type: ...; } | { readonly text: ...; readonly type: ...; } | { readonly refusal: ...; readonly type: ...; } | { readonly detail?: ...; readonly file_id?: ...; readonly image_url?: ...; readonly type: ...; } | { readonly file_id: ...; readonly image_url: ...; readonly type: ...; } | { readonly file_data?: ...; readonly file_id?: ...; readonly file_url?: ...; readonly filename?: ...; readonly type: ...; }>; readonly id: string; readonly role: "assistant"; readonly status: "in_progress" | "completed" | "incomplete"; readonly type: "message"; } | { readonly content?: readonly Array<{ readonly text: ...; readonly type: ...; }>; readonly encrypted_content?: string | null; readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly summary: readonly Array<{ readonly text: string; readonly type: "summary_text"; }>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: string; readonly type: "web_search_call"; }; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_item.added"; } | { readonly item: { readonly call_id: string; readonly id: string; readonly operation: { readonly diff?: string; readonly path: string; readonly type: string; }; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "apply_patch_call"; } | { readonly code?: string | null; readonly container_id: string; readonly id: string; readonly outputs?: readonly Array<unknown> | null; readonly status?: "in_progress" | "completed" | "incomplete" | "interpreting" | "failed"; readonly type: "code_interpreter_call"; } | { readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "computer_call"; } | { readonly id: string; readonly queries?: readonly Array<string>; readonly results?: unknown; readonly status?: string; readonly type: "file_search_call"; } | { readonly arguments: string; readonly call_id: string; readonly id?: string; readonly name: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "function_call"; } | { readonly id: string; readonly result?: string | null; readonly status?: "in_progress" | "completed" | "failed" | "generating"; readonly type: "image_generation_call"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "local_shell_call"; } | { readonly approval_request_id?: string | null; readonly arguments: unknown; readonly error?: unknown; readonly id: string; readonly name: string; readonly output?: unknown; readonly server_label?: string | null; readonly type: "mcp_call"; } | { readonly id: string; readonly type: "mcp_list_tools"; } | { readonly approval_request_id?: string; readonly arguments: unknown; readonly id: string; readonly name: string; readonly type: "mcp_approval_request"; } | { readonly content: readonly Array<{ readonly prompt_cache_breakpoint?: ...; readonly text: ...; readonly type: ...; } | { readonly annotations: ...; readonly logprobs?: ...; readonly text: ...; readonly type: ...; } | { readonly text: ...; readonly type: ...; } | { readonly text: ...; readonly type: ...; } | { readonly text: ...; readonly type: ...; } | { readonly refusal: ...; readonly type: ...; } | { readonly detail?: ...; readonly file_id?: ...; readonly image_url?: ...; readonly type: ...; } | { readonly file_id: ...; readonly image_url: ...; readonly type: ...; } | { readonly file_data?: ...; readonly file_id?: ...; readonly file_url?: ...; readonly filename?: ...; readonly type: ...; }>; readonly id: string; readonly role: "assistant"; readonly status: "in_progress" | "completed" | "incomplete"; readonly type: "message"; } | { readonly content?: readonly Array<{ readonly text: ...; readonly type: ...; }>; readonly encrypted_content?: string | null; readonly id: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly summary: readonly Array<{ readonly text: string; readonly type: "summary_text"; }>; readonly type: "reasoning"; } | { readonly action: unknown; readonly call_id: string; readonly id?: string; readonly status?: "in_progress" | "completed" | "incomplete"; readonly type: "shell_call"; } | { readonly action?: unknown; readonly id: string; readonly status?: string; readonly type: "web_search_call"; }; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_item.done"; } | { readonly content_index: number; readonly delta: string; readonly item_id: string; readonly logprobs?: readonly Array<unknown>; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_text.delta"; } | { readonly annotation: { readonly file_id: string; readonly filename: string; readonly index: number; readonly type: "file_citation"; } | { readonly end_index: number; readonly start_index: number; readonly title: string; readonly type: "url_citation"; readonly url: string; } | { readonly container_id: string; readonly end_index: number; readonly file_id: string; readonly filename: string; readonly start_index: number; readonly type: "container_file_citation"; } | { readonly file_id: string; readonly index: number; readonly type: "file_path"; }; readonly annotation_index: number; readonly content_index: number; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.output_text.annotation.added"; } | { readonly item_id: string; readonly output_index: number; readonly part: { readonly text: string; readonly type: "summary_text"; }; readonly sequence_number?: number; readonly summary_index: number; readonly type: "response.reasoning_summary_part.added"; } | { readonly item_id: string; readonly output_index: number; readonly part: { readonly text: string; readonly type: "summary_text"; }; readonly sequence_number?: number; readonly summary_index: number; readonly type: "response.reasoning_summary_part.done"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly summary_index: number; readonly type: "response.reasoning_summary_text.delta"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.function_call_arguments.delta"; } | { readonly arguments: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.function_call_arguments.done"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.code_interpreter_call_code.delta"; } | { readonly code: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.code_interpreter_call_code.done"; } | { readonly delta: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.apply_patch_call_operation_diff.delta"; } | { readonly delta?: string; readonly item_id: string; readonly output_index: number; readonly sequence_number?: number; readonly type: "response.apply_patch_call_operation_diff.done"; } | { readonly item_id: string; readonly output_index: number; readonly partial_image_b64: string; readonly sequence_number?: number; readonly type: "response.image_generation_call.partial_image"; } | { readonly code: string | null; readonly message: string; readonly param: string | null; readonly sequence_number?: number; readonly status?: number; readonly type: "error"; }, AiError, never>], AiError>;}