Skip to content

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.

10 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

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]) => Effect;

Layers

layer

Added in v4.0.0 Source

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

Added in v4.0.0 Source

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

  • make for constructing the client service effectfully
  • layer for providing the client from already-resolved options

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>;

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.layerWebSocketConstructorWS - BunSocket.layerWebSocketConstructor

These constructor layers support the non-standard options needed to set the Authorization header.

See

Signature

declare const layerWebSocketMode: Layer.Layer<
  OpenAiSocket | ResponseIdTracker.ResponseIdTracker,
  never,
  OpenAiClient | Socket.WebSocketConstructor
>;

Models

ResponseStreamEvent type

Added in v4.0.0 Source

Response stream event emitted by the OpenAI Responses API.

Signature

type ResponseStreamEvent = typeof OpenAiSchema.ResponseStreamEvent.Type;

Options

Options type

Added in v4.0.0 Source

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

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.layerWebSocketConstructorWS - BunSocket.layerWebSocketConstructor

These constructor layers support the non-standard options needed to set the Authorization header.

See

Signature

declare function withWebSocketMode<A, E, R>(
  effect: Effect<A, E, R>,
): Effect<A, E, OpenAiClient | Exclude<R, OpenAiSocket | ResponseIdTracker> | WebSocketConstructor>;

Services

OpenAiClient

Added in v4.0.0 Source

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

Added in v4.0.0 Source

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

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 | ReadonlySide<{
    readonly response: Struct<...>;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly response: Struct<...>;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly response: Struct<...>;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly response: Struct<...>;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly item: Union<...>;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly item: Union<...>;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | {
    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";
  } | ReadonlySide<{
    readonly annotation: Union<...>;
    readonly annotation_index: Int;
    readonly content_index: Int;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly item_id: String;
    readonly output_index: Int;
    readonly part: Struct<...>;
    readonly sequence_number: Int;
    readonly summary_index: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly item_id: String;
    readonly output_index: Int;
    readonly part: Struct<...>;
    readonly sequence_number: Int;
    readonly summary_index: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly summary_index: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly arguments: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly code: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | {
    readonly delta?: string;
    readonly item_id: string;
    readonly output_index: number;
    readonly sequence_number: number;
    readonly type: "response.apply_patch_call_operation_diff.done";
  } | ReadonlySide<{
    readonly item_id: String;
    readonly output_index: Int;
    readonly partial_image_b64: String;
    readonly sequence_number: Int;
    readonly type: Literal<...>;
  }, "Type"> | {
    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);
}

Service interface

Added in v4.0.0 Source

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?: ReadonlySide<{
      readonly prompt_tokens: Int;
      readonly total_tokens: Int;
    }, "Type">;
  }, 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";
    } | ReadonlySide<{
      readonly content: $Array<Union<readonly [Struct<...>, Struct<...>, Struct<...>, Struct<...>, Struct<...>, Struct<...>, Struct<...>, Struct<...>, Struct<...>]>>;
      readonly id: String;
      readonly role: Literal<"assistant">;
      readonly status: Literals<readonly ["in_progress", "completed", "incomplete"]>;
      readonly type: Literal<"message">;
    }, "Encoded"> | {
      readonly content?: readonly Array<ReadonlySide<{
        readonly text: String;
        readonly type: Literal<...>;
      }, "Encoded">>;
      readonly encrypted_content?: string | null;
      readonly id: string;
      readonly status?: "in_progress" | "completed" | "incomplete";
      readonly summary: readonly Array<ReadonlySide<{
        readonly text: String;
        readonly type: Literal<"summary_text">;
      }, "Encoded">>;
      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<ReadonlySide<{
        readonly text: ...;
        readonly type: ...;
      }, "Encoded"> | {
        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<ReadonlySide<{
        readonly text: ...;
        readonly type: ...;
      }, "Encoded"> | {
        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";
    } | ReadonlySide<{
      readonly id: String;
      readonly type: Literal<"item_reference">;
    }, "Encoded"> | {
      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";
    } | ReadonlySide<{
      readonly approval_request_id: String;
      readonly approve: Boolean;
      readonly type: Literal<"mcp_approval_response">;
    }, "Encoded">>;
    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 reasoning?: {
      readonly effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
      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?: ReadonlySide<{
        readonly type: Literal<"text">;
      }, "Encoded"> | {
        readonly description?: string;
        readonly name: string;
        readonly schema: {
          [key: string]: unknown;
        };
        readonly strict?: boolean | null;
        readonly type: "json_schema";
      } | ReadonlySide<{
        readonly type: Literal<"json_object">;
      }, "Encoded">;
      readonly verbosity?: "low" | "medium" | "high";
    };
    readonly tool_choice?: "required" | "none" | "auto" | ReadonlySide<{
      readonly mode: Literals<readonly ["auto", "required"]>;
      readonly tools: $Array<$Record<String, Unknown>>;
      readonly type: Literal<"allowed_tools">;
    }, "Encoded"> | ReadonlySide<{
      readonly name: String;
      readonly type: Literal<"function">;
    }, "Encoded"> | ReadonlySide<{
      readonly name: String;
      readonly type: Literal<"custom">;
    }, "Encoded"> | {
      [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?: ReadonlySide<{
      readonly code: String;
      readonly message: String;
    }, "Type"> | 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;
      readonly container_id: string;
      readonly id: string;
      readonly outputs?: readonly Array<unknown>;
      readonly status?: "in_progress" | "completed" | "incomplete";
      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" | "generating" | "failed";
      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";
    } | ReadonlySide<{
      readonly id: String;
      readonly type: Literal<"mcp_list_tools">;
    }, "Type"> | {
      readonly approval_request_id?: string;
      readonly arguments: unknown;
      readonly id: string;
      readonly name: string;
      readonly type: "mcp_approval_request";
    } | ReadonlySide<{
      readonly content: $Array<Union<readonly [..., ..., ..., ..., ..., ..., ..., ..., ...]>>;
      readonly id: String;
      readonly role: Literal<"assistant">;
      readonly status: Literals<readonly ["in_progress", "completed", "incomplete"]>;
      readonly type: Literal<"message">;
    }, "Type"> | {
      readonly content?: readonly Array<ReadonlySide<{
        readonly text: ...;
        readonly type: ...;
      }, "Type">>;
      readonly encrypted_content?: string | null;
      readonly id: string;
      readonly status?: "in_progress" | "completed" | "incomplete";
      readonly summary: readonly Array<ReadonlySide<{
        readonly text: String;
        readonly type: Literal<...>;
      }, "Type">>;
      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 | ReadonlySide<{
    readonly response: Struct<{
      readonly created_at: Int;
      readonly error: optionalKey<NullOr<...>>;
      readonly id: String;
      readonly incomplete_details: optionalKey<NullOr<...>>;
      readonly model: String;
      readonly object: optionalKey<Literal<...>>;
      readonly output: withDecodingDefault<$Array<...>, never>;
      readonly service_tier: optionalKey<String>;
      readonly usage: optionalKey<NullOr<...>>;
    }>;
    readonly sequence_number: Int;
    readonly type: Literal<"response.created">;
  }, "Type"> | ReadonlySide<{
    readonly response: Struct<{
      readonly created_at: Int;
      readonly error: optionalKey<NullOr<...>>;
      readonly id: String;
      readonly incomplete_details: optionalKey<NullOr<...>>;
      readonly model: String;
      readonly object: optionalKey<Literal<...>>;
      readonly output: withDecodingDefault<$Array<...>, never>;
      readonly service_tier: optionalKey<String>;
      readonly usage: optionalKey<NullOr<...>>;
    }>;
    readonly sequence_number: Int;
    readonly type: Literal<"response.completed">;
  }, "Type"> | ReadonlySide<{
    readonly response: Struct<{
      readonly created_at: Int;
      readonly error: optionalKey<NullOr<...>>;
      readonly id: String;
      readonly incomplete_details: optionalKey<NullOr<...>>;
      readonly model: String;
      readonly object: optionalKey<Literal<...>>;
      readonly output: withDecodingDefault<$Array<...>, never>;
      readonly service_tier: optionalKey<String>;
      readonly usage: optionalKey<NullOr<...>>;
    }>;
    readonly sequence_number: Int;
    readonly type: Literal<"response.incomplete">;
  }, "Type"> | ReadonlySide<{
    readonly response: Struct<{
      readonly created_at: Int;
      readonly error: optionalKey<NullOr<...>>;
      readonly id: String;
      readonly incomplete_details: optionalKey<NullOr<...>>;
      readonly model: String;
      readonly object: optionalKey<Literal<...>>;
      readonly output: withDecodingDefault<$Array<...>, never>;
      readonly service_tier: optionalKey<String>;
      readonly usage: optionalKey<NullOr<...>>;
    }>;
    readonly sequence_number: Int;
    readonly type: Literal<"response.failed">;
  }, "Type"> | ReadonlySide<{
    readonly item: Union<readonly [Struct<{
      readonly call_id: ...;
      readonly id: ...;
      readonly operation: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly code: ...;
      readonly container_id: ...;
      readonly id: ...;
      readonly outputs: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly queries: ...;
      readonly results: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly arguments: ...;
      readonly call_id: ...;
      readonly id: ...;
      readonly name: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly result: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly action: ...;
      readonly call_id: ...;
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly approval_request_id: ...;
      readonly arguments: ...;
      readonly error: ...;
      readonly id: ...;
      readonly name: ...;
      readonly output: ...;
      readonly server_label: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly type: ...;
    }>, Struct<{
      readonly approval_request_id: ...;
      readonly arguments: ...;
      readonly id: ...;
      readonly name: ...;
      readonly type: ...;
    }>, Struct<{
      readonly content: ...;
      readonly id: ...;
      readonly role: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly content: ...;
      readonly encrypted_content: ...;
      readonly id: ...;
      readonly status: ...;
      readonly summary: ...;
      readonly type: ...;
    }>, Struct<{
      readonly action: ...;
      readonly call_id: ...;
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly action: ...;
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>]>;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.output_item.added">;
  }, "Type"> | ReadonlySide<{
    readonly item: Union<readonly [Struct<{
      readonly call_id: ...;
      readonly id: ...;
      readonly operation: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly code: ...;
      readonly container_id: ...;
      readonly id: ...;
      readonly outputs: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly queries: ...;
      readonly results: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly arguments: ...;
      readonly call_id: ...;
      readonly id: ...;
      readonly name: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly result: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly action: ...;
      readonly call_id: ...;
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly approval_request_id: ...;
      readonly arguments: ...;
      readonly error: ...;
      readonly id: ...;
      readonly name: ...;
      readonly output: ...;
      readonly server_label: ...;
      readonly type: ...;
    }>, Struct<{
      readonly id: ...;
      readonly type: ...;
    }>, Struct<{
      readonly approval_request_id: ...;
      readonly arguments: ...;
      readonly id: ...;
      readonly name: ...;
      readonly type: ...;
    }>, Struct<{
      readonly content: ...;
      readonly id: ...;
      readonly role: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly content: ...;
      readonly encrypted_content: ...;
      readonly id: ...;
      readonly status: ...;
      readonly summary: ...;
      readonly type: ...;
    }>, Struct<{
      readonly action: ...;
      readonly call_id: ...;
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>, Struct<{
      readonly action: ...;
      readonly id: ...;
      readonly status: ...;
      readonly type: ...;
    }>]>;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.output_item.done">;
  }, "Type"> | {
    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";
  } | ReadonlySide<{
    readonly annotation: Union<readonly [Struct<{
      readonly file_id: ...;
      readonly filename: ...;
      readonly index: ...;
      readonly type: ...;
    }>, Struct<{
      readonly end_index: ...;
      readonly start_index: ...;
      readonly title: ...;
      readonly type: ...;
      readonly url: ...;
    }>, Struct<{
      readonly container_id: ...;
      readonly end_index: ...;
      readonly file_id: ...;
      readonly filename: ...;
      readonly start_index: ...;
      readonly type: ...;
    }>, Struct<{
      readonly file_id: ...;
      readonly index: ...;
      readonly type: ...;
    }>]>;
    readonly annotation_index: Int;
    readonly content_index: Int;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.output_text.annotation.added">;
  }, "Type"> | ReadonlySide<{
    readonly item_id: String;
    readonly output_index: Int;
    readonly part: Struct<{
      readonly text: String;
      readonly type: Literal<"summary_text">;
    }>;
    readonly sequence_number: Int;
    readonly summary_index: Int;
    readonly type: Literal<"response.reasoning_summary_part.added">;
  }, "Type"> | ReadonlySide<{
    readonly item_id: String;
    readonly output_index: Int;
    readonly part: Struct<{
      readonly text: String;
      readonly type: Literal<"summary_text">;
    }>;
    readonly sequence_number: Int;
    readonly summary_index: Int;
    readonly type: Literal<"response.reasoning_summary_part.done">;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly summary_index: Int;
    readonly type: Literal<"response.reasoning_summary_text.delta">;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.function_call_arguments.delta">;
  }, "Type"> | ReadonlySide<{
    readonly arguments: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.function_call_arguments.done">;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.code_interpreter_call_code.delta">;
  }, "Type"> | ReadonlySide<{
    readonly code: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.code_interpreter_call_code.done">;
  }, "Type"> | ReadonlySide<{
    readonly delta: String;
    readonly item_id: String;
    readonly output_index: Int;
    readonly sequence_number: Int;
    readonly type: Literal<"response.apply_patch_call_operation_diff.delta">;
  }, "Type"> | {
    readonly delta?: string;
    readonly item_id: string;
    readonly output_index: number;
    readonly sequence_number: number;
    readonly type: "response.apply_patch_call_operation_diff.done";
  } | ReadonlySide<{
    readonly item_id: String;
    readonly output_index: Int;
    readonly partial_image_b64: String;
    readonly sequence_number: Int;
    readonly type: Literal<"response.image_generation_call.partial_image">;
  }, "Type"> | {
    readonly code: string | null;
    readonly message: string;
    readonly param: string | null;
    readonly sequence_number: number;
    readonly status?: number;
    readonly type: "error";
  }, AiError, never>], AiError>;
}