# OpenAI API

Every handle of the OpenAI fake: the `openai` fixture, the scripts a test answers the model's calls with, and the calls it reads and waits for. How to script the model, step by step, is in the [OpenAI guide](https://channelstack.dev/docs/platforms/openai).

Each call is shown in every SDK's language, with its required options (the table under it lists them all). Arguments go first; options are TypeScript's trailing object, Python's keyword arguments and Rust's builder setters. The variable names are the ones the calls return elsewhere on these pages, so `user` is a `OpenAIUser` handle.

Besides the errors listed with each method, most methods can fail with [`action_requires`](https://channelstack.dev/docs/reference/api/errors#action-requires), [`cross_workspace_credential`](https://channelstack.dev/docs/reference/api/errors#cross-workspace-credential), [`fake_actor_in_live_world`](https://channelstack.dev/docs/reference/api/errors#fake-actor-in-live-world), [`internal`](https://channelstack.dev/docs/reference/api/errors#internal), [`invalid_argument`](https://channelstack.dev/docs/reference/api/errors#invalid-argument), [`live_misconfigured`](https://channelstack.dev/docs/reference/api/errors#live-misconfigured), [`live_not_allowlisted`](https://channelstack.dev/docs/reference/api/errors#live-not-allowlisted), [`not_found`](https://channelstack.dev/docs/reference/api/errors#not-found), [`session_not_found`](https://channelstack.dev/docs/reference/api/errors#session-not-found), [`unauthorized`](https://channelstack.dev/docs/reference/api/errors#unauthorized), [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#unsupported-in-live): a bad request, a closed session, or live mode refusing or misconfigured.

## OpenAIFixture

Returned by [`Session.openai()`](https://channelstack.dev/docs/reference/api/client#openai).

| Field     | Python / Rust | Type     |
| --------- | ------------- | -------- |
| `baseUrl` | `base_url`    | `string` |

### respond()

Script what the model answers: turns used in order, one per matching call, or a responder the test answers. Scripts are tried in the order they were added.

```ts title="TypeScript"
const script = await openai.respond({ when });
```

```python title="Python"
script = await openai.respond(when=when)
```

```rust title="Rust"
let script = openai.respond().when(when).await?;
```

| Parameter   | Type                                   | Required |            |
| ----------- | -------------------------------------- | -------- | ---------- |
| `turns`     | `OpenAITurnInput \| OpenAITurnInput[]` | no       | positional |
| `when`      | `OpenAIMatch`                          | no       | option     |
| `times`     | `number`                               | no       | option     |
| `timing`    | `OpenAITiming`                         | no       | option     |
| `responder` | `boolean`                              | no       | option     |

**Returns** [`OpenAIScript`](https://channelstack.dev/docs/reference/api/openai#openaiscript).

### calls()

Every model call attributed to this session, oldest first.

```ts title="TypeScript"
const sessionCalls = await openai.calls({ endpoint });
```

```python title="Python"
session_calls = await openai.calls(endpoint=endpoint)
```

```rust title="Rust"
let session_calls = openai.calls().endpoint(endpoint).await?;
```

| Parameter  | Type             | Required |        |
| ---------- | ---------------- | -------- | ------ |
| `endpoint` | `OpenAIEndpoint` | no       | option |
| `error`    | `true \| string` | no       | option |

**Returns** [`OpenAISessionCalls`](https://channelstack.dev/docs/reference/api/openai#openaisessioncalls).

### toolCalls()

Every tool call the model made in this session, each with the result the agent sent back.

```ts title="TypeScript"
const sessionToolCalls = await openai.toolCalls({ name: "…" });
```

```python title="Python"
session_tool_calls = await openai.tool_calls(name="…")
```

```rust title="Rust"
let session_tool_calls = openai.tool_calls().name("…").await?;
```

| Parameter | Type     | Required |        |
| --------- | -------- | -------- | ------ |
| `name`    | `string` | no       | option |

**Returns** [`OpenAISessionToolCalls`](https://channelstack.dev/docs/reference/api/openai#openaisessiontoolcalls).

### problems()

What went wrong with the model in this session: a call no script answered, a script that ran out or did what the real API can't, a responder that threw. Matchers fail at once on these.

```ts title="TypeScript"
const problems = await openai.problems();
```

```python title="Python"
problems = await openai.problems()
```

```rust title="Rust"
let problems = openai.problems().await?;
```

**Returns** [`OpenAIProblems`](https://channelstack.dev/docs/reference/api/openai#openaiproblems).

### sentSecrets()

The calls that sent a secret channelstack knows to the model, and the kinds they sent (`slack.botToken`): never the values.

```ts title="TypeScript"
const sentSecrets = await openai.sentSecrets();
```

```python title="Python"
sent_secrets = await openai.sent_secrets()
```

```rust title="Rust"
let sent_secrets = openai.sent_secrets().await?;
```

**Returns** [`OpenAISentSecrets`](https://channelstack.dev/docs/reference/api/openai#openaisentsecrets).

### unattributed()

Model calls no session could be given (the agent calling the model at startup, for example), oldest first: what a failing matcher names.

```ts title="TypeScript"
const unattributedCalls = await openai.unattributed({ withinMs });
```

```python title="Python"
unattributed_calls = await openai.unattributed(within_ms=within_ms)
```

```rust title="Rust"
let unattributed_calls = openai.unattributed().within_ms(within_ms).await?;
```

| Parameter  | Python / Rust | Type                  | Required |        |
| ---------- | ------------- | --------------------- | -------- | ------ |
| `withinMs` | `within_ms`   | `number \| undefined` | no       | option |

**Returns** [`OpenAIUnattributedCalls`](https://channelstack.dev/docs/reference/api/openai#openaiunattributedcalls).

### rateLimit()

Limit this session's model calls: requests and tokens per window, with truthful x-ratelimit-\* headers.

```ts title="TypeScript"
const rateLimit = await openai.rateLimit({ requests });
```

```python title="Python"
rate_limit = await openai.rate_limit(requests=requests)
```

```rust title="Rust"
let rate_limit = openai.rate_limit().requests(requests).await?;
```

| Parameter  | Type                                | Required |        |
| ---------- | ----------------------------------- | -------- | ------ |
| `requests` | `{ limit: number; per?: Duration }` | no       | option |
| `tokens`   | `{ limit: number; per?: Duration }` | no       | option |
| `error`    | `"rate_limit" \| "slow_down"`       | no       | option |

**Returns** [`OpenAIRateLimit`](https://channelstack.dev/docs/reference/api/openai#openairatelimit).

### waitForCall()

Waits for the next model call from the agent after the last one this handle returned: it polls `calls()` and never sleeps longer than it must.

```ts title="TypeScript"
const call = await openai.waitForCall({ endpoint });
```

```python title="Python"
call = await openai.wait_for_call(endpoint=endpoint)
```

```rust title="Rust"
let call = openai.wait_for_call().endpoint(endpoint).await?;
```

| Parameter  | Type             | Required |             |
| ---------- | ---------------- | -------- | ----------- |
| `endpoint` | `OpenAIEndpoint` | no       | filter      |
| `error`    | `true \| string` | no       | filter      |
| `timeout`  | `Duration`       | no       | default 10s |

**Returns** [`OpenAICall`](https://channelstack.dev/docs/reference/api/openai#openaicall). When the time is up, it fails with what it was waiting for.

### latestCall()

The latest model call from the agent, once the app is quiet. Waits for at least one: it polls `calls()` and never sleeps longer than it must.

```ts title="TypeScript"
const call = await openai.latestCall({ endpoint });
```

```python title="Python"
call = await openai.latest_call(endpoint=endpoint)
```

```rust title="Rust"
let call = openai.latest_call().endpoint(endpoint).await?;
```

| Parameter  | Python / Rust | Type             | Required |               |
| ---------- | ------------- | ---------------- | -------- | ------------- |
| `endpoint` | `endpoint`    | `OpenAIEndpoint` | no       | filter        |
| `error`    | `error`       | `true \| string` | no       | filter        |
| `timeout`  | `timeout`     | `Duration`       | no       | default 10s   |
| `quietFor` | `quiet_for`   | `Duration`       | no       | default 750ms |

**Returns** [`OpenAICall`](https://channelstack.dev/docs/reference/api/openai#openaicall). When the time is up, it fails with what it was waiting for.

## OpenAIScript

Returned by [`OpenAIFixture.respond()`](https://channelstack.dev/docs/reference/api/openai#respond), [`OpenAIScript.refresh()`](https://channelstack.dev/docs/reference/api/openai#refresh).

| Field       | Type       |
| ----------- | ---------- |
| `id`        | `string`   |
| `responder` | `boolean`  |
| `times`     | `number`   |
| `used`      | `number`   |
| `problems`  | `string[]` |

### refresh()

Re-read a script: how many calls it answered, and its problems.

```ts title="TypeScript"
const updated = await script.refresh();
```

```python title="Python"
updated = await script.refresh()
```

```rust title="Rust"
let updated = script.refresh().await?;
```

**Returns** [`OpenAIScript`](https://channelstack.dev/docs/reference/api/openai#openaiscript).

### undo()

Remove a script. Closing the session does it too.

```ts title="TypeScript"
await script.undo();
```

```python title="Python"
await script.undo()
```

```rust title="Rust"
script.undo().await?;
```

**Returns** nothing. Disposing the handle calls it.

### resume()

Let the streams this script holds at `pauseAfter` go on.

```ts title="TypeScript"
await script.resume();
```

```python title="Python"
await script.resume()
```

```rust title="Rust"
script.resume().await?;
```

**Returns** nothing.

### calls()

The calls this script answered.

```ts title="TypeScript"
const calls = await script.calls();
```

```python title="Python"
calls = await script.calls()
```

```rust title="Rust"
let calls = script.calls().await?;
```

**Returns** [`OpenAICalls`](https://channelstack.dev/docs/reference/api/openai#openaicalls).

### pausedCalls()

The calls whose streams this script holds at `pauseAfter`.

```ts title="TypeScript"
const pausedCalls = await script.pausedCalls();
```

```python title="Python"
paused_calls = await script.paused_calls()
```

```rust title="Rust"
let paused_calls = script.paused_calls().await?;
```

**Returns** [`OpenAIPausedCalls`](https://channelstack.dev/docs/reference/api/openai#openaipausedcalls).

### toolCalls()

The tool calls this script made, each with the result the agent sent back.

```ts title="TypeScript"
const toolCalls = await script.toolCalls({ name: "…" });
```

```python title="Python"
tool_calls = await script.tool_calls(name="…")
```

```rust title="Rust"
let tool_calls = script.tool_calls().name("…").await?;
```

| Parameter | Type     | Required |        |
| --------- | -------- | -------- | ------ |
| `name`    | `string` | no       | option |

**Returns** [`OpenAIToolCalls`](https://channelstack.dev/docs/reference/api/openai#openaitoolcalls).

### heldCalls()

For a responder's SDK: the calls held for it since `since`, waiting up to `waitMs` for one.

```ts title="TypeScript"
const heldPage = await script.heldCalls({ since: "…" });
```

```python title="Python"
held_page = await script.held_calls(since="…")
```

```rust title="Rust"
let held_page = script.held_calls().since("…").await?;
```

| Parameter | Python / Rust | Type                  | Required |        |
| --------- | ------------- | --------------------- | -------- | ------ |
| `since`   | `since`       | `string`              | no       | option |
| `waitMs`  | `wait_ms`     | `number \| undefined` | no       | option |

**Returns** [`OpenAIHeldPage`](https://channelstack.dev/docs/reference/api/openai#openaiheldpage).

### answerHeld()

For a responder's SDK: answer a held call with a turn, or report that the test's function threw.

```ts title="TypeScript"
await script.answerHeld("…", { turn });
```

```python title="Python"
await script.answer_held("…", turn=turn)
```

```rust title="Rust"
script.answer_held("…").turn(turn).await?;
```

| Parameter | Type              | Required |            |
| --------- | ----------------- | -------- | ---------- |
| `held`    | `string`          | yes      | positional |
| `turn`    | `OpenAITurnInput` | no       | option     |
| `error`   | `string`          | no       | option     |

**Returns** nothing.

### waitForCall()

Waits for the next model call this script answers after the last one this handle returned: it polls `calls()` and never sleeps longer than it must.

```ts title="TypeScript"
const call = await script.waitForCall();
```

```python title="Python"
call = await script.wait_for_call()
```

```rust title="Rust"
let call = script.wait_for_call().await?;
```

| Parameter | Type       | Required |             |
| --------- | ---------- | -------- | ----------- |
| `timeout` | `Duration` | no       | default 10s |

**Returns** [`OpenAICall`](https://channelstack.dev/docs/reference/api/openai#openaicall). When the time is up, it fails with what it was waiting for.

### waitForPause()

Waits for the next stream held at pauseAfter after the last one this handle returned: it polls `pausedCalls()` and never sleeps longer than it must.

```ts title="TypeScript"
const call = await script.waitForPause();
```

```python title="Python"
call = await script.wait_for_pause()
```

```rust title="Rust"
let call = script.wait_for_pause().await?;
```

| Parameter | Type       | Required |             |
| --------- | ---------- | -------- | ----------- |
| `timeout` | `Duration` | no       | default 10s |

**Returns** [`OpenAICall`](https://channelstack.dev/docs/reference/api/openai#openaicall). When the time is up, it fails with what it was waiting for.

## OpenAICall

Returned by [`OpenAICall.refresh()`](https://channelstack.dev/docs/reference/api/openai#refresh-1).

| Field        | Python / Rust | Type                                                                                                                                                                               |
| ------------ | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`         | `id`          | `string`                                                                                                                                                                           |
| `endpoint`   | `endpoint`    | `OpenAIEndpoint`                                                                                                                                                                   |
| `model`      | `model`       | `string`                                                                                                                                                                           |
| `stream`     | `stream`      | `boolean`                                                                                                                                                                          |
| `at`         | `at`          | `string`                                                                                                                                                                           |
| `durationMs` | `duration_ms` | `number`                                                                                                                                                                           |
| `attempt`    | `attempt`     | `number`                                                                                                                                                                           |
| `done`       | `done`        | `boolean`                                                                                                                                                                          |
| `request`    | `request`     | `OpenAIRequest`                                                                                                                                                                    |
| `response`   | `response`    | `{ status: number; text?: string; finish?: string; error?: string; aborted: boolean; chunksSent?: number; end?: "completed" \| "errored" \| "dropped" \| "stalled" \| "aborted" }` |
| `toolCalls`  | `tool_calls`  | `OpenAIToolCall[]`                                                                                                                                                                 |
| `script`     | `script`      | `string \| undefined`                                                                                                                                                              |

### refresh()

Re-read a model call: whether it is done, how it ended.

```ts title="TypeScript"
const updated = await call.refresh();
```

```python title="Python"
updated = await call.refresh()
```

```rust title="Rust"
let updated = call.refresh().await?;
```

**Returns** [`OpenAICall`](https://channelstack.dev/docs/reference/api/openai#openaicall).

## OpenAIRateLimit

Returned by [`OpenAIFixture.rateLimit()`](https://channelstack.dev/docs/reference/api/openai#ratelimit), [`OpenAIRateLimit.remaining()`](https://channelstack.dev/docs/reference/api/openai#remaining).

| Field        | Python / Rust  | Type                  |
| ------------ | -------------- | --------------------- |
| `id`         | `id`           | `string`              |
| `requests`   | `requests`     | `number \| undefined` |
| `tokens`     | `tokens`       | `number \| undefined` |
| `resetsInMs` | `resets_in_ms` | `number`              |

### remaining()

What the rate limit's headers would say now.

```ts title="TypeScript"
const updated = await rateLimit.remaining();
```

```python title="Python"
updated = await rate_limit.remaining()
```

```rust title="Rust"
let updated = rate_limit.remaining().await?;
```

**Returns** [`OpenAIRateLimit`](https://channelstack.dev/docs/reference/api/openai#openairatelimit).

### undo()

Remove the rate limit.

```ts title="TypeScript"
await rateLimit.undo();
```

```python title="Python"
await rate_limit.undo()
```

```rust title="Rust"
rate_limit.undo().await?;
```

**Returns** nothing. Disposing the handle calls it.

## Types

Plain values the handles return and take.

### OpenAITurnInput

```ts
type OpenAITurnInput = string | OpenAITurn;
```

### OpenAITurn

| Field         | Python / Rust  | Type                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`        | `text`         | `string \| string[] \| undefined`                                                                                                                                                                                                                                                                                                                                                                             |
| `toolCalls`   | `tool_calls`   | `OpenAIToolCallSpec[] \| undefined`                                                                                                                                                                                                                                                                                                                                                                           |
| `citations`   | `citations`    | `Array<{ quote: string; url?: string; title?: string; file?: string }> \| undefined`                                                                                                                                                                                                                                                                                                                          |
| `image`       | `image`        | `OpenAIMediaSource \| OpenAIMediaSource[] \| undefined`                                                                                                                                                                                                                                                                                                                                                       |
| `audio`       | `audio`        | `OpenAIMediaSource \| undefined`                                                                                                                                                                                                                                                                                                                                                                              |
| `reasoning`   | `reasoning`    | `{ summary?: string \| string[]; tokens?: number } \| undefined`                                                                                                                                                                                                                                                                                                                                              |
| `refusal`     | `refusal`      | `string \| undefined`                                                                                                                                                                                                                                                                                                                                                                                         |
| `finish`      | `finish`       | `"stop" \| "length" \| "content_filter" \| undefined`                                                                                                                                                                                                                                                                                                                                                         |
| `usage`       | `usage`        | `{ input?: number; output?: number; reasoning?: number; cached?: number } \| undefined`                                                                                                                                                                                                                                                                                                                       |
| `timing`      | `timing`       | `OpenAITiming \| undefined`                                                                                                                                                                                                                                                                                                                                                                                   |
| `failAfter`   | `fail_after`   | `{ chunks: number; how?: "error" \| "drop" \| "stall" } \| undefined`                                                                                                                                                                                                                                                                                                                                         |
| `pauseAfter`  | `pause_after`  | `number \| undefined`                                                                                                                                                                                                                                                                                                                                                                                         |
| `error`       | `error`        | `"rate_limit" \| "slow_down" \| "insufficient_quota" \| "credit_balance_exhausted" \| "organization_spend_limit_exceeded" \| "project_spend_limit_exceeded" \| "organization_usage_limit_exceeded" \| "server_error" \| "overloaded" \| "timeout" \| "context_length_exceeded" \| "content_policy" \| "invalid_api_key" \| "not_in_organization" \| "ip_not_authorized" \| "unsupported_region" \| undefined` |
| `retryAfter`  | `retry_after`  | `number \| string \| undefined`                                                                                                                                                                                                                                                                                                                                                                               |
| `shouldRetry` | `should_retry` | `boolean \| undefined`                                                                                                                                                                                                                                                                                                                                                                                        |
| `message`     | `message`      | `string \| undefined`                                                                                                                                                                                                                                                                                                                                                                                         |

### OpenAIToolCallSpec

| Field             | Python / Rust      | Type                                                                                                                                                                   |
| ----------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`            | `name`             | `string \| undefined`                                                                                                                                                  |
| `arguments`       | `arguments`        | `Record<string, unknown> \| string \| undefined`                                                                                                                       |
| `input`           | `input`            | `string \| undefined`                                                                                                                                                  |
| `webSearch`       | `web_search`       | `{ query: string; action?: "search" \| "open_page" \| "find_in_page"; url?: string; pattern?: string; sources?: Array<{ url: string; title?: string }> } \| undefined` |
| `fileSearch`      | `file_search`      | `{ queries: string[]; results?: Array<{ file: string; text: string; score?: number }> } \| undefined`                                                                  |
| `codeInterpreter` | `code_interpreter` | `{ code: string; logs?: string; files?: OpenAIMediaSource[] } \| undefined`                                                                                            |
| `imageGeneration` | `image_generation` | `{ image: OpenAIMediaSource; revisedPrompt?: string } \| undefined`                                                                                                    |
| `mcp`             | `mcp`              | `{ server: string; tool: string; arguments?: Record<string, unknown>; output?: string; error?: string; approval?: boolean } \| undefined`                              |
| `shell`           | `shell`            | `{ commands: string[]; output?: string } \| undefined`                                                                                                                 |
| `computer`        | `computer`         | `{ actions: OpenAIComputerAction[] } \| undefined`                                                                                                                     |
| `applyPatch`      | `apply_patch`      | `{ operations: OpenAIPatchOperation[] } \| undefined`                                                                                                                  |

### OpenAIMediaSource

```ts
type OpenAIMediaSource = MediaSource;
```

### OpenAIComputerAction

| Field  | Python / Rust     | Type     |
| ------ | ----------------- | -------- |
| `type` | `type` · `r#type` | `string` |

### OpenAIPatchOperation

| Field  | Python / Rust     | Type                                              |
| ------ | ----------------- | ------------------------------------------------- |
| `type` | `type` · `r#type` | `"create_file" \| "update_file" \| "delete_file"` |
| `path` | `path`            | `string`                                          |
| `diff` | `diff`            | `string \| undefined`                             |

### OpenAITiming

| Field           | Python / Rust    | Type                            |
| --------------- | ---------------- | ------------------------------- |
| `firstToken`    | `first_token`    | `number \| string \| undefined` |
| `betweenChunks` | `between_chunks` | `number \| string \| undefined` |

### OpenAIMatch

| Field        | Python / Rust    | Type                                                                                                                                                           |
| ------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`       | `text`           | `string \| RegExp \| undefined`                                                                                                                                |
| `prompt`     | `prompt`         | `string \| RegExp \| undefined`                                                                                                                                |
| `tools`      | `tools`          | `string[] \| undefined`                                                                                                                                        |
| `toolResult` | `tool_result`    | `boolean \| string \| undefined`                                                                                                                               |
| `endpoint`   | `endpoint`       | `"chat.completions" \| "responses" \| "images.generations" \| "images.edits" \| "audio.speech" \| "audio.transcriptions" \| "audio.translations" \| undefined` |
| `model`      | `model`          | `string \| RegExp \| undefined`                                                                                                                                |
| `stream`     | `stream`         | `boolean \| undefined`                                                                                                                                         |
| `from`       | `from_` · `from` | `SlackUser \| GitHubUser \| LinearUser \| NotionUser \| ResendUser \| GoogleUser \| DiscordUser \| undefined`                                                  |
| `in`         | `in_` · `r#in`   | `SlackConversation \| GitHubRepo \| LinearTeam \| NotionPage \| NotionDatabase \| ResendThread \| GoogleThread \| DiscordChannel \| undefined`                 |
| `approval`   | `approval`       | `boolean \| undefined`                                                                                                                                         |

### OpenAICalls

```ts
type OpenAICalls = OpenAICall[];
```

### OpenAIEndpoint

```ts
type OpenAIEndpoint = "chat.completions" | "responses" | "images.generations" | "images.edits" | "audio.speech" | "audio.transcriptions" | "audio.translations";
```

### OpenAIRequest

| Field             | Python / Rust       | Type                                                     |
| ----------------- | ------------------- | -------------------------------------------------------- |
| `endpoint`        | `endpoint`          | `OpenAIEndpoint`                                         |
| `model`           | `model`             | `string`                                                 |
| `stream`          | `stream`            | `boolean`                                                |
| `prompt`          | `prompt`            | `string \| undefined`                                    |
| `file`            | `file`              | `OpenAIPart \| undefined`                                |
| `instructions`    | `instructions`      | `string \| undefined`                                    |
| `messages`        | `messages`          | `OpenAIMessage[]`                                        |
| `tools`           | `tools`             | `OpenAITool[]`                                           |
| `toolChoice`      | `tool_choice`       | `unknown \| undefined`                                   |
| `responseFormat`  | `response_format`   | `unknown \| undefined`                                   |
| `lastUserText`    | `last_user_text`    | `string \| undefined`                                    |
| `lastToolResults` | `last_tool_results` | `Array<{ callId: string; name?: string; text: string }>` |
| `text`            | `text`              | `string`                                                 |
| `context`         | `context`           | `OpenAIContext`                                          |
| `body`            | `body`              | `unknown \| undefined`                                   |
| `headers`         | `headers`           | `Record<string, string>`                                 |

### OpenAIPart

| Field       | Python / Rust     | Type                           |
| ----------- | ----------------- | ------------------------------ |
| `type`      | `type` · `r#type` | `"image" \| "file" \| "audio"` |
| `from`      | `from_` · `from`  | `"data" \| "file_id" \| "url"` |
| `url`       | `url`             | `string \| undefined`          |
| `fileId`    | `file_id`         | `string \| undefined`          |
| `mediaType` | `media_type`      | `string \| undefined`          |
| `bytes`     | `bytes`           | `number \| undefined`          |
| `sha256`    | `sha256`          | `string \| undefined`          |
| `filename`  | `filename`        | `string \| undefined`          |

### OpenAIMessage

| Field       | Python / Rust | Type                                                                    |
| ----------- | ------------- | ----------------------------------------------------------------------- |
| `role`      | `role`        | `"system" \| "developer" \| "user" \| "assistant" \| "tool"`            |
| `text`      | `text`        | `string`                                                                |
| `toolCalls` | `tool_calls`  | `Array<{ id: string; name: string; arguments?: unknown }> \| undefined` |
| `callId`    | `call_id`     | `string \| undefined`                                                   |
| `name`      | `name`        | `string \| undefined`                                                   |
| `parts`     | `parts`       | `OpenAIPart[] \| undefined`                                             |

### OpenAITool

| Field         | Python / Rust     | Type                                   |
| ------------- | ----------------- | -------------------------------------- |
| `type`        | `type` · `r#type` | `string`                               |
| `name`        | `name`            | `string \| undefined`                  |
| `description` | `description`     | `string \| undefined`                  |
| `parameters`  | `parameters`      | `unknown \| undefined`                 |
| `strict`      | `strict`          | `boolean \| undefined`                 |
| `settings`    | `settings`        | `Record<string, unknown> \| undefined` |

### OpenAIContext

| Field          | Python / Rust    | Type                                                                   |
| -------------- | ---------------- | ---------------------------------------------------------------------- |
| `channel`      | `channel`        | `string \| undefined`                                                  |
| `from`         | `from_` · `from` | `OpenAIRef \| undefined`                                               |
| `conversation` | `conversation`   | `OpenAIRef \| undefined`                                               |
| `thread`       | `thread`         | `OpenAIRef \| undefined`                                               |
| `message`      | `message`        | `OpenAIRef \| undefined`                                               |
| `attributedBy` | `attributed_by`  | `"minted_id" \| "tag" \| "owned_id" \| "text" \| "order" \| undefined` |
| `matched`      | `matched`        | `string \| undefined`                                                  |
| `tiedWith`     | `tied_with`      | `string[] \| undefined`                                                |

### OpenAIRef

| Field | Type     |
| ----- | -------- |
| `id`  | `string` |

### OpenAIToolCall

| Field       | Python / Rust     | Type                                                                                                                                                     |
| ----------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`        | `id`              | `string`                                                                                                                                                 |
| `type`      | `type` · `r#type` | `"function" \| "custom" \| "web_search" \| "file_search" \| "code_interpreter" \| "image_generation" \| "mcp" \| "shell" \| "computer" \| "apply_patch"` |
| `hosted`    | `hosted`          | `boolean`                                                                                                                                                |
| `name`      | `name`            | `string`                                                                                                                                                 |
| `arguments` | `arguments`       | `unknown \| undefined`                                                                                                                                   |
| `madeIn`    | `made_in`         | `string`                                                                                                                                                 |
| `result`    | `result`          | `{ text: string; sentIn: string } \| undefined`                                                                                                          |

### OpenAIPausedCalls

```ts
type OpenAIPausedCalls = OpenAICall[];
```

### OpenAIToolCalls

```ts
type OpenAIToolCalls = OpenAIToolCall[];
```

### OpenAIHeldPage

| Field    | Type               |
| -------- | ------------------ |
| `held`   | `OpenAIHeldCall[]` |
| `cursor` | `string`           |

### OpenAIHeldCall

| Field     | Type            |
| --------- | --------------- |
| `id`      | `string`        |
| `request` | `OpenAIRequest` |

### OpenAISessionCalls

```ts
type OpenAISessionCalls = OpenAICall[];
```

### OpenAISessionToolCalls

```ts
type OpenAISessionToolCalls = OpenAIToolCall[];
```

### OpenAIProblems

```ts
type OpenAIProblems = string[];
```

### OpenAISentSecrets

```ts
type OpenAISentSecrets = OpenAISentSecret[];
```

### OpenAISentSecret

| Field   | Type       |
| ------- | ---------- |
| `call`  | `string`   |
| `kinds` | `string[]` |

### OpenAIUnattributedCalls

```ts
type OpenAIUnattributedCalls = OpenAIUnattributedCall[];
```

### OpenAIUnattributedCall

| Field          | Python / Rust    | Type                  |
| -------------- | ---------------- | --------------------- |
| `id`           | `id`             | `string`              |
| `endpoint`     | `endpoint`       | `OpenAIEndpoint`      |
| `model`        | `model`          | `string`              |
| `at`           | `at`             | `string`              |
| `lastUserText` | `last_user_text` | `string \| undefined` |
| `tools`        | `tools`          | `string[]`            |
| `sinceMs`      | `since_ms`       | `number`              |
| `message`      | `message`        | `string`              |
