transl8-srt 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +176 -0
- package/dist/index.cjs +7469 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +7440 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../node_modules/openai/internal/tslib.mjs","../node_modules/openai/src/internal/utils/uuid.ts","../node_modules/openai/src/internal/errors.ts","../node_modules/openai/src/core/error.ts","../node_modules/openai/src/internal/utils/values.ts","../node_modules/openai/src/internal/utils/sleep.ts","../node_modules/openai/src/version.ts","../node_modules/openai/src/internal/detect-platform.ts","../node_modules/openai/src/internal/shims.ts","../node_modules/openai/src/internal/request-options.ts","../node_modules/openai/src/internal/qs/formats.ts","../node_modules/openai/src/internal/qs/utils.ts","../node_modules/openai/src/internal/qs/stringify.ts","../node_modules/openai/src/internal/utils/query.ts","../node_modules/openai/src/internal/utils/bytes.ts","../node_modules/openai/src/internal/decoders/line.ts","../node_modules/openai/src/internal/utils/log.ts","../node_modules/openai/src/core/streaming.ts","../node_modules/openai/src/internal/parse.ts","../node_modules/openai/src/core/api-promise.ts","../node_modules/openai/src/core/pagination.ts","../node_modules/openai/src/internal/uploads.ts","../node_modules/openai/src/internal/to-file.ts","../node_modules/openai/src/core/resource.ts","../node_modules/openai/src/internal/utils/path.ts","../node_modules/openai/src/resources/chat/completions/messages.ts","../node_modules/openai/src/lib/parser.ts","../node_modules/openai/src/lib/chatCompletionUtils.ts","../node_modules/openai/src/lib/EventStream.ts","../node_modules/openai/src/lib/RunnableFunction.ts","../node_modules/openai/src/lib/AbstractChatCompletionRunner.ts","../node_modules/openai/src/lib/ChatCompletionRunner.ts","../node_modules/openai/src/_vendor/partial-json-parser/parser.ts","../node_modules/openai/src/lib/ChatCompletionStream.ts","../node_modules/openai/src/lib/ChatCompletionStreamingRunner.ts","../node_modules/openai/src/resources/chat/completions/completions.ts","../node_modules/openai/src/resources/chat/chat.ts","../node_modules/openai/src/internal/headers.ts","../node_modules/openai/src/resources/audio/speech.ts","../node_modules/openai/src/resources/audio/transcriptions.ts","../node_modules/openai/src/resources/audio/translations.ts","../node_modules/openai/src/resources/audio/audio.ts","../node_modules/openai/src/resources/batches.ts","../node_modules/openai/src/resources/beta/assistants.ts","../node_modules/openai/src/resources/beta/realtime/sessions.ts","../node_modules/openai/src/resources/beta/realtime/transcription-sessions.ts","../node_modules/openai/src/resources/beta/realtime/realtime.ts","../node_modules/openai/src/resources/beta/chatkit/sessions.ts","../node_modules/openai/src/resources/beta/chatkit/threads.ts","../node_modules/openai/src/resources/beta/chatkit/chatkit.ts","../node_modules/openai/src/resources/beta/threads/messages.ts","../node_modules/openai/src/resources/beta/threads/runs/steps.ts","../node_modules/openai/src/internal/utils/base64.ts","../node_modules/openai/src/internal/utils/env.ts","../node_modules/openai/src/lib/AssistantStream.ts","../node_modules/openai/src/resources/beta/threads/runs/runs.ts","../node_modules/openai/src/resources/beta/threads/threads.ts","../node_modules/openai/src/resources/beta/beta.ts","../node_modules/openai/src/resources/completions.ts","../node_modules/openai/src/resources/containers/files/content.ts","../node_modules/openai/src/resources/containers/files/files.ts","../node_modules/openai/src/resources/containers/containers.ts","../node_modules/openai/src/resources/conversations/items.ts","../node_modules/openai/src/resources/conversations/conversations.ts","../node_modules/openai/src/resources/embeddings.ts","../node_modules/openai/src/resources/evals/runs/output-items.ts","../node_modules/openai/src/resources/evals/runs/runs.ts","../node_modules/openai/src/resources/evals/evals.ts","../node_modules/openai/src/resources/files.ts","../node_modules/openai/src/resources/fine-tuning/methods.ts","../node_modules/openai/src/resources/fine-tuning/alpha/graders.ts","../node_modules/openai/src/resources/fine-tuning/alpha/alpha.ts","../node_modules/openai/src/resources/fine-tuning/checkpoints/permissions.ts","../node_modules/openai/src/resources/fine-tuning/checkpoints/checkpoints.ts","../node_modules/openai/src/resources/fine-tuning/jobs/checkpoints.ts","../node_modules/openai/src/resources/fine-tuning/jobs/jobs.ts","../node_modules/openai/src/resources/fine-tuning/fine-tuning.ts","../node_modules/openai/src/resources/graders/grader-models.ts","../node_modules/openai/src/resources/graders/graders.ts","../node_modules/openai/src/resources/images.ts","../node_modules/openai/src/resources/models.ts","../node_modules/openai/src/resources/moderations.ts","../node_modules/openai/src/resources/realtime/calls.ts","../node_modules/openai/src/resources/realtime/client-secrets.ts","../node_modules/openai/src/resources/realtime/realtime.ts","../node_modules/openai/src/lib/ResponsesParser.ts","../node_modules/openai/src/lib/responses/ResponseStream.ts","../node_modules/openai/src/resources/responses/input-items.ts","../node_modules/openai/src/resources/responses/input-tokens.ts","../node_modules/openai/src/resources/responses/responses.ts","../node_modules/openai/src/resources/skills/content.ts","../node_modules/openai/src/resources/skills/versions/content.ts","../node_modules/openai/src/resources/skills/versions/versions.ts","../node_modules/openai/src/resources/skills/skills.ts","../node_modules/openai/src/resources/uploads/parts.ts","../node_modules/openai/src/resources/uploads/uploads.ts","../node_modules/openai/src/lib/Util.ts","../node_modules/openai/src/resources/vector-stores/file-batches.ts","../node_modules/openai/src/resources/vector-stores/files.ts","../node_modules/openai/src/resources/vector-stores/vector-stores.ts","../node_modules/openai/src/resources/videos.ts","../node_modules/openai/src/resources/webhooks/webhooks.ts","../node_modules/openai/src/client.ts","../src/types/types.ts","../src/utils/parser.ts","../src/utils/reconstructor.ts","../src/utils/prompts.ts","../src/utils/executor.ts","../src/utils/reanchor.ts","../src/utils/emitter.ts"],"sourcesContent":["import OpenAI from \"openai\";\nimport {parseCues, detectFormat} from \"./utils/parser.js\";\nimport {reconstructSentences} from \"./utils/reconstructor.js\";\nimport {executeTranslation} from \"./utils/executor.js\";\nimport {reanchorCues} from \"./utils/reanchor.js\";\nimport {emitSRT, emitVTT} from \"./utils/emitter.js\";\nimport type {\n TranslateOptions,\n TranslationResult,\n} from \"./types/types.js\";\n\nexport * from \"./types/types.js\";\n\n// ─── Cost model (as of June 2025) ─────────────────────────────────────────────\n\nconst COST_PER_M_TOKENS = {\n \"gpt-4o\": {input: 2.50, output: 10.00},\n \"gpt-4o-mini\": {input: 0.15, output: 0.60},\n} as const;\n\nfunction estimateCost(\n model: \"gpt-4o\" | \"gpt-4o-mini\",\n inputTokens: number,\n outputTokens: number\n): number {\n const rates = COST_PER_M_TOKENS[model];\n return (\n (inputTokens / 1_000_000) * rates.input +\n (outputTokens / 1_000_000) * rates.output\n );\n}\n\n// ─── Core translate function ──────────────────────────────────────────────────\n\nexport async function translate(\n /** Raw SRT or VTT file content */\n fileContent: string,\n opts: TranslateOptions,\n /** Pass your own OpenAI client (allows custom baseURL, auth, etc.) */\n client?: OpenAI\n): Promise<TranslationResult> {\n const startTime = Date.now();\n\n const oi = client ?? new OpenAI(); // uses OPENAI_API_KEY from env\n const format = detectFormat(fileContent);\n\n // 1. Parse\n const cues = parseCues(fileContent, format);\n\n // 2. Reconstruct sentences from fragmented cues\n const sentences = reconstructSentences(cues);\n\n // 3. Translate (batched, concurrent, sliding window)\n const {translations, totalInputTokens, totalOutputTokens, totalBatches} =\n await executeTranslation(oi, sentences, opts);\n\n // 4. Re-anchor back to original timestamps\n const translatedCues = reanchorCues(cues, sentences, translations);\n\n // 5. Assemble result\n const model = opts.model ??\n ([\"yo\", \"ig\", \"ha\", \"sw\", \"zu\", \"ar\", \"am\"].includes(opts.targetLang)\n ? \"gpt-4o\"\n : \"gpt-4o-mini\");\n\n const stats = {\n totalCues: cues.length,\n totalSentences: sentences.length,\n totalBatches,\n inputTokens: totalInputTokens,\n outputTokens: totalOutputTokens,\n estimatedCostUsd: estimateCost(model, totalInputTokens, totalOutputTokens),\n durationMs: Date.now() - startTime,\n };\n\n return {\n sourceLang: opts.sourceLang ?? \"en\",\n targetLang: opts.targetLang,\n cues: translatedCues,\n stats,\n toSRT: () => emitSRT(translatedCues),\n toVTT: () => emitVTT(translatedCues),\n };\n}\n\n// ─── Convenience: translate from file path (Node.js) ─────────────────────────\n\nimport {readFile, writeFile} from \"fs/promises\";\nimport {extname} from \"path\";\n\nexport async function translateFile(\n inputPath: string,\n outputPath: string,\n opts: TranslateOptions,\n client?: OpenAI\n): Promise<TranslationResult> {\n const content = await readFile(inputPath, \"utf-8\");\n const result = await translate(content, opts, client);\n\n const ext = extname(outputPath).toLowerCase();\n const output = ext === \".vtt\" ? result.toVTT() : result.toSRT();\n await writeFile(outputPath, output, \"utf-8\");\n\n return result;\n}\n","function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\")\n throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f)\n throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver))\n throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return kind === \"a\" ? f.call(receiver, value) : f ? (f.value = value) : state.set(receiver, value), value;\n}\nfunction __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f)\n throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver))\n throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\nexport { __classPrivateFieldSet, __classPrivateFieldGet };\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * https://stackoverflow.com/a/2117523\n */\nexport let uuid4 = function () {\n const { crypto } = globalThis as any;\n if (crypto?.randomUUID) {\n uuid4 = crypto.randomUUID.bind(crypto);\n return crypto.randomUUID();\n }\n const u8 = new Uint8Array(1);\n const randomByte = crypto ? () => crypto.getRandomValues(u8)[0]! : () => (Math.random() * 0xff) & 0xff;\n return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>\n (+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16),\n );\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport function isAbortError(err: unknown) {\n return (\n typeof err === 'object' &&\n err !== null &&\n // Spec-compliant fetch implementations\n (('name' in err && (err as any).name === 'AbortError') ||\n // Expo fetch\n ('message' in err && String((err as any).message).includes('FetchRequestCanceledException')))\n );\n}\n\nexport const castToError = (err: any): Error => {\n if (err instanceof Error) return err;\n if (typeof err === 'object' && err !== null) {\n try {\n if (Object.prototype.toString.call(err) === '[object Error]') {\n // @ts-ignore - not all envs have native support for cause yet\n const error = new Error(err.message, err.cause ? { cause: err.cause } : {});\n if (err.stack) error.stack = err.stack;\n // @ts-ignore - not all envs have native support for cause yet\n if (err.cause && !error.cause) error.cause = err.cause;\n if (err.name) error.name = err.name;\n return error;\n }\n } catch {}\n try {\n return new Error(JSON.stringify(err));\n } catch {}\n }\n return new Error(err);\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { castToError } from '../internal/errors';\n\nexport class OpenAIError extends Error {}\n\nexport class APIError<\n TStatus extends number | undefined = number | undefined,\n THeaders extends Headers | undefined = Headers | undefined,\n TError extends Object | undefined = Object | undefined,\n> extends OpenAIError {\n /** HTTP status for the response that caused the error */\n readonly status: TStatus;\n /** HTTP headers for the response that caused the error */\n readonly headers: THeaders;\n /** JSON body of the response that caused the error */\n readonly error: TError;\n\n readonly code: string | null | undefined;\n readonly param: string | null | undefined;\n readonly type: string | undefined;\n\n readonly requestID: string | null | undefined;\n\n constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {\n super(`${APIError.makeMessage(status, error, message)}`);\n this.status = status;\n this.headers = headers;\n this.requestID = headers?.get('x-request-id');\n this.error = error;\n\n const data = error as Record<string, any>;\n this.code = data?.['code'];\n this.param = data?.['param'];\n this.type = data?.['type'];\n }\n\n private static makeMessage(status: number | undefined, error: any, message: string | undefined) {\n const msg =\n error?.message ?\n typeof error.message === 'string' ?\n error.message\n : JSON.stringify(error.message)\n : error ? JSON.stringify(error)\n : message;\n\n if (status && msg) {\n return `${status} ${msg}`;\n }\n if (status) {\n return `${status} status code (no body)`;\n }\n if (msg) {\n return msg;\n }\n return '(no status code or body)';\n }\n\n static generate(\n status: number | undefined,\n errorResponse: Object | undefined,\n message: string | undefined,\n headers: Headers | undefined,\n ): APIError {\n if (!status || !headers) {\n return new APIConnectionError({ message, cause: castToError(errorResponse) });\n }\n\n const error = (errorResponse as Record<string, any>)?.['error'];\n\n if (status === 400) {\n return new BadRequestError(status, error, message, headers);\n }\n\n if (status === 401) {\n return new AuthenticationError(status, error, message, headers);\n }\n\n if (status === 403) {\n return new PermissionDeniedError(status, error, message, headers);\n }\n\n if (status === 404) {\n return new NotFoundError(status, error, message, headers);\n }\n\n if (status === 409) {\n return new ConflictError(status, error, message, headers);\n }\n\n if (status === 422) {\n return new UnprocessableEntityError(status, error, message, headers);\n }\n\n if (status === 429) {\n return new RateLimitError(status, error, message, headers);\n }\n\n if (status >= 500) {\n return new InternalServerError(status, error, message, headers);\n }\n\n return new APIError(status, error, message, headers);\n }\n}\n\nexport class APIUserAbortError extends APIError<undefined, undefined, undefined> {\n constructor({ message }: { message?: string } = {}) {\n super(undefined, undefined, message || 'Request was aborted.', undefined);\n }\n}\n\nexport class APIConnectionError extends APIError<undefined, undefined, undefined> {\n constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {\n super(undefined, undefined, message || 'Connection error.', undefined);\n // in some environments the 'cause' property is already declared\n // @ts-ignore\n if (cause) this.cause = cause;\n }\n}\n\nexport class APIConnectionTimeoutError extends APIConnectionError {\n constructor({ message }: { message?: string } = {}) {\n super({ message: message ?? 'Request timed out.' });\n }\n}\n\nexport class BadRequestError extends APIError<400, Headers> {}\n\nexport class AuthenticationError extends APIError<401, Headers> {}\n\nexport class PermissionDeniedError extends APIError<403, Headers> {}\n\nexport class NotFoundError extends APIError<404, Headers> {}\n\nexport class ConflictError extends APIError<409, Headers> {}\n\nexport class UnprocessableEntityError extends APIError<422, Headers> {}\n\nexport class RateLimitError extends APIError<429, Headers> {}\n\nexport class InternalServerError extends APIError<number, Headers> {}\n\nexport class LengthFinishReasonError extends OpenAIError {\n constructor() {\n super(`Could not parse response content as the length limit was reached`);\n }\n}\n\nexport class ContentFilterFinishReasonError extends OpenAIError {\n constructor() {\n super(`Could not parse response content as the request was rejected by the content filter`);\n }\n}\n\nexport class InvalidWebhookSignatureError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { OpenAIError } from '../../core/error';\n\n// https://url.spec.whatwg.org/#url-scheme-string\nconst startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;\n\nexport const isAbsoluteURL = (url: string): boolean => {\n return startsWithSchemeRegexp.test(url);\n};\n\nexport let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));\nexport let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];\n\n/** Returns an object if the given value isn't an object, otherwise returns as-is */\nexport function maybeObj(x: unknown): object {\n if (typeof x !== 'object') {\n return {};\n }\n\n return x ?? {};\n}\n\n// https://stackoverflow.com/a/34491287\nexport function isEmptyObj(obj: Object | null | undefined): boolean {\n if (!obj) return true;\n for (const _k in obj) return false;\n return true;\n}\n\n// https://eslint.org/docs/latest/rules/no-prototype-builtins\nexport function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {\n return Object.prototype.hasOwnProperty.call(obj, key);\n}\n\nexport function isObj(obj: unknown): obj is Record<string, unknown> {\n return obj != null && typeof obj === 'object' && !Array.isArray(obj);\n}\n\nexport const ensurePresent = <T>(value: T | null | undefined): T => {\n if (value == null) {\n throw new OpenAIError(`Expected a value to be given but received ${value} instead.`);\n }\n\n return value;\n};\n\nexport const validatePositiveInteger = (name: string, n: unknown): number => {\n if (typeof n !== 'number' || !Number.isInteger(n)) {\n throw new OpenAIError(`${name} must be an integer`);\n }\n if (n < 0) {\n throw new OpenAIError(`${name} must be a positive integer`);\n }\n return n;\n};\n\nexport const coerceInteger = (value: unknown): number => {\n if (typeof value === 'number') return Math.round(value);\n if (typeof value === 'string') return parseInt(value, 10);\n\n throw new OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);\n};\n\nexport const coerceFloat = (value: unknown): number => {\n if (typeof value === 'number') return value;\n if (typeof value === 'string') return parseFloat(value);\n\n throw new OpenAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);\n};\n\nexport const coerceBoolean = (value: unknown): boolean => {\n if (typeof value === 'boolean') return value;\n if (typeof value === 'string') return value === 'true';\n return Boolean(value);\n};\n\nexport const maybeCoerceInteger = (value: unknown): number | undefined => {\n if (value == null) {\n return undefined;\n }\n return coerceInteger(value);\n};\n\nexport const maybeCoerceFloat = (value: unknown): number | undefined => {\n if (value == null) {\n return undefined;\n }\n return coerceFloat(value);\n};\n\nexport const maybeCoerceBoolean = (value: unknown): boolean | undefined => {\n if (value == null) {\n return undefined;\n }\n return coerceBoolean(value);\n};\n\nexport const safeJSON = (text: string) => {\n try {\n return JSON.parse(text);\n } catch (err) {\n return undefined;\n }\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nexport const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n","export const VERSION = '6.27.0'; // x-release-please-version\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { VERSION } from '../version';\n\nexport const isRunningInBrowser = () => {\n return (\n // @ts-ignore\n typeof window !== 'undefined' &&\n // @ts-ignore\n typeof window.document !== 'undefined' &&\n // @ts-ignore\n typeof navigator !== 'undefined'\n );\n};\n\ntype DetectedPlatform = 'deno' | 'node' | 'edge' | 'unknown';\n\n/**\n * Note this does not detect 'browser'; for that, use getBrowserInfo().\n */\nfunction getDetectedPlatform(): DetectedPlatform {\n if (typeof Deno !== 'undefined' && Deno.build != null) {\n return 'deno';\n }\n if (typeof EdgeRuntime !== 'undefined') {\n return 'edge';\n }\n if (\n Object.prototype.toString.call(\n typeof (globalThis as any).process !== 'undefined' ? (globalThis as any).process : 0,\n ) === '[object process]'\n ) {\n return 'node';\n }\n return 'unknown';\n}\n\ndeclare const Deno: any;\ndeclare const EdgeRuntime: any;\ntype Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';\ntype PlatformName =\n | 'MacOS'\n | 'Linux'\n | 'Windows'\n | 'FreeBSD'\n | 'OpenBSD'\n | 'iOS'\n | 'Android'\n | `Other:${string}`\n | 'Unknown';\ntype Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';\ntype PlatformProperties = {\n 'X-Stainless-Lang': 'js';\n 'X-Stainless-Package-Version': string;\n 'X-Stainless-OS': PlatformName;\n 'X-Stainless-Arch': Arch;\n 'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';\n 'X-Stainless-Runtime-Version': string;\n};\nconst getPlatformProperties = (): PlatformProperties => {\n const detectedPlatform = getDetectedPlatform();\n if (detectedPlatform === 'deno') {\n return {\n 'X-Stainless-Lang': 'js',\n 'X-Stainless-Package-Version': VERSION,\n 'X-Stainless-OS': normalizePlatform(Deno.build.os),\n 'X-Stainless-Arch': normalizeArch(Deno.build.arch),\n 'X-Stainless-Runtime': 'deno',\n 'X-Stainless-Runtime-Version':\n typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',\n };\n }\n if (typeof EdgeRuntime !== 'undefined') {\n return {\n 'X-Stainless-Lang': 'js',\n 'X-Stainless-Package-Version': VERSION,\n 'X-Stainless-OS': 'Unknown',\n 'X-Stainless-Arch': `other:${EdgeRuntime}`,\n 'X-Stainless-Runtime': 'edge',\n 'X-Stainless-Runtime-Version': (globalThis as any).process.version,\n };\n }\n // Check if Node.js\n if (detectedPlatform === 'node') {\n return {\n 'X-Stainless-Lang': 'js',\n 'X-Stainless-Package-Version': VERSION,\n 'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),\n 'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),\n 'X-Stainless-Runtime': 'node',\n 'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',\n };\n }\n\n const browserInfo = getBrowserInfo();\n if (browserInfo) {\n return {\n 'X-Stainless-Lang': 'js',\n 'X-Stainless-Package-Version': VERSION,\n 'X-Stainless-OS': 'Unknown',\n 'X-Stainless-Arch': 'unknown',\n 'X-Stainless-Runtime': `browser:${browserInfo.browser}`,\n 'X-Stainless-Runtime-Version': browserInfo.version,\n };\n }\n\n // TODO add support for Cloudflare workers, etc.\n return {\n 'X-Stainless-Lang': 'js',\n 'X-Stainless-Package-Version': VERSION,\n 'X-Stainless-OS': 'Unknown',\n 'X-Stainless-Arch': 'unknown',\n 'X-Stainless-Runtime': 'unknown',\n 'X-Stainless-Runtime-Version': 'unknown',\n };\n};\n\ntype BrowserInfo = {\n browser: Browser;\n version: string;\n};\n\ndeclare const navigator: { userAgent: string } | undefined;\n\n// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts\nfunction getBrowserInfo(): BrowserInfo | null {\n if (typeof navigator === 'undefined' || !navigator) {\n return null;\n }\n\n // NOTE: The order matters here!\n const browserPatterns = [\n { key: 'edge' as const, pattern: /Edge(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n { key: 'ie' as const, pattern: /MSIE(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n { key: 'ie' as const, pattern: /Trident(?:.*rv\\:(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n { key: 'chrome' as const, pattern: /Chrome(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n { key: 'firefox' as const, pattern: /Firefox(?:\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?/ },\n { key: 'safari' as const, pattern: /(?:Version\\W+(\\d+)\\.(\\d+)(?:\\.(\\d+))?)?(?:\\W+Mobile\\S*)?\\W+Safari/ },\n ];\n\n // Find the FIRST matching browser\n for (const { key, pattern } of browserPatterns) {\n const match = pattern.exec(navigator.userAgent);\n if (match) {\n const major = match[1] || 0;\n const minor = match[2] || 0;\n const patch = match[3] || 0;\n\n return { browser: key, version: `${major}.${minor}.${patch}` };\n }\n }\n\n return null;\n}\n\nconst normalizeArch = (arch: string): Arch => {\n // Node docs:\n // - https://nodejs.org/api/process.html#processarch\n // Deno docs:\n // - https://doc.deno.land/deno/stable/~/Deno.build\n if (arch === 'x32') return 'x32';\n if (arch === 'x86_64' || arch === 'x64') return 'x64';\n if (arch === 'arm') return 'arm';\n if (arch === 'aarch64' || arch === 'arm64') return 'arm64';\n if (arch) return `other:${arch}`;\n return 'unknown';\n};\n\nconst normalizePlatform = (platform: string): PlatformName => {\n // Node platforms:\n // - https://nodejs.org/api/process.html#processplatform\n // Deno platforms:\n // - https://doc.deno.land/deno/stable/~/Deno.build\n // - https://github.com/denoland/deno/issues/14799\n\n platform = platform.toLowerCase();\n\n // NOTE: this iOS check is untested and may not work\n // Node does not work natively on IOS, there is a fork at\n // https://github.com/nodejs-mobile/nodejs-mobile\n // however it is unknown at the time of writing how to detect if it is running\n if (platform.includes('ios')) return 'iOS';\n if (platform === 'android') return 'Android';\n if (platform === 'darwin') return 'MacOS';\n if (platform === 'win32') return 'Windows';\n if (platform === 'freebsd') return 'FreeBSD';\n if (platform === 'openbsd') return 'OpenBSD';\n if (platform === 'linux') return 'Linux';\n if (platform) return `Other:${platform}`;\n return 'Unknown';\n};\n\nlet _platformHeaders: PlatformProperties;\nexport const getPlatformHeaders = () => {\n return (_platformHeaders ??= getPlatformProperties());\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.\n *\n * These are used to ensure we can provide a consistent behaviour between different JavaScript environments and good error\n * messages in cases where an environment isn't fully supported.\n */\n\nimport type { Fetch } from './builtin-types';\nimport type { ReadableStream } from './shim-types';\n\nexport function getDefaultFetch(): Fetch {\n if (typeof fetch !== 'undefined') {\n return fetch as any;\n }\n\n throw new Error(\n '`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',\n );\n}\n\ntype ReadableStreamArgs = ConstructorParameters<typeof ReadableStream>;\n\nexport function makeReadableStream(...args: ReadableStreamArgs): ReadableStream {\n const ReadableStream = (globalThis as any).ReadableStream;\n if (typeof ReadableStream === 'undefined') {\n // Note: All of the platforms / runtimes we officially support already define\n // `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.\n throw new Error(\n '`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`',\n );\n }\n\n return new ReadableStream(...args);\n}\n\nexport function ReadableStreamFrom<T>(iterable: Iterable<T> | AsyncIterable<T>): ReadableStream<T> {\n let iter: AsyncIterator<T> | Iterator<T> =\n Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();\n\n return makeReadableStream({\n start() {},\n async pull(controller: any) {\n const { done, value } = await iter.next();\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n },\n async cancel() {\n await iter.return?.();\n },\n });\n}\n\n/**\n * Most browsers don't yet have async iterable support for ReadableStream,\n * and Node has a very different way of reading bytes from its \"ReadableStream\".\n *\n * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {\n if (stream[Symbol.asyncIterator]) return stream;\n\n const reader = stream.getReader();\n return {\n async next() {\n try {\n const result = await reader.read();\n if (result?.done) reader.releaseLock(); // release lock when stream becomes closed\n return result;\n } catch (e) {\n reader.releaseLock(); // release lock when stream becomes errored\n throw e;\n }\n },\n async return() {\n const cancelPromise = reader.cancel();\n reader.releaseLock();\n await cancelPromise;\n return { done: true, value: undefined };\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n };\n}\n\n/**\n * Cancels a ReadableStream we don't need to consume.\n * See https://undici.nodejs.org/#/?id=garbage-collection\n */\nexport async function CancelReadableStream(stream: any): Promise<void> {\n if (stream === null || typeof stream !== 'object') return;\n\n if (stream[Symbol.asyncIterator]) {\n await stream[Symbol.asyncIterator]().return?.();\n return;\n }\n\n const reader = stream.getReader();\n const cancelPromise = reader.cancel();\n reader.releaseLock();\n await cancelPromise;\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { NullableHeaders } from './headers';\n\nimport type { BodyInit } from './builtin-types';\nimport { Stream } from '../core/streaming';\nimport type { HTTPMethod, MergedRequestInit } from './types';\nimport { type HeadersLike } from './headers';\n\nexport type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };\n\nexport type RequestOptions = {\n /**\n * The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').\n */\n method?: HTTPMethod;\n\n /**\n * The URL path for the request.\n *\n * @example \"/v1/foo\"\n */\n path?: string;\n\n /**\n * Query parameters to include in the request URL.\n */\n query?: object | undefined | null;\n\n /**\n * The request body. Can be a string, JSON object, FormData, or other supported types.\n */\n body?: unknown;\n\n /**\n * HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.\n */\n headers?: HeadersLike;\n\n /**\n * The maximum number of times that the client will retry a request in case of a\n * temporary failure, like a network error or a 5XX error from the server.\n *\n * @default 2\n */\n maxRetries?: number;\n\n stream?: boolean | undefined;\n\n /**\n * The maximum amount of time (in milliseconds) that the client should wait for a response\n * from the server before timing out a single request.\n *\n * @unit milliseconds\n */\n timeout?: number;\n\n /**\n * Additional `RequestInit` options to be passed to the underlying `fetch` call.\n * These options will be merged with the client's default fetch options.\n */\n fetchOptions?: MergedRequestInit;\n\n /**\n * An AbortSignal that can be used to cancel the request.\n */\n signal?: AbortSignal | undefined | null;\n\n /**\n * A unique key for this request to enable idempotency.\n */\n idempotencyKey?: string;\n\n /**\n * Override the default base URL for this specific request.\n */\n defaultBaseURL?: string | undefined;\n\n __metadata?: Record<string, unknown>;\n __binaryResponse?: boolean | undefined;\n __streamClass?: typeof Stream;\n __synthesizeEventData?: boolean;\n};\n\nexport type EncodedContent = { bodyHeaders: HeadersLike; body: BodyInit };\nexport type RequestEncoder = (request: { headers: NullableHeaders; body: unknown }) => EncodedContent;\n\nexport const FallbackEncoder: RequestEncoder = ({ headers, body }) => {\n return {\n bodyHeaders: {\n 'content-type': 'application/json',\n },\n body: JSON.stringify(body),\n };\n};\n","import type { Format } from './types';\n\nexport const default_format: Format = 'RFC3986';\nexport const default_formatter = (v: PropertyKey) => String(v);\nexport const formatters: Record<Format, (str: PropertyKey) => string> = {\n RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),\n RFC3986: default_formatter,\n};\nexport const RFC1738 = 'RFC1738';\nexport const RFC3986 = 'RFC3986';\n","import { RFC1738 } from './formats';\nimport type { DefaultEncoder, Format } from './types';\nimport { isArray } from '../utils/values';\n\nexport let has = (obj: object, key: PropertyKey): boolean => (\n (has = (Object as any).hasOwn ?? Function.prototype.call.bind(Object.prototype.hasOwnProperty)),\n has(obj, key)\n);\n\nconst hex_table = /* @__PURE__ */ (() => {\n const array = [];\n for (let i = 0; i < 256; ++i) {\n array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());\n }\n\n return array;\n})();\n\nfunction compact_queue<T extends Record<string, any>>(queue: Array<{ obj: T; prop: string }>) {\n while (queue.length > 1) {\n const item = queue.pop();\n if (!item) continue;\n\n const obj = item.obj[item.prop];\n\n if (isArray(obj)) {\n const compacted: unknown[] = [];\n\n for (let j = 0; j < obj.length; ++j) {\n if (typeof obj[j] !== 'undefined') {\n compacted.push(obj[j]);\n }\n }\n\n // @ts-ignore\n item.obj[item.prop] = compacted;\n }\n }\n}\n\nfunction array_to_object(source: any[], options: { plainObjects: boolean }) {\n const obj = options && options.plainObjects ? Object.create(null) : {};\n for (let i = 0; i < source.length; ++i) {\n if (typeof source[i] !== 'undefined') {\n obj[i] = source[i];\n }\n }\n\n return obj;\n}\n\nexport function merge(\n target: any,\n source: any,\n options: { plainObjects?: boolean; allowPrototypes?: boolean } = {},\n) {\n if (!source) {\n return target;\n }\n\n if (typeof source !== 'object') {\n if (isArray(target)) {\n target.push(source);\n } else if (target && typeof target === 'object') {\n if ((options && (options.plainObjects || options.allowPrototypes)) || !has(Object.prototype, source)) {\n target[source] = true;\n }\n } else {\n return [target, source];\n }\n\n return target;\n }\n\n if (!target || typeof target !== 'object') {\n return [target].concat(source);\n }\n\n let mergeTarget = target;\n if (isArray(target) && !isArray(source)) {\n // @ts-ignore\n mergeTarget = array_to_object(target, options);\n }\n\n if (isArray(target) && isArray(source)) {\n source.forEach(function (item, i) {\n if (has(target, i)) {\n const targetItem = target[i];\n if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {\n target[i] = merge(targetItem, item, options);\n } else {\n target.push(item);\n }\n } else {\n target[i] = item;\n }\n });\n return target;\n }\n\n return Object.keys(source).reduce(function (acc, key) {\n const value = source[key];\n\n if (has(acc, key)) {\n acc[key] = merge(acc[key], value, options);\n } else {\n acc[key] = value;\n }\n return acc;\n }, mergeTarget);\n}\n\nexport function assign_single_source(target: any, source: any) {\n return Object.keys(source).reduce(function (acc, key) {\n acc[key] = source[key];\n return acc;\n }, target);\n}\n\nexport function decode(str: string, _: any, charset: string) {\n const strWithoutPlus = str.replace(/\\+/g, ' ');\n if (charset === 'iso-8859-1') {\n // unescape never throws, no try...catch needed:\n return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);\n }\n // utf-8\n try {\n return decodeURIComponent(strWithoutPlus);\n } catch (e) {\n return strWithoutPlus;\n }\n}\n\nconst limit = 1024;\n\nexport const encode: (\n str: any,\n defaultEncoder: DefaultEncoder,\n charset: string,\n type: 'key' | 'value',\n format: Format,\n) => string = (str, _defaultEncoder, charset, _kind, format: Format) => {\n // This code was originally written by Brian White for the io.js core querystring library.\n // It has been adapted here for stricter adherence to RFC 3986\n if (str.length === 0) {\n return str;\n }\n\n let string = str;\n if (typeof str === 'symbol') {\n string = Symbol.prototype.toString.call(str);\n } else if (typeof str !== 'string') {\n string = String(str);\n }\n\n if (charset === 'iso-8859-1') {\n return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {\n return '%26%23' + parseInt($0.slice(2), 16) + '%3B';\n });\n }\n\n let out = '';\n for (let j = 0; j < string.length; j += limit) {\n const segment = string.length >= limit ? string.slice(j, j + limit) : string;\n const arr = [];\n\n for (let i = 0; i < segment.length; ++i) {\n let c = segment.charCodeAt(i);\n if (\n c === 0x2d || // -\n c === 0x2e || // .\n c === 0x5f || // _\n c === 0x7e || // ~\n (c >= 0x30 && c <= 0x39) || // 0-9\n (c >= 0x41 && c <= 0x5a) || // a-z\n (c >= 0x61 && c <= 0x7a) || // A-Z\n (format === RFC1738 && (c === 0x28 || c === 0x29)) // ( )\n ) {\n arr[arr.length] = segment.charAt(i);\n continue;\n }\n\n if (c < 0x80) {\n arr[arr.length] = hex_table[c];\n continue;\n }\n\n if (c < 0x800) {\n arr[arr.length] = hex_table[0xc0 | (c >> 6)]! + hex_table[0x80 | (c & 0x3f)];\n continue;\n }\n\n if (c < 0xd800 || c >= 0xe000) {\n arr[arr.length] =\n hex_table[0xe0 | (c >> 12)]! + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)];\n continue;\n }\n\n i += 1;\n c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff));\n\n arr[arr.length] =\n hex_table[0xf0 | (c >> 18)]! +\n hex_table[0x80 | ((c >> 12) & 0x3f)] +\n hex_table[0x80 | ((c >> 6) & 0x3f)] +\n hex_table[0x80 | (c & 0x3f)];\n }\n\n out += arr.join('');\n }\n\n return out;\n};\n\nexport function compact(value: any) {\n const queue = [{ obj: { o: value }, prop: 'o' }];\n const refs = [];\n\n for (let i = 0; i < queue.length; ++i) {\n const item = queue[i];\n // @ts-ignore\n const obj = item.obj[item.prop];\n\n const keys = Object.keys(obj);\n for (let j = 0; j < keys.length; ++j) {\n const key = keys[j]!;\n const val = obj[key];\n if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {\n queue.push({ obj: obj, prop: key });\n refs.push(val);\n }\n }\n }\n\n compact_queue(queue);\n\n return value;\n}\n\nexport function is_regexp(obj: any) {\n return Object.prototype.toString.call(obj) === '[object RegExp]';\n}\n\nexport function is_buffer(obj: any) {\n if (!obj || typeof obj !== 'object') {\n return false;\n }\n\n return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));\n}\n\nexport function combine(a: any, b: any) {\n return [].concat(a, b);\n}\n\nexport function maybe_map<T>(val: T[], fn: (v: T) => T) {\n if (isArray(val)) {\n const mapped = [];\n for (let i = 0; i < val.length; i += 1) {\n mapped.push(fn(val[i]!));\n }\n return mapped;\n }\n return fn(val);\n}\n","import { encode, is_buffer, maybe_map, has } from './utils';\nimport { default_format, default_formatter, formatters } from './formats';\nimport type { NonNullableProperties, StringifyOptions } from './types';\nimport { isArray } from '../utils/values';\n\nconst array_prefix_generators = {\n brackets(prefix: PropertyKey) {\n return String(prefix) + '[]';\n },\n comma: 'comma',\n indices(prefix: PropertyKey, key: string) {\n return String(prefix) + '[' + key + ']';\n },\n repeat(prefix: PropertyKey) {\n return String(prefix);\n },\n};\n\nconst push_to_array = function (arr: any[], value_or_array: any) {\n Array.prototype.push.apply(arr, isArray(value_or_array) ? value_or_array : [value_or_array]);\n};\n\nlet toISOString;\n\nconst defaults = {\n addQueryPrefix: false,\n allowDots: false,\n allowEmptyArrays: false,\n arrayFormat: 'indices',\n charset: 'utf-8',\n charsetSentinel: false,\n delimiter: '&',\n encode: true,\n encodeDotInKeys: false,\n encoder: encode,\n encodeValuesOnly: false,\n format: default_format,\n formatter: default_formatter,\n /** @deprecated */\n indices: false,\n serializeDate(date) {\n return (toISOString ??= Function.prototype.call.bind(Date.prototype.toISOString))(date);\n },\n skipNulls: false,\n strictNullHandling: false,\n} as NonNullableProperties<StringifyOptions & { formatter: (typeof formatters)['RFC1738'] }>;\n\nfunction is_non_nullish_primitive(v: unknown): v is string | number | boolean | symbol | bigint {\n return (\n typeof v === 'string' ||\n typeof v === 'number' ||\n typeof v === 'boolean' ||\n typeof v === 'symbol' ||\n typeof v === 'bigint'\n );\n}\n\nconst sentinel = {};\n\nfunction inner_stringify(\n object: any,\n prefix: PropertyKey,\n generateArrayPrefix: StringifyOptions['arrayFormat'] | ((prefix: string, key: string) => string),\n commaRoundTrip: boolean,\n allowEmptyArrays: boolean,\n strictNullHandling: boolean,\n skipNulls: boolean,\n encodeDotInKeys: boolean,\n encoder: StringifyOptions['encoder'],\n filter: StringifyOptions['filter'],\n sort: StringifyOptions['sort'],\n allowDots: StringifyOptions['allowDots'],\n serializeDate: StringifyOptions['serializeDate'],\n format: StringifyOptions['format'],\n formatter: StringifyOptions['formatter'],\n encodeValuesOnly: boolean,\n charset: StringifyOptions['charset'],\n sideChannel: WeakMap<any, any>,\n) {\n let obj = object;\n\n let tmp_sc = sideChannel;\n let step = 0;\n let find_flag = false;\n while ((tmp_sc = tmp_sc.get(sentinel)) !== void undefined && !find_flag) {\n // Where object last appeared in the ref tree\n const pos = tmp_sc.get(object);\n step += 1;\n if (typeof pos !== 'undefined') {\n if (pos === step) {\n throw new RangeError('Cyclic object value');\n } else {\n find_flag = true; // Break while\n }\n }\n if (typeof tmp_sc.get(sentinel) === 'undefined') {\n step = 0;\n }\n }\n\n if (typeof filter === 'function') {\n obj = filter(prefix, obj);\n } else if (obj instanceof Date) {\n obj = serializeDate?.(obj);\n } else if (generateArrayPrefix === 'comma' && isArray(obj)) {\n obj = maybe_map(obj, function (value) {\n if (value instanceof Date) {\n return serializeDate?.(value);\n }\n return value;\n });\n }\n\n if (obj === null) {\n if (strictNullHandling) {\n return encoder && !encodeValuesOnly ?\n // @ts-expect-error\n encoder(prefix, defaults.encoder, charset, 'key', format)\n : prefix;\n }\n\n obj = '';\n }\n\n if (is_non_nullish_primitive(obj) || is_buffer(obj)) {\n if (encoder) {\n const key_value =\n encodeValuesOnly ? prefix\n // @ts-expect-error\n : encoder(prefix, defaults.encoder, charset, 'key', format);\n return [\n formatter?.(key_value) +\n '=' +\n // @ts-expect-error\n formatter?.(encoder(obj, defaults.encoder, charset, 'value', format)),\n ];\n }\n return [formatter?.(prefix) + '=' + formatter?.(String(obj))];\n }\n\n const values: string[] = [];\n\n if (typeof obj === 'undefined') {\n return values;\n }\n\n let obj_keys;\n if (generateArrayPrefix === 'comma' && isArray(obj)) {\n // we need to join elements in\n if (encodeValuesOnly && encoder) {\n // @ts-expect-error values only\n obj = maybe_map(obj, encoder);\n }\n obj_keys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];\n } else if (isArray(filter)) {\n obj_keys = filter;\n } else {\n const keys = Object.keys(obj);\n obj_keys = sort ? keys.sort(sort) : keys;\n }\n\n const encoded_prefix = encodeDotInKeys ? String(prefix).replace(/\\./g, '%2E') : String(prefix);\n\n const adjusted_prefix =\n commaRoundTrip && isArray(obj) && obj.length === 1 ? encoded_prefix + '[]' : encoded_prefix;\n\n if (allowEmptyArrays && isArray(obj) && obj.length === 0) {\n return adjusted_prefix + '[]';\n }\n\n for (let j = 0; j < obj_keys.length; ++j) {\n const key = obj_keys[j];\n const value =\n // @ts-ignore\n typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key as any];\n\n if (skipNulls && value === null) {\n continue;\n }\n\n // @ts-ignore\n const encoded_key = allowDots && encodeDotInKeys ? (key as any).replace(/\\./g, '%2E') : key;\n const key_prefix =\n isArray(obj) ?\n typeof generateArrayPrefix === 'function' ?\n generateArrayPrefix(adjusted_prefix, encoded_key)\n : adjusted_prefix\n : adjusted_prefix + (allowDots ? '.' + encoded_key : '[' + encoded_key + ']');\n\n sideChannel.set(object, step);\n const valueSideChannel = new WeakMap();\n valueSideChannel.set(sentinel, sideChannel);\n push_to_array(\n values,\n inner_stringify(\n value,\n key_prefix,\n generateArrayPrefix,\n commaRoundTrip,\n allowEmptyArrays,\n strictNullHandling,\n skipNulls,\n encodeDotInKeys,\n // @ts-ignore\n generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,\n filter,\n sort,\n allowDots,\n serializeDate,\n format,\n formatter,\n encodeValuesOnly,\n charset,\n valueSideChannel,\n ),\n );\n }\n\n return values;\n}\n\nfunction normalize_stringify_options(\n opts: StringifyOptions = defaults,\n): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {\n if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {\n throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');\n }\n\n if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {\n throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');\n }\n\n if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {\n throw new TypeError('Encoder has to be a function.');\n }\n\n const charset = opts.charset || defaults.charset;\n if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {\n throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');\n }\n\n let format = default_format;\n if (typeof opts.format !== 'undefined') {\n if (!has(formatters, opts.format)) {\n throw new TypeError('Unknown format option provided.');\n }\n format = opts.format;\n }\n const formatter = formatters[format];\n\n let filter = defaults.filter;\n if (typeof opts.filter === 'function' || isArray(opts.filter)) {\n filter = opts.filter;\n }\n\n let arrayFormat: StringifyOptions['arrayFormat'];\n if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {\n arrayFormat = opts.arrayFormat;\n } else if ('indices' in opts) {\n arrayFormat = opts.indices ? 'indices' : 'repeat';\n } else {\n arrayFormat = defaults.arrayFormat;\n }\n\n if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {\n throw new TypeError('`commaRoundTrip` must be a boolean, or absent');\n }\n\n const allowDots =\n typeof opts.allowDots === 'undefined' ?\n !!opts.encodeDotInKeys === true ?\n true\n : defaults.allowDots\n : !!opts.allowDots;\n\n return {\n addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,\n // @ts-ignore\n allowDots: allowDots,\n allowEmptyArrays:\n typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,\n arrayFormat: arrayFormat,\n charset: charset,\n charsetSentinel:\n typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,\n commaRoundTrip: !!opts.commaRoundTrip,\n delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,\n encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,\n encodeDotInKeys:\n typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,\n encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,\n encodeValuesOnly:\n typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,\n filter: filter,\n format: format,\n formatter: formatter,\n serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,\n skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,\n // @ts-ignore\n sort: typeof opts.sort === 'function' ? opts.sort : null,\n strictNullHandling:\n typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling,\n };\n}\n\nexport function stringify(object: any, opts: StringifyOptions = {}) {\n let obj = object;\n const options = normalize_stringify_options(opts);\n\n let obj_keys: PropertyKey[] | undefined;\n let filter;\n\n if (typeof options.filter === 'function') {\n filter = options.filter;\n obj = filter('', obj);\n } else if (isArray(options.filter)) {\n filter = options.filter;\n obj_keys = filter;\n }\n\n const keys: string[] = [];\n\n if (typeof obj !== 'object' || obj === null) {\n return '';\n }\n\n const generateArrayPrefix = array_prefix_generators[options.arrayFormat];\n const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;\n\n if (!obj_keys) {\n obj_keys = Object.keys(obj);\n }\n\n if (options.sort) {\n obj_keys.sort(options.sort);\n }\n\n const sideChannel = new WeakMap();\n for (let i = 0; i < obj_keys.length; ++i) {\n const key = obj_keys[i]!;\n\n if (options.skipNulls && obj[key] === null) {\n continue;\n }\n push_to_array(\n keys,\n inner_stringify(\n obj[key],\n key,\n // @ts-expect-error\n generateArrayPrefix,\n commaRoundTrip,\n options.allowEmptyArrays,\n options.strictNullHandling,\n options.skipNulls,\n options.encodeDotInKeys,\n options.encode ? options.encoder : null,\n options.filter,\n options.sort,\n options.allowDots,\n options.serializeDate,\n options.format,\n options.formatter,\n options.encodeValuesOnly,\n options.charset,\n sideChannel,\n ),\n );\n }\n\n const joined = keys.join(options.delimiter);\n let prefix = options.addQueryPrefix === true ? '?' : '';\n\n if (options.charsetSentinel) {\n if (options.charset === 'iso-8859-1') {\n // encodeURIComponent('✓'), the \"numeric entity\" representation of a checkmark\n prefix += 'utf8=%26%2310003%3B&';\n } else {\n // encodeURIComponent('✓')\n prefix += 'utf8=%E2%9C%93&';\n }\n }\n\n return joined.length > 0 ? prefix + joined : '';\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport * as qs from '../qs/stringify';\n\nexport function stringifyQuery(query: object | Record<string, unknown>) {\n return qs.stringify(query, { arrayFormat: 'brackets' });\n}\n","export function concatBytes(buffers: Uint8Array[]): Uint8Array {\n let length = 0;\n for (const buffer of buffers) {\n length += buffer.length;\n }\n const output = new Uint8Array(length);\n let index = 0;\n for (const buffer of buffers) {\n output.set(buffer, index);\n index += buffer.length;\n }\n\n return output;\n}\n\nlet encodeUTF8_: (str: string) => Uint8Array;\nexport function encodeUTF8(str: string) {\n let encoder;\n return (\n encodeUTF8_ ??\n ((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))\n )(str);\n}\n\nlet decodeUTF8_: (bytes: Uint8Array) => string;\nexport function decodeUTF8(bytes: Uint8Array) {\n let decoder;\n return (\n decodeUTF8_ ??\n ((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))\n )(bytes);\n}\n","import { concatBytes, decodeUTF8, encodeUTF8 } from '../utils/bytes';\n\nexport type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;\n\n/**\n * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally\n * reading lines from text.\n *\n * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258\n */\nexport class LineDecoder {\n // prettier-ignore\n static NEWLINE_CHARS = new Set(['\\n', '\\r']);\n static NEWLINE_REGEXP = /\\r\\n|[\\n\\r]/g;\n\n #buffer: Uint8Array;\n #carriageReturnIndex: number | null;\n\n constructor() {\n this.#buffer = new Uint8Array();\n this.#carriageReturnIndex = null;\n }\n\n decode(chunk: Bytes): string[] {\n if (chunk == null) {\n return [];\n }\n\n const binaryChunk =\n chunk instanceof ArrayBuffer ? new Uint8Array(chunk)\n : typeof chunk === 'string' ? encodeUTF8(chunk)\n : chunk;\n\n this.#buffer = concatBytes([this.#buffer, binaryChunk]);\n\n const lines: string[] = [];\n let patternIndex;\n while ((patternIndex = findNewlineIndex(this.#buffer, this.#carriageReturnIndex)) != null) {\n if (patternIndex.carriage && this.#carriageReturnIndex == null) {\n // skip until we either get a corresponding `\\n`, a new `\\r` or nothing\n this.#carriageReturnIndex = patternIndex.index;\n continue;\n }\n\n // we got double \\r or \\rtext\\n\n if (\n this.#carriageReturnIndex != null &&\n (patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)\n ) {\n lines.push(decodeUTF8(this.#buffer.subarray(0, this.#carriageReturnIndex - 1)));\n this.#buffer = this.#buffer.subarray(this.#carriageReturnIndex);\n this.#carriageReturnIndex = null;\n continue;\n }\n\n const endIndex =\n this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;\n\n const line = decodeUTF8(this.#buffer.subarray(0, endIndex));\n lines.push(line);\n\n this.#buffer = this.#buffer.subarray(patternIndex.index);\n this.#carriageReturnIndex = null;\n }\n\n return lines;\n }\n\n flush(): string[] {\n if (!this.#buffer.length) {\n return [];\n }\n return this.decode('\\n');\n }\n}\n\n/**\n * This function searches the buffer for the end patterns, (\\r or \\n)\n * and returns an object with the index preceding the matched newline and the\n * index after the newline char. `null` is returned if no new line is found.\n *\n * ```ts\n * findNewLineIndex('abc\\ndef') -> { preceding: 2, index: 3 }\n * ```\n */\nfunction findNewlineIndex(\n buffer: Uint8Array,\n startIndex: number | null,\n): { preceding: number; index: number; carriage: boolean } | null {\n const newline = 0x0a; // \\n\n const carriage = 0x0d; // \\r\n\n for (let i = startIndex ?? 0; i < buffer.length; i++) {\n if (buffer[i] === newline) {\n return { preceding: i, index: i + 1, carriage: false };\n }\n\n if (buffer[i] === carriage) {\n return { preceding: i, index: i + 1, carriage: true };\n }\n }\n\n return null;\n}\n\nexport function findDoubleNewlineIndex(buffer: Uint8Array): number {\n // This function searches the buffer for the end patterns (\\r\\r, \\n\\n, \\r\\n\\r\\n)\n // and returns the index right after the first occurrence of any pattern,\n // or -1 if none of the patterns are found.\n const newline = 0x0a; // \\n\n const carriage = 0x0d; // \\r\n\n for (let i = 0; i < buffer.length - 1; i++) {\n if (buffer[i] === newline && buffer[i + 1] === newline) {\n // \\n\\n\n return i + 2;\n }\n if (buffer[i] === carriage && buffer[i + 1] === carriage) {\n // \\r\\r\n return i + 2;\n }\n if (\n buffer[i] === carriage &&\n buffer[i + 1] === newline &&\n i + 3 < buffer.length &&\n buffer[i + 2] === carriage &&\n buffer[i + 3] === newline\n ) {\n // \\r\\n\\r\\n\n return i + 4;\n }\n }\n\n return -1;\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { hasOwn } from './values';\nimport { type OpenAI } from '../../client';\nimport { RequestOptions } from '../request-options';\n\ntype LogFn = (message: string, ...rest: unknown[]) => void;\nexport type Logger = {\n error: LogFn;\n warn: LogFn;\n info: LogFn;\n debug: LogFn;\n};\nexport type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';\n\nconst levelNumbers = {\n off: 0,\n error: 200,\n warn: 300,\n info: 400,\n debug: 500,\n};\n\nexport const parseLogLevel = (\n maybeLevel: string | undefined,\n sourceName: string,\n client: OpenAI,\n): LogLevel | undefined => {\n if (!maybeLevel) {\n return undefined;\n }\n if (hasOwn(levelNumbers, maybeLevel)) {\n return maybeLevel;\n }\n loggerFor(client).warn(\n `${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(\n Object.keys(levelNumbers),\n )}`,\n );\n return undefined;\n};\n\nfunction noop() {}\n\nfunction makeLogFn(fnLevel: keyof Logger, logger: Logger | undefined, logLevel: LogLevel) {\n if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {\n return noop;\n } else {\n // Don't wrap logger functions, we want the stacktrace intact!\n return logger[fnLevel].bind(logger);\n }\n}\n\nconst noopLogger = {\n error: noop,\n warn: noop,\n info: noop,\n debug: noop,\n};\n\nlet cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();\n\nexport function loggerFor(client: OpenAI): Logger {\n const logger = client.logger;\n const logLevel = client.logLevel ?? 'off';\n if (!logger) {\n return noopLogger;\n }\n\n const cachedLogger = cachedLoggers.get(logger);\n if (cachedLogger && cachedLogger[0] === logLevel) {\n return cachedLogger[1];\n }\n\n const levelLogger = {\n error: makeLogFn('error', logger, logLevel),\n warn: makeLogFn('warn', logger, logLevel),\n info: makeLogFn('info', logger, logLevel),\n debug: makeLogFn('debug', logger, logLevel),\n };\n\n cachedLoggers.set(logger, [logLevel, levelLogger]);\n\n return levelLogger;\n}\n\nexport const formatRequestDetails = (details: {\n options?: RequestOptions | undefined;\n headers?: Headers | Record<string, string> | undefined;\n retryOfRequestLogID?: string | undefined;\n retryOf?: string | undefined;\n url?: string | undefined;\n status?: number | undefined;\n method?: string | undefined;\n durationMs?: number | undefined;\n message?: unknown;\n body?: unknown;\n}) => {\n if (details.options) {\n details.options = { ...details.options };\n delete details.options['headers']; // redundant + leaks internals\n }\n if (details.headers) {\n details.headers = Object.fromEntries(\n (details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(\n ([name, value]) => [\n name,\n (\n name.toLowerCase() === 'authorization' ||\n name.toLowerCase() === 'cookie' ||\n name.toLowerCase() === 'set-cookie'\n ) ?\n '***'\n : value,\n ],\n ),\n );\n }\n if ('retryOfRequestLogID' in details) {\n if (details.retryOfRequestLogID) {\n details.retryOf = details.retryOfRequestLogID;\n }\n delete details.retryOfRequestLogID;\n }\n return details;\n};\n","import { OpenAIError } from './error';\nimport { type ReadableStream } from '../internal/shim-types';\nimport { makeReadableStream } from '../internal/shims';\nimport { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';\nimport { ReadableStreamToAsyncIterable } from '../internal/shims';\nimport { isAbortError } from '../internal/errors';\nimport { encodeUTF8 } from '../internal/utils/bytes';\nimport { loggerFor } from '../internal/utils/log';\nimport type { OpenAI } from '../client';\n\nimport { APIError } from './error';\n\ntype Bytes = string | ArrayBuffer | Uint8Array | null | undefined;\n\nexport type ServerSentEvent = {\n event: string | null;\n data: string;\n raw: string[];\n};\n\nexport class Stream<Item> implements AsyncIterable<Item> {\n controller: AbortController;\n #client: OpenAI | undefined;\n\n constructor(\n private iterator: () => AsyncIterator<Item>,\n controller: AbortController,\n client?: OpenAI,\n ) {\n this.controller = controller;\n this.#client = client;\n }\n\n static fromSSEResponse<Item>(\n response: Response,\n controller: AbortController,\n client?: OpenAI,\n synthesizeEventData?: boolean,\n ): Stream<Item> {\n let consumed = false;\n const logger = client ? loggerFor(client) : console;\n\n async function* iterator(): AsyncIterator<Item, any, undefined> {\n if (consumed) {\n throw new OpenAIError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');\n }\n consumed = true;\n let done = false;\n try {\n for await (const sse of _iterSSEMessages(response, controller)) {\n if (done) continue;\n\n if (sse.data.startsWith('[DONE]')) {\n done = true;\n continue;\n }\n\n if (sse.event === null || !sse.event.startsWith('thread.')) {\n let data;\n\n try {\n data = JSON.parse(sse.data) as any;\n } catch (e) {\n logger.error(`Could not parse message into JSON:`, sse.data);\n logger.error(`From chunk:`, sse.raw);\n throw e;\n }\n\n if (data && data.error) {\n throw new APIError(undefined, data.error, undefined, response.headers);\n }\n\n yield synthesizeEventData ? { event: sse.event, data } : data;\n } else {\n let data;\n try {\n data = JSON.parse(sse.data);\n } catch (e) {\n console.error(`Could not parse message into JSON:`, sse.data);\n console.error(`From chunk:`, sse.raw);\n throw e;\n }\n // TODO: Is this where the error should be thrown?\n if (sse.event == 'error') {\n throw new APIError(undefined, data.error, data.message, undefined);\n }\n yield { event: sse.event, data: data } as any;\n }\n }\n done = true;\n } catch (e) {\n // If the user calls `stream.controller.abort()`, we should exit without throwing.\n if (isAbortError(e)) return;\n throw e;\n } finally {\n // If the user `break`s, abort the ongoing request.\n if (!done) controller.abort();\n }\n }\n\n return new Stream(iterator, controller, client);\n }\n\n /**\n * Generates a Stream from a newline-separated ReadableStream\n * where each item is a JSON value.\n */\n static fromReadableStream<Item>(\n readableStream: ReadableStream,\n controller: AbortController,\n client?: OpenAI,\n ): Stream<Item> {\n let consumed = false;\n\n async function* iterLines(): AsyncGenerator<string, void, unknown> {\n const lineDecoder = new LineDecoder();\n\n const iter = ReadableStreamToAsyncIterable<Bytes>(readableStream);\n for await (const chunk of iter) {\n for (const line of lineDecoder.decode(chunk)) {\n yield line;\n }\n }\n\n for (const line of lineDecoder.flush()) {\n yield line;\n }\n }\n\n async function* iterator(): AsyncIterator<Item, any, undefined> {\n if (consumed) {\n throw new OpenAIError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');\n }\n consumed = true;\n let done = false;\n try {\n for await (const line of iterLines()) {\n if (done) continue;\n if (line) yield JSON.parse(line) as Item;\n }\n done = true;\n } catch (e) {\n // If the user calls `stream.controller.abort()`, we should exit without throwing.\n if (isAbortError(e)) return;\n throw e;\n } finally {\n // If the user `break`s, abort the ongoing request.\n if (!done) controller.abort();\n }\n }\n\n return new Stream(iterator, controller, client);\n }\n\n [Symbol.asyncIterator](): AsyncIterator<Item> {\n return this.iterator();\n }\n\n /**\n * Splits the stream into two streams which can be\n * independently read from at different speeds.\n */\n tee(): [Stream<Item>, Stream<Item>] {\n const left: Array<Promise<IteratorResult<Item>>> = [];\n const right: Array<Promise<IteratorResult<Item>>> = [];\n const iterator = this.iterator();\n\n const teeIterator = (queue: Array<Promise<IteratorResult<Item>>>): AsyncIterator<Item> => {\n return {\n next: () => {\n if (queue.length === 0) {\n const result = iterator.next();\n left.push(result);\n right.push(result);\n }\n return queue.shift()!;\n },\n };\n };\n\n return [\n new Stream(() => teeIterator(left), this.controller, this.#client),\n new Stream(() => teeIterator(right), this.controller, this.#client),\n ];\n }\n\n /**\n * Converts this stream to a newline-separated ReadableStream of\n * JSON stringified values in the stream\n * which can be turned back into a Stream with `Stream.fromReadableStream()`.\n */\n toReadableStream(): ReadableStream {\n const self = this;\n let iter: AsyncIterator<Item>;\n\n return makeReadableStream({\n async start() {\n iter = self[Symbol.asyncIterator]();\n },\n async pull(ctrl: any) {\n try {\n const { value, done } = await iter.next();\n if (done) return ctrl.close();\n\n const bytes = encodeUTF8(JSON.stringify(value) + '\\n');\n\n ctrl.enqueue(bytes);\n } catch (err) {\n ctrl.error(err);\n }\n },\n async cancel() {\n await iter.return?.();\n },\n });\n }\n}\n\nexport async function* _iterSSEMessages(\n response: Response,\n controller: AbortController,\n): AsyncGenerator<ServerSentEvent, void, unknown> {\n if (!response.body) {\n controller.abort();\n if (\n typeof (globalThis as any).navigator !== 'undefined' &&\n (globalThis as any).navigator.product === 'ReactNative'\n ) {\n throw new OpenAIError(\n `The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`,\n );\n }\n throw new OpenAIError(`Attempted to iterate over a response with no body`);\n }\n\n const sseDecoder = new SSEDecoder();\n const lineDecoder = new LineDecoder();\n\n const iter = ReadableStreamToAsyncIterable<Bytes>(response.body);\n for await (const sseChunk of iterSSEChunks(iter)) {\n for (const line of lineDecoder.decode(sseChunk)) {\n const sse = sseDecoder.decode(line);\n if (sse) yield sse;\n }\n }\n\n for (const line of lineDecoder.flush()) {\n const sse = sseDecoder.decode(line);\n if (sse) yield sse;\n }\n}\n\n/**\n * Given an async iterable iterator, iterates over it and yields full\n * SSE chunks, i.e. yields when a double new-line is encountered.\n */\nasync function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGenerator<Uint8Array> {\n let data = new Uint8Array();\n\n for await (const chunk of iterator) {\n if (chunk == null) {\n continue;\n }\n\n const binaryChunk =\n chunk instanceof ArrayBuffer ? new Uint8Array(chunk)\n : typeof chunk === 'string' ? encodeUTF8(chunk)\n : chunk;\n\n let newData = new Uint8Array(data.length + binaryChunk.length);\n newData.set(data);\n newData.set(binaryChunk, data.length);\n data = newData;\n\n let patternIndex;\n while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {\n yield data.slice(0, patternIndex);\n data = data.slice(patternIndex);\n }\n }\n\n if (data.length > 0) {\n yield data;\n }\n}\n\nclass SSEDecoder {\n private data: string[];\n private event: string | null;\n private chunks: string[];\n\n constructor() {\n this.event = null;\n this.data = [];\n this.chunks = [];\n }\n\n decode(line: string) {\n if (line.endsWith('\\r')) {\n line = line.substring(0, line.length - 1);\n }\n\n if (!line) {\n // empty line and we didn't previously encounter any messages\n if (!this.event && !this.data.length) return null;\n\n const sse: ServerSentEvent = {\n event: this.event,\n data: this.data.join('\\n'),\n raw: this.chunks,\n };\n\n this.event = null;\n this.data = [];\n this.chunks = [];\n\n return sse;\n }\n\n this.chunks.push(line);\n\n if (line.startsWith(':')) {\n return null;\n }\n\n let [fieldname, _, value] = partition(line, ':');\n\n if (value.startsWith(' ')) {\n value = value.substring(1);\n }\n\n if (fieldname === 'event') {\n this.event = value;\n } else if (fieldname === 'data') {\n this.data.push(value);\n }\n\n return null;\n }\n}\n\nfunction partition(str: string, delimiter: string): [string, string, string] {\n const index = str.indexOf(delimiter);\n if (index !== -1) {\n return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];\n }\n\n return [str, '', ''];\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { FinalRequestOptions } from './request-options';\nimport { Stream } from '../core/streaming';\nimport { type OpenAI } from '../client';\nimport { formatRequestDetails, loggerFor } from './utils/log';\nimport type { AbstractPage } from '../pagination';\n\nexport type APIResponseProps = {\n response: Response;\n options: FinalRequestOptions;\n controller: AbortController;\n requestLogID: string;\n retryOfRequestLogID: string | undefined;\n startTime: number;\n};\n\nexport async function defaultParseResponse<T>(\n client: OpenAI,\n props: APIResponseProps,\n): Promise<WithRequestID<T>> {\n const { response, requestLogID, retryOfRequestLogID, startTime } = props;\n const body = await (async () => {\n if (props.options.stream) {\n loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);\n\n // Note: there is an invariant here that isn't represented in the type system\n // that if you set `stream: true` the response type must also be `Stream<T>`\n\n if (props.options.__streamClass) {\n return props.options.__streamClass.fromSSEResponse(\n response,\n props.controller,\n client,\n props.options.__synthesizeEventData,\n ) as any;\n }\n\n return Stream.fromSSEResponse(\n response,\n props.controller,\n client,\n props.options.__synthesizeEventData,\n ) as any;\n }\n\n // fetch refuses to read the body when the status code is 204.\n if (response.status === 204) {\n return null as T;\n }\n\n if (props.options.__binaryResponse) {\n return response as unknown as T;\n }\n\n const contentType = response.headers.get('content-type');\n const mediaType = contentType?.split(';')[0]?.trim();\n const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');\n if (isJSON) {\n const contentLength = response.headers.get('content-length');\n if (contentLength === '0') {\n // if there is no content we can't do anything\n return undefined as T;\n }\n\n const json = await response.json();\n return addRequestID(json as T, response);\n }\n\n const text = await response.text();\n return text as unknown as T;\n })();\n loggerFor(client).debug(\n `[${requestLogID}] response parsed`,\n formatRequestDetails({\n retryOfRequestLogID,\n url: response.url,\n status: response.status,\n body,\n durationMs: Date.now() - startTime,\n }),\n );\n return body;\n}\n\nexport type WithRequestID<T> =\n T extends Array<any> | Response | AbstractPage<any> ? T\n : T extends Record<string, any> ? T & { _request_id?: string | null }\n : T;\n\nexport function addRequestID<T>(value: T, response: Response): WithRequestID<T> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return value as WithRequestID<T>;\n }\n\n return Object.defineProperty(value, '_request_id', {\n value: response.headers.get('x-request-id'),\n enumerable: false,\n }) as WithRequestID<T>;\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { type OpenAI } from '../client';\n\nimport { type PromiseOrValue } from '../internal/types';\nimport {\n type APIResponseProps,\n defaultParseResponse,\n type WithRequestID,\n addRequestID,\n} from '../internal/parse';\n\n/**\n * A subclass of `Promise` providing additional helper methods\n * for interacting with the SDK.\n */\nexport class APIPromise<T> extends Promise<WithRequestID<T>> {\n private parsedPromise: Promise<WithRequestID<T>> | undefined;\n #client: OpenAI;\n\n constructor(\n client: OpenAI,\n private responsePromise: Promise<APIResponseProps>,\n private parseResponse: (\n client: OpenAI,\n props: APIResponseProps,\n ) => PromiseOrValue<WithRequestID<T>> = defaultParseResponse,\n ) {\n super((resolve) => {\n // this is maybe a bit weird but this has to be a no-op to not implicitly\n // parse the response body; instead .then, .catch, .finally are overridden\n // to parse the response\n resolve(null as any);\n });\n this.#client = client;\n }\n\n _thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {\n return new APIPromise(this.#client, this.responsePromise, async (client, props) =>\n addRequestID(transform(await this.parseResponse(client, props), props), props.response),\n );\n }\n\n /**\n * Gets the raw `Response` instance instead of parsing the response\n * data.\n *\n * If you want to parse the response body but still get the `Response`\n * instance, you can use {@link withResponse()}.\n *\n * 👋 Getting the wrong TypeScript type for `Response`?\n * Try setting `\"moduleResolution\": \"NodeNext\"` or add `\"lib\": [\"DOM\"]`\n * to your `tsconfig.json`.\n */\n asResponse(): Promise<Response> {\n return this.responsePromise.then((p) => p.response);\n }\n\n /**\n * Gets the parsed response data, the raw `Response` instance and the ID of the request,\n * returned via the X-Request-ID header which is useful for debugging requests and reporting\n * issues to OpenAI.\n *\n * If you just want to get the raw `Response` instance without parsing it,\n * you can use {@link asResponse()}.\n *\n * 👋 Getting the wrong TypeScript type for `Response`?\n * Try setting `\"moduleResolution\": \"NodeNext\"` or add `\"lib\": [\"DOM\"]`\n * to your `tsconfig.json`.\n */\n async withResponse(): Promise<{ data: T; response: Response; request_id: string | null }> {\n const [data, response] = await Promise.all([this.parse(), this.asResponse()]);\n return { data, response, request_id: response.headers.get('x-request-id') };\n }\n\n private parse(): Promise<WithRequestID<T>> {\n if (!this.parsedPromise) {\n this.parsedPromise = this.responsePromise.then((data) =>\n this.parseResponse(this.#client, data),\n ) as any as Promise<WithRequestID<T>>;\n }\n return this.parsedPromise;\n }\n\n override then<TResult1 = WithRequestID<T>, TResult2 = never>(\n onfulfilled?: ((value: WithRequestID<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): Promise<TResult1 | TResult2> {\n return this.parse().then(onfulfilled, onrejected);\n }\n\n override catch<TResult = never>(\n onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,\n ): Promise<WithRequestID<T> | TResult> {\n return this.parse().catch(onrejected);\n }\n\n override finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>> {\n return this.parse().finally(onfinally);\n }\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { OpenAIError } from './error';\nimport { FinalRequestOptions } from '../internal/request-options';\nimport { defaultParseResponse, WithRequestID } from '../internal/parse';\nimport { APIPromise } from './api-promise';\nimport { type OpenAI } from '../client';\nimport { type APIResponseProps } from '../internal/parse';\nimport { maybeObj } from '../internal/utils/values';\n\nexport type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;\n\nexport abstract class AbstractPage<Item> implements AsyncIterable<Item> {\n #client: OpenAI;\n protected options: FinalRequestOptions;\n\n protected response: Response;\n protected body: unknown;\n\n constructor(client: OpenAI, response: Response, body: unknown, options: FinalRequestOptions) {\n this.#client = client;\n this.options = options;\n this.response = response;\n this.body = body;\n }\n\n abstract nextPageRequestOptions(): PageRequestOptions | null;\n\n abstract getPaginatedItems(): Item[];\n\n hasNextPage(): boolean {\n const items = this.getPaginatedItems();\n if (!items.length) return false;\n return this.nextPageRequestOptions() != null;\n }\n\n async getNextPage(): Promise<this> {\n const nextOptions = this.nextPageRequestOptions();\n if (!nextOptions) {\n throw new OpenAIError(\n 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',\n );\n }\n\n return await this.#client.requestAPIList(this.constructor as any, nextOptions);\n }\n\n async *iterPages(): AsyncGenerator<this> {\n let page: this = this;\n yield page;\n while (page.hasNextPage()) {\n page = await page.getNextPage();\n yield page;\n }\n }\n\n async *[Symbol.asyncIterator](): AsyncGenerator<Item> {\n for await (const page of this.iterPages()) {\n for (const item of page.getPaginatedItems()) {\n yield item;\n }\n }\n }\n}\n\n/**\n * This subclass of Promise will resolve to an instantiated Page once the request completes.\n *\n * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:\n *\n * for await (const item of client.items.list()) {\n * console.log(item)\n * }\n */\nexport class PagePromise<\n PageClass extends AbstractPage<Item>,\n Item = ReturnType<PageClass['getPaginatedItems']>[number],\n >\n extends APIPromise<PageClass>\n implements AsyncIterable<Item>\n{\n constructor(\n client: OpenAI,\n request: Promise<APIResponseProps>,\n Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,\n ) {\n super(\n client,\n request,\n async (client, props) =>\n new Page(\n client,\n props.response,\n await defaultParseResponse(client, props),\n props.options,\n ) as WithRequestID<PageClass>,\n );\n }\n\n /**\n * Allow auto-paginating iteration on an unawaited list call, eg:\n *\n * for await (const item of client.items.list()) {\n * console.log(item)\n * }\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<Item> {\n const page = await this;\n for await (const item of page) {\n yield item;\n }\n }\n}\n\nexport interface PageResponse<Item> {\n data: Array<Item>;\n\n object: string;\n}\n\n/**\n * Note: no pagination actually occurs yet, this is for forwards-compatibility.\n */\nexport class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {\n data: Array<Item>;\n\n object: string;\n\n constructor(client: OpenAI, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {\n super(client, response, body, options);\n\n this.data = body.data || [];\n this.object = body.object;\n }\n\n getPaginatedItems(): Item[] {\n return this.data ?? [];\n }\n\n nextPageRequestOptions(): PageRequestOptions | null {\n return null;\n }\n}\n\nexport interface CursorPageResponse<Item> {\n data: Array<Item>;\n\n has_more: boolean;\n}\n\nexport interface CursorPageParams {\n after?: string;\n\n limit?: number;\n}\n\nexport class CursorPage<Item extends { id: string }>\n extends AbstractPage<Item>\n implements CursorPageResponse<Item>\n{\n data: Array<Item>;\n\n has_more: boolean;\n\n constructor(\n client: OpenAI,\n response: Response,\n body: CursorPageResponse<Item>,\n options: FinalRequestOptions,\n ) {\n super(client, response, body, options);\n\n this.data = body.data || [];\n this.has_more = body.has_more || false;\n }\n\n getPaginatedItems(): Item[] {\n return this.data ?? [];\n }\n\n override hasNextPage(): boolean {\n if (this.has_more === false) {\n return false;\n }\n\n return super.hasNextPage();\n }\n\n nextPageRequestOptions(): PageRequestOptions | null {\n const data = this.getPaginatedItems();\n const id = data[data.length - 1]?.id;\n if (!id) {\n return null;\n }\n\n return {\n ...this.options,\n query: {\n ...maybeObj(this.options.query),\n after: id,\n },\n };\n }\n}\n\nexport interface ConversationCursorPageResponse<Item> {\n data: Array<Item>;\n\n has_more: boolean;\n\n last_id: string;\n}\n\nexport interface ConversationCursorPageParams {\n after?: string;\n\n limit?: number;\n}\n\nexport class ConversationCursorPage<Item>\n extends AbstractPage<Item>\n implements ConversationCursorPageResponse<Item>\n{\n data: Array<Item>;\n\n has_more: boolean;\n\n last_id: string;\n\n constructor(\n client: OpenAI,\n response: Response,\n body: ConversationCursorPageResponse<Item>,\n options: FinalRequestOptions,\n ) {\n super(client, response, body, options);\n\n this.data = body.data || [];\n this.has_more = body.has_more || false;\n this.last_id = body.last_id || '';\n }\n\n getPaginatedItems(): Item[] {\n return this.data ?? [];\n }\n\n override hasNextPage(): boolean {\n if (this.has_more === false) {\n return false;\n }\n\n return super.hasNextPage();\n }\n\n nextPageRequestOptions(): PageRequestOptions | null {\n const cursor = this.last_id;\n if (!cursor) {\n return null;\n }\n\n return {\n ...this.options,\n query: {\n ...maybeObj(this.options.query),\n after: cursor,\n },\n };\n }\n}\n","import { type RequestOptions } from './request-options';\nimport type { FilePropertyBag, Fetch } from './builtin-types';\nimport type { OpenAI } from '../client';\nimport { ReadableStreamFrom } from './shims';\n\nexport type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;\ntype FsReadStream = AsyncIterable<Uint8Array> & { path: string | { toString(): string } };\n\n// https://github.com/oven-sh/bun/issues/5980\ninterface BunFile extends Blob {\n readonly name?: string | undefined;\n}\n\nexport const checkFileSupport = () => {\n if (typeof File === 'undefined') {\n const { process } = globalThis as any;\n const isOldNode =\n typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;\n throw new Error(\n '`File` is not defined as a global, which is required for file uploads.' +\n (isOldNode ?\n \" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.\"\n : ''),\n );\n }\n};\n\n/**\n * Typically, this is a native \"File\" class.\n *\n * We provide the {@link toFile} utility to convert a variety of objects\n * into the File class.\n *\n * For convenience, you can also pass a fetch Response, or in Node,\n * the result of fs.createReadStream().\n */\nexport type Uploadable = File | Response | FsReadStream | BunFile;\n\n/**\n * Construct a `File` instance. This is used to ensure a helpful error is thrown\n * for environments that don't define a global `File` yet.\n */\nexport function makeFile(\n fileBits: BlobPart[],\n fileName: string | undefined,\n options?: FilePropertyBag,\n): File {\n checkFileSupport();\n return new File(fileBits as any, fileName ?? 'unknown_file', options);\n}\n\nexport function getName(value: any): string | undefined {\n return (\n (\n (typeof value === 'object' &&\n value !== null &&\n (('name' in value && value.name && String(value.name)) ||\n ('url' in value && value.url && String(value.url)) ||\n ('filename' in value && value.filename && String(value.filename)) ||\n ('path' in value && value.path && String(value.path)))) ||\n ''\n )\n .split(/[\\\\/]/)\n .pop() || undefined\n );\n}\n\nexport const isAsyncIterable = (value: any): value is AsyncIterable<any> =>\n value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';\n\n/**\n * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.\n * Otherwise returns the request as is.\n */\nexport const maybeMultipartFormRequestOptions = async (\n opts: RequestOptions,\n fetch: OpenAI | Fetch,\n): Promise<RequestOptions> => {\n if (!hasUploadableValue(opts.body)) return opts;\n\n return { ...opts, body: await createForm(opts.body, fetch) };\n};\n\ntype MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknown };\n\nexport const multipartFormRequestOptions = async (\n opts: MultipartFormRequestOptions,\n fetch: OpenAI | Fetch,\n): Promise<RequestOptions> => {\n return { ...opts, body: await createForm(opts.body, fetch) };\n};\n\nconst supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();\n\n/**\n * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending\n * properly-encoded form data, it just stringifies the object, resulting in a request body of \"[object FormData]\".\n * This function detects if the fetch function provided supports the global FormData object to avoid\n * confusing error messages later on.\n */\nfunction supportsFormData(fetchObject: OpenAI | Fetch): Promise<boolean> {\n const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;\n const cached = supportsFormDataMap.get(fetch);\n if (cached) return cached;\n const promise = (async () => {\n try {\n const FetchResponse = (\n 'Response' in fetch ?\n fetch.Response\n : (await fetch('data:,')).constructor) as typeof Response;\n const data = new FormData();\n if (data.toString() === (await new FetchResponse(data).text())) {\n return false;\n }\n return true;\n } catch {\n // avoid false negatives\n return true;\n }\n })();\n supportsFormDataMap.set(fetch, promise);\n return promise;\n}\n\nexport const createForm = async <T = Record<string, unknown>>(\n body: T | undefined,\n fetch: OpenAI | Fetch,\n): Promise<FormData> => {\n if (!(await supportsFormData(fetch))) {\n throw new TypeError(\n 'The provided fetch function does not support file uploads with the current global FormData class.',\n );\n }\n const form = new FormData();\n await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));\n return form;\n};\n\n// We check for Blob not File because Bun.File doesn't inherit from File,\n// but they both inherit from Blob and have a `name` property at runtime.\nconst isNamedBlob = (value: unknown) => value instanceof Blob && 'name' in value;\n\nconst isUploadable = (value: unknown) =>\n typeof value === 'object' &&\n value !== null &&\n (value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));\n\nconst hasUploadableValue = (value: unknown): boolean => {\n if (isUploadable(value)) return true;\n if (Array.isArray(value)) return value.some(hasUploadableValue);\n if (value && typeof value === 'object') {\n for (const k in value) {\n if (hasUploadableValue((value as any)[k])) return true;\n }\n }\n return false;\n};\n\nconst addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {\n if (value === undefined) return;\n if (value == null) {\n throw new TypeError(\n `Received null for \"${key}\"; to pass null in FormData, you must use the string 'null'`,\n );\n }\n\n // TODO: make nested formats configurable\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n form.append(key, String(value));\n } else if (value instanceof Response) {\n form.append(key, makeFile([await value.blob()], getName(value)));\n } else if (isAsyncIterable(value)) {\n form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value)));\n } else if (isNamedBlob(value)) {\n form.append(key, value, getName(value));\n } else if (Array.isArray(value)) {\n await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));\n } else if (typeof value === 'object') {\n await Promise.all(\n Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),\n );\n } else {\n throw new TypeError(\n `Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,\n );\n }\n};\n","import { BlobPart, getName, makeFile, isAsyncIterable } from './uploads';\nimport type { FilePropertyBag } from './builtin-types';\nimport { checkFileSupport } from './uploads';\n\ntype BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;\n\n/**\n * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.\n * Don't add arrayBuffer here, node-fetch doesn't have it\n */\ninterface BlobLike {\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */\n readonly size: number;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */\n readonly type: string;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */\n text(): Promise<string>;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */\n slice(start?: number, end?: number): BlobLike;\n}\n\n/**\n * This check adds the arrayBuffer() method type because it is available and used at runtime\n */\nconst isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>\n value != null &&\n typeof value === 'object' &&\n typeof value.size === 'number' &&\n typeof value.type === 'string' &&\n typeof value.text === 'function' &&\n typeof value.slice === 'function' &&\n typeof value.arrayBuffer === 'function';\n\n/**\n * Intended to match DOM File, node:buffer File, undici File, etc.\n */\ninterface FileLike extends BlobLike {\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */\n readonly lastModified: number;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */\n readonly name?: string | undefined;\n}\n\n/**\n * This check adds the arrayBuffer() method type because it is available and used at runtime\n */\nconst isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<ArrayBuffer> } =>\n value != null &&\n typeof value === 'object' &&\n typeof value.name === 'string' &&\n typeof value.lastModified === 'number' &&\n isBlobLike(value);\n\n/**\n * Intended to match DOM Response, node-fetch Response, undici Response, etc.\n */\nexport interface ResponseLike {\n url: string;\n blob(): Promise<BlobLike>;\n}\n\nconst isResponseLike = (value: any): value is ResponseLike =>\n value != null &&\n typeof value === 'object' &&\n typeof value.url === 'string' &&\n typeof value.blob === 'function';\n\nexport type ToFileInput =\n | FileLike\n | ResponseLike\n | Exclude<BlobLikePart, string>\n | AsyncIterable<BlobLikePart>;\n\n/**\n * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats\n * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts\n * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible\n * @param {Object=} options additional properties\n * @param {string=} options.type the MIME type of the content\n * @param {number=} options.lastModified the last modified timestamp\n * @returns a {@link File} with the given properties\n */\nexport async function toFile(\n value: ToFileInput | PromiseLike<ToFileInput>,\n name?: string | null | undefined,\n options?: FilePropertyBag | undefined,\n): Promise<File> {\n checkFileSupport();\n\n // If it's a promise, resolve it.\n value = await value;\n\n // If we've been given a `File` we don't need to do anything\n if (isFileLike(value)) {\n if (value instanceof File) {\n return value;\n }\n return makeFile([await value.arrayBuffer()], value.name);\n }\n\n if (isResponseLike(value)) {\n const blob = await value.blob();\n name ||= new URL(value.url).pathname.split(/[\\\\/]/).pop();\n\n return makeFile(await getBytes(blob), name, options);\n }\n\n const parts = await getBytes(value);\n\n name ||= getName(value);\n\n if (!options?.type) {\n const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);\n if (typeof type === 'string') {\n options = { ...options, type };\n }\n }\n\n return makeFile(parts, name, options);\n}\n\nasync function getBytes(value: BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>> {\n let parts: Array<BlobPart> = [];\n if (\n typeof value === 'string' ||\n ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.\n value instanceof ArrayBuffer\n ) {\n parts.push(value);\n } else if (isBlobLike(value)) {\n parts.push(value instanceof Blob ? value : await value.arrayBuffer());\n } else if (\n isAsyncIterable(value) // includes Readable, ReadableStream, etc.\n ) {\n for await (const chunk of value) {\n parts.push(...(await getBytes(chunk as BlobLikePart))); // TODO, consider validating?\n }\n } else {\n const constructor = value?.constructor?.name;\n throw new Error(\n `Unexpected data type: ${typeof value}${\n constructor ? `; constructor: ${constructor}` : ''\n }${propsForError(value)}`,\n );\n }\n\n return parts;\n}\n\nfunction propsForError(value: unknown): string {\n if (typeof value !== 'object' || value === null) return '';\n const props = Object.getOwnPropertyNames(value);\n return `; props: [${props.map((p) => `\"${p}\"`).join(', ')}]`;\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { OpenAI } from '../client';\n\nexport abstract class APIResource {\n protected _client: OpenAI;\n\n constructor(client: OpenAI) {\n this._client = client;\n }\n}\n","import { OpenAIError } from '../../core/error';\n\n/**\n * Percent-encode everything that isn't safe to have in a path without encoding safe chars.\n *\n * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:\n * > unreserved = ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\"\n * > sub-delims = \"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\" / \"*\" / \"+\" / \",\" / \";\" / \"=\"\n * > pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"\n */\nexport function encodeURIPath(str: string) {\n return str.replace(/[^A-Za-z0-9\\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);\n}\n\nconst EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));\n\nexport const createPathTagFunction = (pathEncoder = encodeURIPath) =>\n function path(statics: readonly string[], ...params: readonly unknown[]): string {\n // If there are no params, no processing is needed.\n if (statics.length === 1) return statics[0]!;\n\n let postPath = false;\n const invalidSegments = [];\n const path = statics.reduce((previousValue, currentValue, index) => {\n if (/[?#]/.test(currentValue)) {\n postPath = true;\n }\n const value = params[index];\n let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);\n if (\n index !== params.length &&\n (value == null ||\n (typeof value === 'object' &&\n // handle values from other realms\n value.toString ===\n Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)\n ?.toString))\n ) {\n encoded = value + '';\n invalidSegments.push({\n start: previousValue.length + currentValue.length,\n length: encoded.length,\n error: `Value of type ${Object.prototype.toString\n .call(value)\n .slice(8, -1)} is not a valid path parameter`,\n });\n }\n return previousValue + currentValue + (index === params.length ? '' : encoded);\n }, '');\n\n const pathOnly = path.split(/[?#]/, 1)[0]!;\n const invalidSegmentPattern = /(?<=^|\\/)(?:\\.|%2e){1,2}(?=\\/|$)/gi;\n let match;\n\n // Find all invalid segments\n while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {\n invalidSegments.push({\n start: match.index,\n length: match[0].length,\n error: `Value \"${match[0]}\" can\\'t be safely passed as a path parameter`,\n });\n }\n\n invalidSegments.sort((a, b) => a.start - b.start);\n\n if (invalidSegments.length > 0) {\n let lastEnd = 0;\n const underline = invalidSegments.reduce((acc, segment) => {\n const spaces = ' '.repeat(segment.start - lastEnd);\n const arrows = '^'.repeat(segment.length);\n lastEnd = segment.start + segment.length;\n return acc + spaces + arrows;\n }, '');\n\n throw new OpenAIError(\n `Path parameters result in path with invalid segments:\\n${invalidSegments\n .map((e) => e.error)\n .join('\\n')}\\n${path}\\n${underline}`,\n );\n }\n\n return path;\n };\n\n/**\n * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.\n */\nexport const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as CompletionsAPI from './completions';\nimport { ChatCompletionStoreMessagesPage } from './completions';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Given a list of messages comprising a conversation, the model will return a response.\n */\nexport class Messages extends APIResource {\n /**\n * Get the messages in a stored chat completion. Only Chat Completions that have\n * been created with the `store` parameter set to `true` will be returned.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const chatCompletionStoreMessage of client.chat.completions.messages.list(\n * 'completion_id',\n * )) {\n * // ...\n * }\n * ```\n */\n list(\n completionID: string,\n query: MessageListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage> {\n return this._client.getAPIList(\n path`/chat/completions/${completionID}/messages`,\n CursorPage<CompletionsAPI.ChatCompletionStoreMessage>,\n { query, ...options },\n );\n }\n}\n\nexport interface MessageListParams extends CursorPageParams {\n /**\n * Sort order for messages by timestamp. Use `asc` for ascending order or `desc`\n * for descending order. Defaults to `asc`.\n */\n order?: 'asc' | 'desc';\n}\n\nexport declare namespace Messages {\n export { type MessageListParams as MessageListParams };\n}\n\nexport { type ChatCompletionStoreMessagesPage };\n","import { ContentFilterFinishReasonError, LengthFinishReasonError, OpenAIError } from '../error';\nimport {\n ChatCompletion,\n ChatCompletionCreateParams,\n ChatCompletionCreateParamsBase,\n ChatCompletionFunctionTool,\n ChatCompletionMessage,\n ChatCompletionMessageFunctionToolCall,\n ChatCompletionStreamingToolRunnerParams,\n ChatCompletionStreamParams,\n ChatCompletionToolRunnerParams,\n ParsedChatCompletion,\n ParsedChoice,\n ParsedFunctionToolCall,\n} from '../resources/chat/completions';\nimport { type ResponseFormatTextJSONSchemaConfig } from '../resources/responses/responses';\nimport { ResponseFormatJSONSchema } from '../resources/shared';\n\ntype AnyChatCompletionCreateParams =\n | ChatCompletionCreateParams\n | ChatCompletionToolRunnerParams<any>\n | ChatCompletionStreamingToolRunnerParams<any>\n | ChatCompletionStreamParams;\n\ntype Unpacked<T> = T extends (infer U)[] ? U : T;\n\ntype ToolCall = Unpacked<ChatCompletionCreateParamsBase['tools']>;\n\nexport function isChatCompletionFunctionTool(tool: ToolCall): tool is ChatCompletionFunctionTool {\n return tool !== undefined && 'function' in tool && tool.function !== undefined;\n}\n\nexport type ExtractParsedContentFromParams<Params extends AnyChatCompletionCreateParams> =\n Params['response_format'] extends AutoParseableResponseFormat<infer P> ? P : null;\n\nexport type AutoParseableResponseFormat<ParsedT> = ResponseFormatJSONSchema & {\n __output: ParsedT; // type-level only\n\n $brand: 'auto-parseable-response-format';\n $parseRaw(content: string): ParsedT;\n};\n\nexport function makeParseableResponseFormat<ParsedT>(\n response_format: ResponseFormatJSONSchema,\n parser: (content: string) => ParsedT,\n): AutoParseableResponseFormat<ParsedT> {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: 'auto-parseable-response-format',\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj as AutoParseableResponseFormat<ParsedT>;\n}\n\nexport type AutoParseableTextFormat<ParsedT> = ResponseFormatTextJSONSchemaConfig & {\n __output: ParsedT; // type-level only\n\n $brand: 'auto-parseable-response-format';\n $parseRaw(content: string): ParsedT;\n};\n\nexport function makeParseableTextFormat<ParsedT>(\n response_format: ResponseFormatTextJSONSchemaConfig,\n parser: (content: string) => ParsedT,\n): AutoParseableTextFormat<ParsedT> {\n const obj = { ...response_format };\n\n Object.defineProperties(obj, {\n $brand: {\n value: 'auto-parseable-response-format',\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n });\n\n return obj as AutoParseableTextFormat<ParsedT>;\n}\n\nexport function isAutoParsableResponseFormat<ParsedT>(\n response_format: any,\n): response_format is AutoParseableResponseFormat<ParsedT> {\n return response_format?.['$brand'] === 'auto-parseable-response-format';\n}\n\ntype ToolOptions = {\n name: string;\n arguments: any;\n function?: ((args: any) => any) | undefined;\n};\n\nexport type AutoParseableTool<\n OptionsT extends ToolOptions,\n HasFunction = OptionsT['function'] extends Function ? true : false,\n> = ChatCompletionFunctionTool & {\n __arguments: OptionsT['arguments']; // type-level only\n __name: OptionsT['name']; // type-level only\n __hasFunction: HasFunction; // type-level only\n\n $brand: 'auto-parseable-tool';\n $callback: ((args: OptionsT['arguments']) => any) | undefined;\n $parseRaw(args: string): OptionsT['arguments'];\n};\n\nexport function makeParseableTool<OptionsT extends ToolOptions>(\n tool: ChatCompletionFunctionTool,\n {\n parser,\n callback,\n }: {\n parser: (content: string) => OptionsT['arguments'];\n callback: ((args: any) => any) | undefined;\n },\n): AutoParseableTool<OptionsT['arguments']> {\n const obj = { ...tool };\n\n Object.defineProperties(obj, {\n $brand: {\n value: 'auto-parseable-tool',\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n $callback: {\n value: callback,\n enumerable: false,\n },\n });\n\n return obj as AutoParseableTool<OptionsT['arguments']>;\n}\n\nexport function isAutoParsableTool(tool: any): tool is AutoParseableTool<any> {\n return tool?.['$brand'] === 'auto-parseable-tool';\n}\n\nexport function maybeParseChatCompletion<\n Params extends ChatCompletionCreateParams | null,\n ParsedT = Params extends null ? null : ExtractParsedContentFromParams<NonNullable<Params>>,\n>(completion: ChatCompletion, params: Params): ParsedChatCompletion<ParsedT> {\n if (!params || !hasAutoParseableInput(params)) {\n return {\n ...completion,\n choices: completion.choices.map((choice) => {\n assertToolCallsAreChatCompletionFunctionToolCalls(choice.message.tool_calls);\n\n return {\n ...choice,\n message: {\n ...choice.message,\n parsed: null,\n ...(choice.message.tool_calls ?\n {\n tool_calls: choice.message.tool_calls,\n }\n : undefined),\n },\n };\n }),\n } as ParsedChatCompletion<ParsedT>;\n }\n\n return parseChatCompletion(completion, params);\n}\n\nexport function parseChatCompletion<\n Params extends ChatCompletionCreateParams,\n ParsedT = ExtractParsedContentFromParams<Params>,\n>(completion: ChatCompletion, params: Params): ParsedChatCompletion<ParsedT> {\n const choices: Array<ParsedChoice<ParsedT>> = completion.choices.map((choice): ParsedChoice<ParsedT> => {\n if (choice.finish_reason === 'length') {\n throw new LengthFinishReasonError();\n }\n\n if (choice.finish_reason === 'content_filter') {\n throw new ContentFilterFinishReasonError();\n }\n\n assertToolCallsAreChatCompletionFunctionToolCalls(choice.message.tool_calls);\n\n return {\n ...choice,\n message: {\n ...choice.message,\n ...(choice.message.tool_calls ?\n {\n tool_calls:\n choice.message.tool_calls?.map((toolCall) => parseToolCall(params, toolCall)) ?? undefined,\n }\n : undefined),\n parsed:\n choice.message.content && !choice.message.refusal ?\n parseResponseFormat(params, choice.message.content)\n : null,\n },\n } as ParsedChoice<ParsedT>;\n });\n\n return { ...completion, choices };\n}\n\nfunction parseResponseFormat<\n Params extends ChatCompletionCreateParams,\n ParsedT = ExtractParsedContentFromParams<Params>,\n>(params: Params, content: string): ParsedT | null {\n if (params.response_format?.type !== 'json_schema') {\n return null;\n }\n\n if (params.response_format?.type === 'json_schema') {\n if ('$parseRaw' in params.response_format) {\n const response_format = params.response_format as AutoParseableResponseFormat<ParsedT>;\n\n return response_format.$parseRaw(content);\n }\n\n return JSON.parse(content);\n }\n\n return null;\n}\n\nfunction parseToolCall<Params extends ChatCompletionCreateParams>(\n params: Params,\n toolCall: ChatCompletionMessageFunctionToolCall,\n): ParsedFunctionToolCall {\n const inputTool = params.tools?.find(\n (inputTool) =>\n isChatCompletionFunctionTool(inputTool) && inputTool.function?.name === toolCall.function.name,\n ) as ChatCompletionFunctionTool | undefined; // TS doesn't narrow based on isChatCompletionTool\n return {\n ...toolCall,\n function: {\n ...toolCall.function,\n parsed_arguments:\n isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.function.arguments)\n : inputTool?.function.strict ? JSON.parse(toolCall.function.arguments)\n : null,\n },\n };\n}\n\nexport function shouldParseToolCall(\n params: ChatCompletionCreateParams | null | undefined,\n toolCall: ChatCompletionMessageFunctionToolCall,\n): boolean {\n if (!params || !('tools' in params) || !params.tools) {\n return false;\n }\n\n const inputTool = params.tools?.find(\n (inputTool) =>\n isChatCompletionFunctionTool(inputTool) && inputTool.function?.name === toolCall.function.name,\n );\n return (\n isChatCompletionFunctionTool(inputTool) &&\n (isAutoParsableTool(inputTool) || inputTool?.function.strict || false)\n );\n}\n\nexport function hasAutoParseableInput(params: AnyChatCompletionCreateParams): boolean {\n if (isAutoParsableResponseFormat(params.response_format)) {\n return true;\n }\n\n return (\n params.tools?.some(\n (t) => isAutoParsableTool(t) || (t.type === 'function' && t.function.strict === true),\n ) ?? false\n );\n}\n\nexport function assertToolCallsAreChatCompletionFunctionToolCalls(\n toolCalls: ChatCompletionMessage['tool_calls'],\n): asserts toolCalls is ChatCompletionMessageFunctionToolCall[] {\n for (const toolCall of toolCalls || []) {\n if (toolCall.type !== 'function') {\n throw new OpenAIError(\n `Currently only \\`function\\` tool calls are supported; Received \\`${toolCall.type}\\``,\n );\n }\n }\n}\n\nexport function validateInputTools(tools: ChatCompletionCreateParamsBase['tools']) {\n for (const tool of tools ?? []) {\n if (tool.type !== 'function') {\n throw new OpenAIError(\n `Currently only \\`function\\` tool types support auto-parsing; Received \\`${tool.type}\\``,\n );\n }\n\n if (tool.function.strict !== true) {\n throw new OpenAIError(\n `The \\`${tool.function.name}\\` tool is not marked with \\`strict: true\\`. Only strict function tools can be auto-parsed`,\n );\n }\n }\n}\n","import {\n type ChatCompletionAssistantMessageParam,\n type ChatCompletionMessageParam,\n type ChatCompletionToolMessageParam,\n} from '../resources';\n\nexport const isAssistantMessage = (\n message: ChatCompletionMessageParam | null | undefined,\n): message is ChatCompletionAssistantMessageParam => {\n return message?.role === 'assistant';\n};\n\nexport const isToolMessage = (\n message: ChatCompletionMessageParam | null | undefined,\n): message is ChatCompletionToolMessageParam => {\n return message?.role === 'tool';\n};\n\nexport function isPresent<T>(obj: T | null | undefined): obj is T {\n return obj != null;\n}\n","import { APIUserAbortError, OpenAIError } from '../error';\n\nexport class EventStream<EventTypes extends BaseEvents> {\n controller: AbortController = new AbortController();\n\n #connectedPromise: Promise<void>;\n #resolveConnectedPromise: () => void = () => {};\n #rejectConnectedPromise: (error: OpenAIError) => void = () => {};\n\n #endPromise: Promise<void>;\n #resolveEndPromise: () => void = () => {};\n #rejectEndPromise: (error: OpenAIError) => void = () => {};\n\n #listeners: {\n [Event in keyof EventTypes]?: EventListeners<EventTypes, Event>;\n } = {};\n\n #ended = false;\n #errored = false;\n #aborted = false;\n #catchingPromiseCreated = false;\n\n constructor() {\n this.#connectedPromise = new Promise<void>((resolve, reject) => {\n this.#resolveConnectedPromise = resolve;\n this.#rejectConnectedPromise = reject;\n });\n\n this.#endPromise = new Promise<void>((resolve, reject) => {\n this.#resolveEndPromise = resolve;\n this.#rejectEndPromise = reject;\n });\n\n // Don't let these promises cause unhandled rejection errors.\n // we will manually cause an unhandled rejection error later\n // if the user hasn't registered any error listener or called\n // any promise-returning method.\n this.#connectedPromise.catch(() => {});\n this.#endPromise.catch(() => {});\n }\n\n protected _run(this: EventStream<EventTypes>, executor: () => Promise<any>) {\n // Unfortunately if we call `executor()` immediately we get runtime errors about\n // references to `this` before the `super()` constructor call returns.\n setTimeout(() => {\n executor().then(() => {\n this._emitFinal();\n this._emit('end');\n }, this.#handleError.bind(this));\n }, 0);\n }\n\n protected _connected(this: EventStream<EventTypes>) {\n if (this.ended) return;\n this.#resolveConnectedPromise();\n this._emit('connect');\n }\n\n get ended(): boolean {\n return this.#ended;\n }\n\n get errored(): boolean {\n return this.#errored;\n }\n\n get aborted(): boolean {\n return this.#aborted;\n }\n\n abort() {\n this.controller.abort();\n }\n\n /**\n * Adds the listener function to the end of the listeners array for the event.\n * No checks are made to see if the listener has already been added. Multiple calls passing\n * the same combination of event and listener will result in the listener being added, and\n * called, multiple times.\n * @returns this ChatCompletionStream, so that calls can be chained\n */\n on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n const listeners: EventListeners<EventTypes, Event> =\n this.#listeners[event] || (this.#listeners[event] = []);\n listeners.push({ listener });\n return this;\n }\n\n /**\n * Removes the specified listener from the listener array for the event.\n * off() will remove, at most, one instance of a listener from the listener array. If any single\n * listener has been added multiple times to the listener array for the specified event, then\n * off() must be called multiple times to remove each instance.\n * @returns this ChatCompletionStream, so that calls can be chained\n */\n off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n const listeners = this.#listeners[event];\n if (!listeners) return this;\n const index = listeners.findIndex((l) => l.listener === listener);\n if (index >= 0) listeners.splice(index, 1);\n return this;\n }\n\n /**\n * Adds a one-time listener function for the event. The next time the event is triggered,\n * this listener is removed and then invoked.\n * @returns this ChatCompletionStream, so that calls can be chained\n */\n once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {\n const listeners: EventListeners<EventTypes, Event> =\n this.#listeners[event] || (this.#listeners[event] = []);\n listeners.push({ listener, once: true });\n return this;\n }\n\n /**\n * This is similar to `.once()`, but returns a Promise that resolves the next time\n * the event is triggered, instead of calling a listener callback.\n * @returns a Promise that resolves the next time given event is triggered,\n * or rejects if an error is emitted. (If you request the 'error' event,\n * returns a promise that resolves with the error).\n *\n * Example:\n *\n * const message = await stream.emitted('message') // rejects if the stream errors\n */\n emitted<Event extends keyof EventTypes>(\n event: Event,\n ): Promise<\n EventParameters<EventTypes, Event> extends [infer Param] ? Param\n : EventParameters<EventTypes, Event> extends [] ? void\n : EventParameters<EventTypes, Event>\n > {\n return new Promise((resolve, reject) => {\n this.#catchingPromiseCreated = true;\n if (event !== 'error') this.once('error', reject);\n this.once(event, resolve as any);\n });\n }\n\n async done(): Promise<void> {\n this.#catchingPromiseCreated = true;\n await this.#endPromise;\n }\n\n #handleError(this: EventStream<EventTypes>, error: unknown) {\n this.#errored = true;\n if (error instanceof Error && error.name === 'AbortError') {\n error = new APIUserAbortError();\n }\n if (error instanceof APIUserAbortError) {\n this.#aborted = true;\n return this._emit('abort', error);\n }\n if (error instanceof OpenAIError) {\n return this._emit('error', error);\n }\n if (error instanceof Error) {\n const openAIError: OpenAIError = new OpenAIError(error.message);\n // @ts-ignore\n openAIError.cause = error;\n return this._emit('error', openAIError);\n }\n return this._emit('error', new OpenAIError(String(error)));\n }\n\n _emit<Event extends keyof BaseEvents>(event: Event, ...args: EventParameters<BaseEvents, Event>): void;\n _emit<Event extends keyof EventTypes>(event: Event, ...args: EventParameters<EventTypes, Event>): void;\n _emit<Event extends keyof EventTypes>(\n this: EventStream<EventTypes>,\n event: Event,\n ...args: EventParameters<EventTypes, Event>\n ) {\n // make sure we don't emit any events after end\n if (this.#ended) {\n return;\n }\n\n if (event === 'end') {\n this.#ended = true;\n this.#resolveEndPromise();\n }\n\n const listeners: EventListeners<EventTypes, Event> | undefined = this.#listeners[event];\n if (listeners) {\n this.#listeners[event] = listeners.filter((l) => !l.once) as any;\n listeners.forEach(({ listener }: any) => listener(...(args as any)));\n }\n\n if (event === 'abort') {\n const error = args[0] as APIUserAbortError;\n if (!this.#catchingPromiseCreated && !listeners?.length) {\n Promise.reject(error);\n }\n this.#rejectConnectedPromise(error);\n this.#rejectEndPromise(error);\n this._emit('end');\n return;\n }\n\n if (event === 'error') {\n // NOTE: _emit('error', error) should only be called from #handleError().\n\n const error = args[0] as OpenAIError;\n if (!this.#catchingPromiseCreated && !listeners?.length) {\n // Trigger an unhandled rejection if the user hasn't registered any error handlers.\n // If you are seeing stack traces here, make sure to handle errors via either:\n // - runner.on('error', () => ...)\n // - await runner.done()\n // - await runner.finalChatCompletion()\n // - etc.\n Promise.reject(error);\n }\n this.#rejectConnectedPromise(error);\n this.#rejectEndPromise(error);\n this._emit('end');\n }\n }\n\n protected _emitFinal(): void {}\n}\n\ntype EventListener<Events, EventType extends keyof Events> = Events[EventType];\n\ntype EventListeners<Events, EventType extends keyof Events> = Array<{\n listener: EventListener<Events, EventType>;\n once?: boolean;\n}>;\n\nexport type EventParameters<Events, EventType extends keyof Events> = {\n [Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;\n}[EventType];\n\nexport interface BaseEvents {\n connect: () => void;\n error: (error: OpenAIError) => void;\n abort: (error: APIUserAbortError) => void;\n end: () => void;\n}\n","import { type ChatCompletionRunner } from './ChatCompletionRunner';\nimport { type ChatCompletionStreamingRunner } from './ChatCompletionStreamingRunner';\nimport { JSONSchema } from './jsonschema';\n\ntype PromiseOrValue<T> = T | Promise<T>;\n\nexport type RunnableFunctionWithParse<Args extends object> = {\n /**\n * @param args the return value from `parse`.\n * @param runner the runner evaluating this callback.\n * @returns a string to send back to OpenAI.\n */\n function: (\n args: Args,\n runner: ChatCompletionRunner<unknown> | ChatCompletionStreamingRunner<unknown>,\n ) => PromiseOrValue<unknown>;\n /**\n * @param input the raw args from the OpenAI function call.\n * @returns the parsed arguments to pass to `function`\n */\n parse: (input: string) => PromiseOrValue<Args>;\n /**\n * The parameters the function accepts, describes as a JSON Schema object.\n */\n parameters: JSONSchema;\n /**\n * A description of what the function does, used by the model to choose when and how to call the function.\n */\n description: string;\n /**\n * The name of the function to be called. Will default to function.name if omitted.\n */\n name?: string | undefined;\n strict?: boolean | undefined;\n};\n\nexport type RunnableFunctionWithoutParse = {\n /**\n * @param args the raw args from the OpenAI function call.\n * @returns a string to send back to OpenAI\n */\n function: (\n args: string,\n runner: ChatCompletionRunner<unknown> | ChatCompletionStreamingRunner<unknown>,\n ) => PromiseOrValue<unknown>;\n /**\n * The parameters the function accepts, describes as a JSON Schema object.\n */\n parameters: JSONSchema;\n /**\n * A description of what the function does, used by the model to choose when and how to call the function.\n */\n description: string;\n /**\n * The name of the function to be called. Will default to function.name if omitted.\n */\n name?: string | undefined;\n strict?: boolean | undefined;\n};\n\nexport type RunnableFunction<Args extends object | string> =\n Args extends string ? RunnableFunctionWithoutParse\n : Args extends object ? RunnableFunctionWithParse<Args>\n : never;\n\nexport type RunnableToolFunction<Args extends object | string> =\n Args extends string ? RunnableToolFunctionWithoutParse\n : Args extends object ? RunnableToolFunctionWithParse<Args>\n : never;\n\nexport type RunnableToolFunctionWithoutParse = {\n type: 'function';\n function: RunnableFunctionWithoutParse;\n};\nexport type RunnableToolFunctionWithParse<Args extends object> = {\n type: 'function';\n function: RunnableFunctionWithParse<Args>;\n};\n\nexport function isRunnableFunctionWithParse<Args extends object>(\n fn: any,\n): fn is RunnableFunctionWithParse<Args> {\n return typeof (fn as any).parse === 'function';\n}\n\nexport type BaseFunctionsArgs = readonly (object | string)[];\n\nexport type RunnableFunctions<FunctionsArgs extends BaseFunctionsArgs> =\n [any[]] extends [FunctionsArgs] ? readonly RunnableFunction<any>[]\n : {\n [Index in keyof FunctionsArgs]: Index extends number ? RunnableFunction<FunctionsArgs[Index]>\n : FunctionsArgs[Index];\n };\n\nexport type RunnableTools<FunctionsArgs extends BaseFunctionsArgs> =\n [any[]] extends [FunctionsArgs] ? readonly RunnableToolFunction<any>[]\n : {\n [Index in keyof FunctionsArgs]: Index extends number ? RunnableToolFunction<FunctionsArgs[Index]>\n : FunctionsArgs[Index];\n };\n\n/**\n * This is helper class for passing a `function` and `parse` where the `function`\n * argument type matches the `parse` return type.\n */\nexport class ParsingToolFunction<Args extends object> {\n type: 'function';\n function: RunnableFunctionWithParse<Args>;\n\n constructor(input: RunnableFunctionWithParse<Args>) {\n this.type = 'function';\n this.function = input;\n }\n}\n","import { OpenAIError } from '../error';\nimport type OpenAI from '../index';\nimport type { RequestOptions } from '../internal/request-options';\nimport { isAutoParsableTool, parseChatCompletion } from '../lib/parser';\nimport type {\n ChatCompletion,\n ChatCompletionCreateParams,\n ChatCompletionMessage,\n ChatCompletionMessageFunctionToolCall,\n ChatCompletionMessageParam,\n ChatCompletionTool,\n ParsedChatCompletion,\n} from '../resources/chat/completions';\nimport type { CompletionUsage } from '../resources/completions';\nimport type { ChatCompletionToolRunnerParams } from './ChatCompletionRunner';\nimport type { ChatCompletionStreamingToolRunnerParams } from './ChatCompletionStreamingRunner';\nimport { isAssistantMessage, isToolMessage } from './chatCompletionUtils';\nimport { BaseEvents, EventStream } from './EventStream';\nimport {\n isRunnableFunctionWithParse,\n type BaseFunctionsArgs,\n type RunnableFunction,\n type RunnableToolFunction,\n} from './RunnableFunction';\n\nconst DEFAULT_MAX_CHAT_COMPLETIONS = 10;\nexport interface RunnerOptions extends RequestOptions {\n /** How many requests to make before canceling. Default 10. */\n maxChatCompletions?: number;\n}\n\nexport class AbstractChatCompletionRunner<\n EventTypes extends AbstractChatCompletionRunnerEvents,\n ParsedT,\n> extends EventStream<EventTypes> {\n protected _chatCompletions: ParsedChatCompletion<ParsedT>[] = [];\n messages: ChatCompletionMessageParam[] = [];\n\n protected _addChatCompletion(\n this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>,\n chatCompletion: ParsedChatCompletion<ParsedT>,\n ): ParsedChatCompletion<ParsedT> {\n this._chatCompletions.push(chatCompletion);\n this._emit('chatCompletion', chatCompletion);\n const message = chatCompletion.choices[0]?.message;\n if (message) this._addMessage(message as ChatCompletionMessageParam);\n return chatCompletion;\n }\n\n protected _addMessage(\n this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>,\n message: ChatCompletionMessageParam,\n emit = true,\n ) {\n if (!('content' in message)) message.content = null;\n\n this.messages.push(message);\n\n if (emit) {\n this._emit('message', message);\n if (isToolMessage(message) && message.content) {\n // Note, this assumes that {role: 'tool', content: …} is always the result of a call of tool of type=function.\n this._emit('functionToolCallResult', message.content as string);\n } else if (isAssistantMessage(message) && message.tool_calls) {\n for (const tool_call of message.tool_calls) {\n if (tool_call.type === 'function') {\n this._emit('functionToolCall', tool_call.function);\n }\n }\n }\n }\n }\n\n /**\n * @returns a promise that resolves with the final ChatCompletion, or rejects\n * if an error occurred or the stream ended prematurely without producing a ChatCompletion.\n */\n async finalChatCompletion(): Promise<ParsedChatCompletion<ParsedT>> {\n await this.done();\n const completion = this._chatCompletions[this._chatCompletions.length - 1];\n if (!completion) throw new OpenAIError('stream ended without producing a ChatCompletion');\n return completion;\n }\n\n #getFinalContent(): string | null {\n return this.#getFinalMessage().content ?? null;\n }\n\n /**\n * @returns a promise that resolves with the content of the final ChatCompletionMessage, or rejects\n * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.\n */\n async finalContent(): Promise<string | null> {\n await this.done();\n return this.#getFinalContent();\n }\n\n #getFinalMessage(): ChatCompletionMessage {\n let i = this.messages.length;\n while (i-- > 0) {\n const message = this.messages[i];\n if (isAssistantMessage(message)) {\n // TODO: support audio here\n const ret: Omit<ChatCompletionMessage, 'audio'> = {\n ...message,\n content: (message as ChatCompletionMessage).content ?? null,\n refusal: (message as ChatCompletionMessage).refusal ?? null,\n };\n return ret;\n }\n }\n throw new OpenAIError('stream ended without producing a ChatCompletionMessage with role=assistant');\n }\n\n /**\n * @returns a promise that resolves with the the final assistant ChatCompletionMessage response,\n * or rejects if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.\n */\n async finalMessage(): Promise<ChatCompletionMessage> {\n await this.done();\n return this.#getFinalMessage();\n }\n\n #getFinalFunctionToolCall(): ChatCompletionMessageFunctionToolCall.Function | undefined {\n for (let i = this.messages.length - 1; i >= 0; i--) {\n const message = this.messages[i];\n if (isAssistantMessage(message) && message?.tool_calls?.length) {\n return message.tool_calls.filter((x) => x.type === 'function').at(-1)?.function;\n }\n }\n\n return;\n }\n\n /**\n * @returns a promise that resolves with the content of the final FunctionCall, or rejects\n * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.\n */\n async finalFunctionToolCall(): Promise<ChatCompletionMessageFunctionToolCall.Function | undefined> {\n await this.done();\n return this.#getFinalFunctionToolCall();\n }\n\n #getFinalFunctionToolCallResult(): string | undefined {\n for (let i = this.messages.length - 1; i >= 0; i--) {\n const message = this.messages[i];\n if (\n isToolMessage(message) &&\n message.content != null &&\n typeof message.content === 'string' &&\n this.messages.some(\n (x) =>\n x.role === 'assistant' &&\n x.tool_calls?.some((y) => y.type === 'function' && y.id === message.tool_call_id),\n )\n ) {\n return message.content;\n }\n }\n\n return;\n }\n\n async finalFunctionToolCallResult(): Promise<string | undefined> {\n await this.done();\n return this.#getFinalFunctionToolCallResult();\n }\n\n #calculateTotalUsage(): CompletionUsage {\n const total: CompletionUsage = {\n completion_tokens: 0,\n prompt_tokens: 0,\n total_tokens: 0,\n };\n for (const { usage } of this._chatCompletions) {\n if (usage) {\n total.completion_tokens += usage.completion_tokens;\n total.prompt_tokens += usage.prompt_tokens;\n total.total_tokens += usage.total_tokens;\n }\n }\n return total;\n }\n\n async totalUsage(): Promise<CompletionUsage> {\n await this.done();\n return this.#calculateTotalUsage();\n }\n\n allChatCompletions(): ChatCompletion[] {\n return [...this._chatCompletions];\n }\n\n protected override _emitFinal(\n this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>,\n ) {\n const completion = this._chatCompletions[this._chatCompletions.length - 1];\n if (completion) this._emit('finalChatCompletion', completion);\n const finalMessage = this.#getFinalMessage();\n if (finalMessage) this._emit('finalMessage', finalMessage);\n const finalContent = this.#getFinalContent();\n if (finalContent) this._emit('finalContent', finalContent);\n\n const finalFunctionCall = this.#getFinalFunctionToolCall();\n if (finalFunctionCall) this._emit('finalFunctionToolCall', finalFunctionCall);\n\n const finalFunctionCallResult = this.#getFinalFunctionToolCallResult();\n if (finalFunctionCallResult != null) this._emit('finalFunctionToolCallResult', finalFunctionCallResult);\n\n if (this._chatCompletions.some((c) => c.usage)) {\n this._emit('totalUsage', this.#calculateTotalUsage());\n }\n }\n\n #validateParams(params: ChatCompletionCreateParams): void {\n if (params.n != null && params.n > 1) {\n throw new OpenAIError(\n 'ChatCompletion convenience helpers only support n=1 at this time. To use n>1, please use chat.completions.create() directly.',\n );\n }\n }\n\n protected async _createChatCompletion(\n client: OpenAI,\n params: ChatCompletionCreateParams,\n options?: RequestOptions,\n ): Promise<ParsedChatCompletion<ParsedT>> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n this.#validateParams(params);\n\n const chatCompletion = await client.chat.completions.create(\n { ...params, stream: false },\n { ...options, signal: this.controller.signal },\n );\n this._connected();\n return this._addChatCompletion(parseChatCompletion(chatCompletion, params));\n }\n\n protected async _runChatCompletion(\n client: OpenAI,\n params: ChatCompletionCreateParams,\n options?: RequestOptions,\n ): Promise<ChatCompletion> {\n for (const message of params.messages) {\n this._addMessage(message, false);\n }\n return await this._createChatCompletion(client, params, options);\n }\n\n protected async _runTools<FunctionsArgs extends BaseFunctionsArgs>(\n client: OpenAI,\n params:\n | ChatCompletionToolRunnerParams<FunctionsArgs>\n | ChatCompletionStreamingToolRunnerParams<FunctionsArgs>,\n options?: RunnerOptions,\n ) {\n const role = 'tool' as const;\n const { tool_choice = 'auto', stream, ...restParams } = params;\n const singleFunctionToCall =\n typeof tool_choice !== 'string' && tool_choice.type === 'function' && tool_choice?.function?.name;\n const { maxChatCompletions = DEFAULT_MAX_CHAT_COMPLETIONS } = options || {};\n\n // TODO(someday): clean this logic up\n const inputTools = params.tools.map((tool): RunnableToolFunction<any> => {\n if (isAutoParsableTool(tool)) {\n if (!tool.$callback) {\n throw new OpenAIError('Tool given to `.runTools()` that does not have an associated function');\n }\n\n return {\n type: 'function',\n function: {\n function: tool.$callback,\n name: tool.function.name,\n description: tool.function.description || '',\n parameters: tool.function.parameters as any,\n parse: tool.$parseRaw,\n strict: true,\n },\n };\n }\n\n return tool as any as RunnableToolFunction<any>;\n });\n\n const functionsByName: Record<string, RunnableFunction<any>> = {};\n for (const f of inputTools) {\n if (f.type === 'function') {\n functionsByName[f.function.name || f.function.function.name] = f.function;\n }\n }\n\n const tools: ChatCompletionTool[] =\n 'tools' in params ?\n inputTools.map((t) =>\n t.type === 'function' ?\n {\n type: 'function',\n function: {\n name: t.function.name || t.function.function.name,\n parameters: t.function.parameters as Record<string, unknown>,\n description: t.function.description,\n strict: t.function.strict,\n },\n }\n : (t as unknown as ChatCompletionTool),\n )\n : (undefined as any);\n\n for (const message of params.messages) {\n this._addMessage(message, false);\n }\n\n for (let i = 0; i < maxChatCompletions; ++i) {\n const chatCompletion: ChatCompletion = await this._createChatCompletion(\n client,\n {\n ...restParams,\n tool_choice,\n tools,\n messages: [...this.messages],\n },\n options,\n );\n const message = chatCompletion.choices[0]?.message;\n if (!message) {\n throw new OpenAIError(`missing message in ChatCompletion response`);\n }\n if (!message.tool_calls?.length) {\n return;\n }\n\n for (const tool_call of message.tool_calls) {\n if (tool_call.type !== 'function') continue;\n const tool_call_id = tool_call.id;\n const { name, arguments: args } = tool_call.function;\n const fn = functionsByName[name];\n\n if (!fn) {\n const content = `Invalid tool_call: ${JSON.stringify(name)}. Available options are: ${Object.keys(\n functionsByName,\n )\n .map((name) => JSON.stringify(name))\n .join(', ')}. Please try again`;\n\n this._addMessage({ role, tool_call_id, content });\n continue;\n } else if (singleFunctionToCall && singleFunctionToCall !== name) {\n const content = `Invalid tool_call: ${JSON.stringify(name)}. ${JSON.stringify(\n singleFunctionToCall,\n )} requested. Please try again`;\n\n this._addMessage({ role, tool_call_id, content });\n continue;\n }\n\n let parsed;\n try {\n parsed = isRunnableFunctionWithParse(fn) ? await fn.parse(args) : args;\n } catch (error) {\n const content = error instanceof Error ? error.message : String(error);\n this._addMessage({ role, tool_call_id, content });\n continue;\n }\n\n // @ts-expect-error it can't rule out `never` type.\n const rawContent = await fn.function(parsed, this);\n const content = this.#stringifyFunctionCallResult(rawContent);\n this._addMessage({ role, tool_call_id, content });\n\n if (singleFunctionToCall) {\n return;\n }\n }\n }\n\n return;\n }\n\n #stringifyFunctionCallResult(rawContent: unknown): string {\n return (\n typeof rawContent === 'string' ? rawContent\n : rawContent === undefined ? 'undefined'\n : JSON.stringify(rawContent)\n );\n }\n}\n\nexport interface AbstractChatCompletionRunnerEvents extends BaseEvents {\n functionToolCall: (functionCall: ChatCompletionMessageFunctionToolCall.Function) => void;\n message: (message: ChatCompletionMessageParam) => void;\n chatCompletion: (completion: ChatCompletion) => void;\n finalContent: (contentSnapshot: string) => void;\n finalMessage: (message: ChatCompletionMessageParam) => void;\n finalChatCompletion: (completion: ChatCompletion) => void;\n finalFunctionToolCall: (functionCall: ChatCompletionMessageFunctionToolCall.Function) => void;\n functionToolCallResult: (content: string) => void;\n finalFunctionToolCallResult: (content: string) => void;\n totalUsage: (usage: CompletionUsage) => void;\n}\n","import {\n type ChatCompletionMessageParam,\n type ChatCompletionCreateParamsNonStreaming,\n} from '../resources/chat/completions';\nimport { type BaseFunctionsArgs, RunnableTools } from './RunnableFunction';\nimport {\n AbstractChatCompletionRunner,\n AbstractChatCompletionRunnerEvents,\n RunnerOptions,\n} from './AbstractChatCompletionRunner';\nimport { isAssistantMessage } from './chatCompletionUtils';\nimport OpenAI from '../index';\nimport { AutoParseableTool } from '../lib/parser';\n\nexport interface ChatCompletionRunnerEvents extends AbstractChatCompletionRunnerEvents {\n content: (content: string) => void;\n}\n\nexport type ChatCompletionToolRunnerParams<FunctionsArgs extends BaseFunctionsArgs> = Omit<\n ChatCompletionCreateParamsNonStreaming,\n 'tools'\n> & {\n tools: RunnableTools<FunctionsArgs> | AutoParseableTool<any, true>[];\n};\n\nexport class ChatCompletionRunner<ParsedT = null> extends AbstractChatCompletionRunner<\n ChatCompletionRunnerEvents,\n ParsedT\n> {\n static runTools<ParsedT>(\n client: OpenAI,\n params: ChatCompletionToolRunnerParams<any[]>,\n options?: RunnerOptions,\n ): ChatCompletionRunner<ParsedT> {\n const runner = new ChatCompletionRunner<ParsedT>();\n const opts = {\n ...options,\n headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runTools' },\n };\n runner._run(() => runner._runTools(client, params, opts));\n return runner;\n }\n\n override _addMessage(\n this: ChatCompletionRunner<ParsedT>,\n message: ChatCompletionMessageParam,\n emit: boolean = true,\n ) {\n super._addMessage(message, emit);\n if (isAssistantMessage(message) && message.content) {\n this._emit('content', message.content as string);\n }\n }\n}\n","const STR = 0b000000001;\nconst NUM = 0b000000010;\nconst ARR = 0b000000100;\nconst OBJ = 0b000001000;\nconst NULL = 0b000010000;\nconst BOOL = 0b000100000;\nconst NAN = 0b001000000;\nconst INFINITY = 0b010000000;\nconst MINUS_INFINITY = 0b100000000;\n\nconst INF = INFINITY | MINUS_INFINITY;\nconst SPECIAL = NULL | BOOL | INF | NAN;\nconst ATOM = STR | NUM | SPECIAL;\nconst COLLECTION = ARR | OBJ;\nconst ALL = ATOM | COLLECTION;\n\nconst Allow = {\n STR,\n NUM,\n ARR,\n OBJ,\n NULL,\n BOOL,\n NAN,\n INFINITY,\n MINUS_INFINITY,\n INF,\n SPECIAL,\n ATOM,\n COLLECTION,\n ALL,\n};\n\n// The JSON string segment was unable to be parsed completely\nclass PartialJSON extends Error {}\n\nclass MalformedJSON extends Error {}\n\n/**\n * Parse incomplete JSON\n * @param {string} jsonString Partial JSON to be parsed\n * @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details\n * @returns The parsed JSON\n * @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter)\n * @throws {MalformedJSON} If the JSON is malformed\n */\nfunction parseJSON(jsonString: string, allowPartial: number = Allow.ALL): any {\n if (typeof jsonString !== 'string') {\n throw new TypeError(`expecting str, got ${typeof jsonString}`);\n }\n if (!jsonString.trim()) {\n throw new Error(`${jsonString} is empty`);\n }\n return _parseJSON(jsonString.trim(), allowPartial);\n}\n\nconst _parseJSON = (jsonString: string, allow: number) => {\n const length = jsonString.length;\n let index = 0;\n\n const markPartialJSON = (msg: string) => {\n throw new PartialJSON(`${msg} at position ${index}`);\n };\n\n const throwMalformedError = (msg: string) => {\n throw new MalformedJSON(`${msg} at position ${index}`);\n };\n\n const parseAny: () => any = () => {\n skipBlank();\n if (index >= length) markPartialJSON('Unexpected end of input');\n if (jsonString[index] === '\"') return parseStr();\n if (jsonString[index] === '{') return parseObj();\n if (jsonString[index] === '[') return parseArr();\n if (\n jsonString.substring(index, index + 4) === 'null' ||\n (Allow.NULL & allow && length - index < 4 && 'null'.startsWith(jsonString.substring(index)))\n ) {\n index += 4;\n return null;\n }\n if (\n jsonString.substring(index, index + 4) === 'true' ||\n (Allow.BOOL & allow && length - index < 4 && 'true'.startsWith(jsonString.substring(index)))\n ) {\n index += 4;\n return true;\n }\n if (\n jsonString.substring(index, index + 5) === 'false' ||\n (Allow.BOOL & allow && length - index < 5 && 'false'.startsWith(jsonString.substring(index)))\n ) {\n index += 5;\n return false;\n }\n if (\n jsonString.substring(index, index + 8) === 'Infinity' ||\n (Allow.INFINITY & allow && length - index < 8 && 'Infinity'.startsWith(jsonString.substring(index)))\n ) {\n index += 8;\n return Infinity;\n }\n if (\n jsonString.substring(index, index + 9) === '-Infinity' ||\n (Allow.MINUS_INFINITY & allow &&\n 1 < length - index &&\n length - index < 9 &&\n '-Infinity'.startsWith(jsonString.substring(index)))\n ) {\n index += 9;\n return -Infinity;\n }\n if (\n jsonString.substring(index, index + 3) === 'NaN' ||\n (Allow.NAN & allow && length - index < 3 && 'NaN'.startsWith(jsonString.substring(index)))\n ) {\n index += 3;\n return NaN;\n }\n return parseNum();\n };\n\n const parseStr: () => string = () => {\n const start = index;\n let escape = false;\n index++; // skip initial quote\n while (index < length && (jsonString[index] !== '\"' || (escape && jsonString[index - 1] === '\\\\'))) {\n escape = jsonString[index] === '\\\\' ? !escape : false;\n index++;\n }\n if (jsonString.charAt(index) == '\"') {\n try {\n return JSON.parse(jsonString.substring(start, ++index - Number(escape)));\n } catch (e) {\n throwMalformedError(String(e));\n }\n } else if (Allow.STR & allow) {\n try {\n return JSON.parse(jsonString.substring(start, index - Number(escape)) + '\"');\n } catch (e) {\n // SyntaxError: Invalid escape sequence\n return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf('\\\\')) + '\"');\n }\n }\n markPartialJSON('Unterminated string literal');\n };\n\n const parseObj = () => {\n index++; // skip initial brace\n skipBlank();\n const obj: Record<string, any> = {};\n try {\n while (jsonString[index] !== '}') {\n skipBlank();\n if (index >= length && Allow.OBJ & allow) return obj;\n const key = parseStr();\n skipBlank();\n index++; // skip colon\n try {\n const value = parseAny();\n Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });\n } catch (e) {\n if (Allow.OBJ & allow) return obj;\n else throw e;\n }\n skipBlank();\n if (jsonString[index] === ',') index++; // skip comma\n }\n } catch (e) {\n if (Allow.OBJ & allow) return obj;\n else markPartialJSON(\"Expected '}' at end of object\");\n }\n index++; // skip final brace\n return obj;\n };\n\n const parseArr = () => {\n index++; // skip initial bracket\n const arr = [];\n try {\n while (jsonString[index] !== ']') {\n arr.push(parseAny());\n skipBlank();\n if (jsonString[index] === ',') {\n index++; // skip comma\n }\n }\n } catch (e) {\n if (Allow.ARR & allow) {\n return arr;\n }\n markPartialJSON(\"Expected ']' at end of array\");\n }\n index++; // skip final bracket\n return arr;\n };\n\n const parseNum = () => {\n if (index === 0) {\n if (jsonString === '-' && Allow.NUM & allow) markPartialJSON(\"Not sure what '-' is\");\n try {\n return JSON.parse(jsonString);\n } catch (e) {\n if (Allow.NUM & allow) {\n try {\n if ('.' === jsonString[jsonString.length - 1])\n return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf('.')));\n return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf('e')));\n } catch (e) {}\n }\n throwMalformedError(String(e));\n }\n }\n\n const start = index;\n\n if (jsonString[index] === '-') index++;\n while (jsonString[index] && !',]}'.includes(jsonString[index]!)) index++;\n\n if (index == length && !(Allow.NUM & allow)) markPartialJSON('Unterminated number literal');\n\n try {\n return JSON.parse(jsonString.substring(start, index));\n } catch (e) {\n if (jsonString.substring(start, index) === '-' && Allow.NUM & allow)\n markPartialJSON(\"Not sure what '-' is\");\n try {\n return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf('e')));\n } catch (e) {\n throwMalformedError(String(e));\n }\n }\n };\n\n const skipBlank = () => {\n while (index < length && ' \\n\\r\\t'.includes(jsonString[index]!)) {\n index++;\n }\n };\n\n return parseAny();\n};\n\n// using this function with malformed JSON is undefined behavior\nconst partialParse = (input: string) => parseJSON(input, Allow.ALL ^ Allow.NUM);\n\nexport { partialParse, PartialJSON, MalformedJSON };\n","import { partialParse } from '../_vendor/partial-json-parser/parser';\nimport {\n APIUserAbortError,\n ContentFilterFinishReasonError,\n LengthFinishReasonError,\n OpenAIError,\n} from '../error';\nimport OpenAI from '../index';\nimport { RequestOptions } from '../internal/request-options';\nimport { type ReadableStream } from '../internal/shim-types';\nimport {\n AutoParseableResponseFormat,\n hasAutoParseableInput,\n isAutoParsableResponseFormat,\n isAutoParsableTool,\n isChatCompletionFunctionTool,\n maybeParseChatCompletion,\n shouldParseToolCall,\n} from '../lib/parser';\nimport { ChatCompletionFunctionTool, ParsedChatCompletion } from '../resources/chat/completions';\nimport {\n ChatCompletionTokenLogprob,\n type ChatCompletion,\n type ChatCompletionChunk,\n type ChatCompletionCreateParams,\n type ChatCompletionCreateParamsBase,\n type ChatCompletionCreateParamsStreaming,\n type ChatCompletionRole,\n} from '../resources/chat/completions/completions';\nimport { Stream } from '../streaming';\nimport {\n AbstractChatCompletionRunner,\n type AbstractChatCompletionRunnerEvents,\n} from './AbstractChatCompletionRunner';\n\nexport interface ContentDeltaEvent {\n delta: string;\n snapshot: string;\n parsed: unknown | null;\n}\n\nexport interface ContentDoneEvent<ParsedT = null> {\n content: string;\n parsed: ParsedT | null;\n}\n\nexport interface RefusalDeltaEvent {\n delta: string;\n snapshot: string;\n}\n\nexport interface RefusalDoneEvent {\n refusal: string;\n}\n\nexport interface FunctionToolCallArgumentsDeltaEvent {\n name: string;\n\n index: number;\n\n arguments: string;\n\n parsed_arguments: unknown;\n\n arguments_delta: string;\n}\n\nexport interface FunctionToolCallArgumentsDoneEvent {\n name: string;\n\n index: number;\n\n arguments: string;\n\n parsed_arguments: unknown;\n}\n\nexport interface LogProbsContentDeltaEvent {\n content: Array<ChatCompletionTokenLogprob>;\n snapshot: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface LogProbsContentDoneEvent {\n content: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface LogProbsRefusalDeltaEvent {\n refusal: Array<ChatCompletionTokenLogprob>;\n snapshot: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface LogProbsRefusalDoneEvent {\n refusal: Array<ChatCompletionTokenLogprob>;\n}\n\nexport interface ChatCompletionStreamEvents<ParsedT = null> extends AbstractChatCompletionRunnerEvents {\n content: (contentDelta: string, contentSnapshot: string) => void;\n chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;\n\n 'content.delta': (props: ContentDeltaEvent) => void;\n 'content.done': (props: ContentDoneEvent<ParsedT>) => void;\n\n 'refusal.delta': (props: RefusalDeltaEvent) => void;\n 'refusal.done': (props: RefusalDoneEvent) => void;\n\n 'tool_calls.function.arguments.delta': (props: FunctionToolCallArgumentsDeltaEvent) => void;\n 'tool_calls.function.arguments.done': (props: FunctionToolCallArgumentsDoneEvent) => void;\n\n 'logprobs.content.delta': (props: LogProbsContentDeltaEvent) => void;\n 'logprobs.content.done': (props: LogProbsContentDoneEvent) => void;\n\n 'logprobs.refusal.delta': (props: LogProbsRefusalDeltaEvent) => void;\n 'logprobs.refusal.done': (props: LogProbsRefusalDoneEvent) => void;\n}\n\nexport type ChatCompletionStreamParams = Omit<ChatCompletionCreateParamsBase, 'stream'> & {\n stream?: true;\n};\n\ninterface ChoiceEventState {\n content_done: boolean;\n refusal_done: boolean;\n logprobs_content_done: boolean;\n logprobs_refusal_done: boolean;\n current_tool_call_index: number | null;\n done_tool_calls: Set<number>;\n}\n\nexport class ChatCompletionStream<ParsedT = null>\n extends AbstractChatCompletionRunner<ChatCompletionStreamEvents<ParsedT>, ParsedT>\n implements AsyncIterable<ChatCompletionChunk>\n{\n #params: ChatCompletionCreateParams | null;\n #choiceEventStates: ChoiceEventState[];\n #currentChatCompletionSnapshot: ChatCompletionSnapshot | undefined;\n\n constructor(params: ChatCompletionCreateParams | null) {\n super();\n this.#params = params;\n this.#choiceEventStates = [];\n }\n\n get currentChatCompletionSnapshot(): ChatCompletionSnapshot | undefined {\n return this.#currentChatCompletionSnapshot;\n }\n\n /**\n * Intended for use on the frontend, consuming a stream produced with\n * `.toReadableStream()` on the backend.\n *\n * Note that messages sent to the model do not appear in `.on('message')`\n * in this context.\n */\n static fromReadableStream(stream: ReadableStream): ChatCompletionStream<null> {\n const runner = new ChatCompletionStream(null);\n runner._run(() => runner._fromReadableStream(stream));\n return runner;\n }\n\n static createChatCompletion<ParsedT>(\n client: OpenAI,\n params: ChatCompletionStreamParams,\n options?: RequestOptions,\n ): ChatCompletionStream<ParsedT> {\n const runner = new ChatCompletionStream<ParsedT>(params as ChatCompletionCreateParamsStreaming);\n runner._run(() =>\n runner._runChatCompletion(\n client,\n { ...params, stream: true },\n { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },\n ),\n );\n return runner;\n }\n\n #beginRequest() {\n if (this.ended) return;\n this.#currentChatCompletionSnapshot = undefined;\n }\n\n #getChoiceEventState(choice: ChatCompletionSnapshot.Choice): ChoiceEventState {\n let state = this.#choiceEventStates[choice.index];\n if (state) {\n return state;\n }\n\n state = {\n content_done: false,\n refusal_done: false,\n logprobs_content_done: false,\n logprobs_refusal_done: false,\n done_tool_calls: new Set(),\n current_tool_call_index: null,\n };\n this.#choiceEventStates[choice.index] = state;\n return state;\n }\n\n #addChunk(this: ChatCompletionStream<ParsedT>, chunk: ChatCompletionChunk) {\n if (this.ended) return;\n\n const completion = this.#accumulateChatCompletion(chunk);\n this._emit('chunk', chunk, completion);\n\n for (const choice of chunk.choices) {\n const choiceSnapshot = completion.choices[choice.index]!;\n\n if (\n choice.delta.content != null &&\n choiceSnapshot.message?.role === 'assistant' &&\n choiceSnapshot.message?.content\n ) {\n this._emit('content', choice.delta.content, choiceSnapshot.message.content);\n this._emit('content.delta', {\n delta: choice.delta.content,\n snapshot: choiceSnapshot.message.content,\n parsed: choiceSnapshot.message.parsed,\n });\n }\n\n if (\n choice.delta.refusal != null &&\n choiceSnapshot.message?.role === 'assistant' &&\n choiceSnapshot.message?.refusal\n ) {\n this._emit('refusal.delta', {\n delta: choice.delta.refusal,\n snapshot: choiceSnapshot.message.refusal,\n });\n }\n\n if (choice.logprobs?.content != null && choiceSnapshot.message?.role === 'assistant') {\n this._emit('logprobs.content.delta', {\n content: choice.logprobs?.content,\n snapshot: choiceSnapshot.logprobs?.content ?? [],\n });\n }\n\n if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === 'assistant') {\n this._emit('logprobs.refusal.delta', {\n refusal: choice.logprobs?.refusal,\n snapshot: choiceSnapshot.logprobs?.refusal ?? [],\n });\n }\n\n const state = this.#getChoiceEventState(choiceSnapshot);\n\n if (choiceSnapshot.finish_reason) {\n this.#emitContentDoneEvents(choiceSnapshot);\n\n if (state.current_tool_call_index != null) {\n this.#emitToolCallDoneEvent(choiceSnapshot, state.current_tool_call_index);\n }\n }\n\n for (const toolCall of choice.delta.tool_calls ?? []) {\n if (state.current_tool_call_index !== toolCall.index) {\n this.#emitContentDoneEvents(choiceSnapshot);\n\n // new tool call started, the previous one is done\n if (state.current_tool_call_index != null) {\n this.#emitToolCallDoneEvent(choiceSnapshot, state.current_tool_call_index);\n }\n }\n\n state.current_tool_call_index = toolCall.index;\n }\n\n for (const toolCallDelta of choice.delta.tool_calls ?? []) {\n const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index];\n if (!toolCallSnapshot?.type) {\n continue;\n }\n\n if (toolCallSnapshot?.type === 'function') {\n this._emit('tool_calls.function.arguments.delta', {\n name: toolCallSnapshot.function?.name,\n index: toolCallDelta.index,\n arguments: toolCallSnapshot.function.arguments,\n parsed_arguments: toolCallSnapshot.function.parsed_arguments,\n arguments_delta: toolCallDelta.function?.arguments ?? '',\n });\n } else {\n assertNever(toolCallSnapshot?.type);\n }\n }\n }\n }\n\n #emitToolCallDoneEvent(choiceSnapshot: ChatCompletionSnapshot.Choice, toolCallIndex: number) {\n const state = this.#getChoiceEventState(choiceSnapshot);\n if (state.done_tool_calls.has(toolCallIndex)) {\n // we've already fired the done event\n return;\n }\n\n const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex];\n if (!toolCallSnapshot) {\n throw new Error('no tool call snapshot');\n }\n if (!toolCallSnapshot.type) {\n throw new Error('tool call snapshot missing `type`');\n }\n\n if (toolCallSnapshot.type === 'function') {\n const inputTool = this.#params?.tools?.find(\n (tool) => isChatCompletionFunctionTool(tool) && tool.function.name === toolCallSnapshot.function.name,\n ) as ChatCompletionFunctionTool | undefined; // TS doesn't narrow based on isChatCompletionTool\n\n this._emit('tool_calls.function.arguments.done', {\n name: toolCallSnapshot.function.name,\n index: toolCallIndex,\n arguments: toolCallSnapshot.function.arguments,\n parsed_arguments:\n isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)\n : inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)\n : null,\n });\n } else {\n assertNever(toolCallSnapshot.type);\n }\n }\n\n #emitContentDoneEvents(choiceSnapshot: ChatCompletionSnapshot.Choice) {\n const state = this.#getChoiceEventState(choiceSnapshot);\n\n if (choiceSnapshot.message.content && !state.content_done) {\n state.content_done = true;\n\n const responseFormat = this.#getAutoParseableResponseFormat();\n\n this._emit('content.done', {\n content: choiceSnapshot.message.content,\n parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : (null as any),\n });\n }\n\n if (choiceSnapshot.message.refusal && !state.refusal_done) {\n state.refusal_done = true;\n\n this._emit('refusal.done', { refusal: choiceSnapshot.message.refusal });\n }\n\n if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) {\n state.logprobs_content_done = true;\n\n this._emit('logprobs.content.done', { content: choiceSnapshot.logprobs.content });\n }\n\n if (choiceSnapshot.logprobs?.refusal && !state.logprobs_refusal_done) {\n state.logprobs_refusal_done = true;\n\n this._emit('logprobs.refusal.done', { refusal: choiceSnapshot.logprobs.refusal });\n }\n }\n\n #endRequest(): ParsedChatCompletion<ParsedT> {\n if (this.ended) {\n throw new OpenAIError(`stream has ended, this shouldn't happen`);\n }\n const snapshot = this.#currentChatCompletionSnapshot;\n if (!snapshot) {\n throw new OpenAIError(`request ended without sending any chunks`);\n }\n this.#currentChatCompletionSnapshot = undefined;\n this.#choiceEventStates = [];\n return finalizeChatCompletion(snapshot, this.#params);\n }\n\n protected override async _createChatCompletion(\n client: OpenAI,\n params: ChatCompletionCreateParams,\n options?: RequestOptions,\n ): Promise<ParsedChatCompletion<ParsedT>> {\n super._createChatCompletion;\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n this.#beginRequest();\n\n const stream = await client.chat.completions.create(\n { ...params, stream: true },\n { ...options, signal: this.controller.signal },\n );\n this._connected();\n for await (const chunk of stream) {\n this.#addChunk(chunk);\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n return this._addChatCompletion(this.#endRequest());\n }\n\n protected async _fromReadableStream(\n readableStream: ReadableStream,\n options?: RequestOptions,\n ): Promise<ChatCompletion> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n this.#beginRequest();\n this._connected();\n const stream = Stream.fromReadableStream<ChatCompletionChunk>(readableStream, this.controller);\n let chatId;\n for await (const chunk of stream) {\n if (chatId && chatId !== chunk.id) {\n // A new request has been made.\n this._addChatCompletion(this.#endRequest());\n }\n\n this.#addChunk(chunk);\n chatId = chunk.id;\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n return this._addChatCompletion(this.#endRequest());\n }\n\n #getAutoParseableResponseFormat(): AutoParseableResponseFormat<ParsedT> | null {\n const responseFormat = this.#params?.response_format;\n if (isAutoParsableResponseFormat<ParsedT>(responseFormat)) {\n return responseFormat;\n }\n\n return null;\n }\n\n #accumulateChatCompletion(chunk: ChatCompletionChunk): ChatCompletionSnapshot {\n let snapshot = this.#currentChatCompletionSnapshot;\n const { choices, ...rest } = chunk;\n if (!snapshot) {\n snapshot = this.#currentChatCompletionSnapshot = {\n ...rest,\n choices: [],\n };\n } else {\n Object.assign(snapshot, rest);\n }\n\n for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices) {\n let choice = snapshot.choices[index];\n if (!choice) {\n choice = snapshot.choices[index] = { finish_reason, index, message: {}, logprobs, ...other };\n }\n\n if (logprobs) {\n if (!choice.logprobs) {\n choice.logprobs = Object.assign({}, logprobs);\n } else {\n const { content, refusal, ...rest } = logprobs;\n assertIsEmpty(rest);\n Object.assign(choice.logprobs, rest);\n\n if (content) {\n choice.logprobs.content ??= [];\n choice.logprobs.content.push(...content);\n }\n\n if (refusal) {\n choice.logprobs.refusal ??= [];\n choice.logprobs.refusal.push(...refusal);\n }\n }\n }\n\n if (finish_reason) {\n choice.finish_reason = finish_reason;\n\n if (this.#params && hasAutoParseableInput(this.#params)) {\n if (finish_reason === 'length') {\n throw new LengthFinishReasonError();\n }\n\n if (finish_reason === 'content_filter') {\n throw new ContentFilterFinishReasonError();\n }\n }\n }\n\n Object.assign(choice, other);\n\n if (!delta) continue; // Shouldn't happen; just in case.\n\n const { content, refusal, function_call, role, tool_calls, ...rest } = delta;\n assertIsEmpty(rest);\n Object.assign(choice.message, rest);\n\n if (refusal) {\n choice.message.refusal = (choice.message.refusal || '') + refusal;\n }\n\n if (role) choice.message.role = role;\n if (function_call) {\n if (!choice.message.function_call) {\n choice.message.function_call = function_call;\n } else {\n if (function_call.name) choice.message.function_call.name = function_call.name;\n if (function_call.arguments) {\n choice.message.function_call.arguments ??= '';\n choice.message.function_call.arguments += function_call.arguments;\n }\n }\n }\n if (content) {\n choice.message.content = (choice.message.content || '') + content;\n\n if (!choice.message.refusal && this.#getAutoParseableResponseFormat()) {\n choice.message.parsed = partialParse(choice.message.content);\n }\n }\n\n if (tool_calls) {\n if (!choice.message.tool_calls) choice.message.tool_calls = [];\n\n for (const { index, id, type, function: fn, ...rest } of tool_calls) {\n const tool_call = (choice.message.tool_calls[index] ??=\n {} as ChatCompletionSnapshot.Choice.Message.ToolCall);\n Object.assign(tool_call, rest);\n if (id) tool_call.id = id;\n if (type) tool_call.type = type;\n if (fn) tool_call.function ??= { name: fn.name ?? '', arguments: '' };\n if (fn?.name) tool_call.function!.name = fn.name;\n if (fn?.arguments) {\n tool_call.function!.arguments += fn.arguments;\n\n if (shouldParseToolCall(this.#params, tool_call)) {\n tool_call.function!.parsed_arguments = partialParse(tool_call.function!.arguments);\n }\n }\n }\n }\n }\n return snapshot;\n }\n\n [Symbol.asyncIterator](this: ChatCompletionStream<ParsedT>): AsyncIterator<ChatCompletionChunk> {\n const pushQueue: ChatCompletionChunk[] = [];\n const readQueue: {\n resolve: (chunk: ChatCompletionChunk | undefined) => void;\n reject: (err: unknown) => void;\n }[] = [];\n let done = false;\n\n this.on('chunk', (chunk) => {\n const reader = readQueue.shift();\n if (reader) {\n reader.resolve(chunk);\n } else {\n pushQueue.push(chunk);\n }\n });\n\n this.on('end', () => {\n done = true;\n for (const reader of readQueue) {\n reader.resolve(undefined);\n }\n readQueue.length = 0;\n });\n\n this.on('abort', (err) => {\n done = true;\n for (const reader of readQueue) {\n reader.reject(err);\n }\n readQueue.length = 0;\n });\n\n this.on('error', (err) => {\n done = true;\n for (const reader of readQueue) {\n reader.reject(err);\n }\n readQueue.length = 0;\n });\n\n return {\n next: async (): Promise<IteratorResult<ChatCompletionChunk>> => {\n if (!pushQueue.length) {\n if (done) {\n return { value: undefined, done: true };\n }\n return new Promise<ChatCompletionChunk | undefined>((resolve, reject) =>\n readQueue.push({ resolve, reject }),\n ).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));\n }\n const chunk = pushQueue.shift()!;\n return { value: chunk, done: false };\n },\n return: async () => {\n this.abort();\n return { value: undefined, done: true };\n },\n };\n }\n\n toReadableStream(): ReadableStream {\n const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);\n return stream.toReadableStream();\n }\n}\n\nfunction finalizeChatCompletion<ParsedT>(\n snapshot: ChatCompletionSnapshot,\n params: ChatCompletionCreateParams | null,\n): ParsedChatCompletion<ParsedT> {\n const { id, choices, created, model, system_fingerprint, ...rest } = snapshot;\n const completion: ChatCompletion = {\n ...rest,\n id,\n choices: choices.map(\n ({ message, finish_reason, index, logprobs, ...choiceRest }): ChatCompletion.Choice => {\n if (!finish_reason) {\n throw new OpenAIError(`missing finish_reason for choice ${index}`);\n }\n\n const { content = null, function_call, tool_calls, ...messageRest } = message;\n const role = message.role as 'assistant'; // this is what we expect; in theory it could be different which would make our types a slight lie but would be fine.\n if (!role) {\n throw new OpenAIError(`missing role for choice ${index}`);\n }\n\n if (function_call) {\n const { arguments: args, name } = function_call;\n if (args == null) {\n throw new OpenAIError(`missing function_call.arguments for choice ${index}`);\n }\n\n if (!name) {\n throw new OpenAIError(`missing function_call.name for choice ${index}`);\n }\n\n return {\n ...choiceRest,\n message: {\n content,\n function_call: { arguments: args, name },\n role,\n refusal: message.refusal ?? null,\n },\n finish_reason,\n index,\n logprobs,\n };\n }\n\n if (tool_calls) {\n return {\n ...choiceRest,\n index,\n finish_reason,\n logprobs,\n message: {\n ...messageRest,\n role,\n content,\n refusal: message.refusal ?? null,\n tool_calls: tool_calls.map((tool_call, i) => {\n const { function: fn, type, id, ...toolRest } = tool_call;\n const { arguments: args, name, ...fnRest } = fn || {};\n if (id == null) {\n throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].id\\n${str(snapshot)}`);\n }\n if (type == null) {\n throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type\\n${str(snapshot)}`);\n }\n if (name == null) {\n throw new OpenAIError(\n `missing choices[${index}].tool_calls[${i}].function.name\\n${str(snapshot)}`,\n );\n }\n if (args == null) {\n throw new OpenAIError(\n `missing choices[${index}].tool_calls[${i}].function.arguments\\n${str(snapshot)}`,\n );\n }\n\n return { ...toolRest, id, type, function: { ...fnRest, name, arguments: args } };\n }),\n },\n };\n }\n return {\n ...choiceRest,\n message: { ...messageRest, content, role, refusal: message.refusal ?? null },\n finish_reason,\n index,\n logprobs,\n };\n },\n ),\n created,\n model,\n object: 'chat.completion',\n ...(system_fingerprint ? { system_fingerprint } : {}),\n };\n\n return maybeParseChatCompletion(completion, params);\n}\n\nfunction str(x: unknown) {\n return JSON.stringify(x);\n}\n\n/**\n * Represents a streamed chunk of a chat completion response returned by model,\n * based on the provided input.\n */\nexport interface ChatCompletionSnapshot {\n /**\n * A unique identifier for the chat completion.\n */\n id: string;\n\n /**\n * A list of chat completion choices. Can be more than one if `n` is greater\n * than 1.\n */\n choices: Array<ChatCompletionSnapshot.Choice>;\n\n /**\n * The Unix timestamp (in seconds) of when the chat completion was created.\n */\n created: number;\n\n /**\n * The model to generate the completion.\n */\n model: string;\n\n // Note we do not include an \"object\" type on the snapshot,\n // because the object is not a valid \"chat.completion\" until finalized.\n // object: 'chat.completion';\n\n /**\n * This fingerprint represents the backend configuration that the model runs with.\n *\n * Can be used in conjunction with the `seed` request parameter to understand when\n * backend changes have been made that might impact determinism.\n */\n system_fingerprint?: string;\n}\n\nexport namespace ChatCompletionSnapshot {\n export interface Choice {\n /**\n * A chat completion delta generated by streamed model responses.\n */\n message: Choice.Message;\n\n /**\n * The reason the model stopped generating tokens. This will be `stop` if the model\n * hit a natural stop point or a provided stop sequence, `length` if the maximum\n * number of tokens specified in the request was reached, `content_filter` if\n * content was omitted due to a flag from our content filters, or `function_call`\n * if the model called a function.\n */\n finish_reason: ChatCompletion.Choice['finish_reason'] | null;\n\n /**\n * Log probability information for the choice.\n */\n logprobs: ChatCompletion.Choice.Logprobs | null;\n\n /**\n * The index of the choice in the list of choices.\n */\n index: number;\n }\n\n export namespace Choice {\n /**\n * A chat completion delta generated by streamed model responses.\n */\n export interface Message {\n /**\n * The contents of the chunk message.\n */\n content?: string | null;\n\n refusal?: string | null;\n\n parsed?: unknown | null;\n\n /**\n * The name and arguments of a function that should be called, as generated by the\n * model.\n */\n function_call?: Message.FunctionCall;\n\n tool_calls?: Array<Message.ToolCall>;\n\n /**\n * The role of the author of this message.\n */\n role?: ChatCompletionRole;\n }\n\n export namespace Message {\n export interface ToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n function: ToolCall.Function;\n\n /**\n * The type of the tool.\n */\n type: 'function';\n }\n\n export namespace ToolCall {\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n parsed_arguments?: unknown;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n }\n\n /**\n * The name and arguments of a function that should be called, as generated by the\n * model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments?: string;\n\n /**\n * The name of the function to call.\n */\n name?: string;\n }\n }\n }\n}\n\ntype AssertIsEmpty<T extends {}> = keyof T extends never ? T : never;\n\n/**\n * Ensures the given argument is an empty object, useful for\n * asserting that all known properties on an object have been\n * destructured.\n */\nfunction assertIsEmpty<T extends {}>(obj: AssertIsEmpty<T>): asserts obj is AssertIsEmpty<T> {\n return;\n}\n\nfunction assertNever(_x: never) {}\n","import {\n type ChatCompletionChunk,\n type ChatCompletionCreateParamsStreaming,\n} from '../resources/chat/completions';\nimport { RunnerOptions, type AbstractChatCompletionRunnerEvents } from './AbstractChatCompletionRunner';\nimport { type ReadableStream } from '../internal/shim-types';\nimport { RunnableTools, type BaseFunctionsArgs } from './RunnableFunction';\nimport { ChatCompletionSnapshot, ChatCompletionStream } from './ChatCompletionStream';\nimport OpenAI from '../index';\nimport { AutoParseableTool } from '../lib/parser';\n\nexport interface ChatCompletionStreamEvents extends AbstractChatCompletionRunnerEvents {\n content: (contentDelta: string, contentSnapshot: string) => void;\n chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;\n}\n\nexport type ChatCompletionStreamingToolRunnerParams<FunctionsArgs extends BaseFunctionsArgs> = Omit<\n ChatCompletionCreateParamsStreaming,\n 'tools'\n> & {\n tools: RunnableTools<FunctionsArgs> | AutoParseableTool<any, true>[];\n};\n\nexport class ChatCompletionStreamingRunner<ParsedT = null>\n extends ChatCompletionStream<ParsedT>\n implements AsyncIterable<ChatCompletionChunk>\n{\n static override fromReadableStream(stream: ReadableStream): ChatCompletionStreamingRunner<null> {\n const runner = new ChatCompletionStreamingRunner(null);\n runner._run(() => runner._fromReadableStream(stream));\n return runner;\n }\n\n static runTools<T extends (string | object)[], ParsedT = null>(\n client: OpenAI,\n params: ChatCompletionStreamingToolRunnerParams<T>,\n options?: RunnerOptions,\n ): ChatCompletionStreamingRunner<ParsedT> {\n const runner = new ChatCompletionStreamingRunner<ParsedT>(\n // @ts-expect-error TODO these types are incompatible\n params,\n );\n const opts = {\n ...options,\n headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runTools' },\n };\n runner._run(() => runner._runTools(client, params, opts));\n return runner;\n }\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ChatCompletionsAPI from './completions';\nimport * as CompletionsAPI from '../../completions';\nimport * as Shared from '../../shared';\nimport * as MessagesAPI from './messages';\nimport { MessageListParams, Messages } from './messages';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { Stream } from '../../../core/streaming';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nimport { ChatCompletionRunner } from '../../../lib/ChatCompletionRunner';\nimport { ChatCompletionStreamingRunner } from '../../../lib/ChatCompletionStreamingRunner';\nimport { RunnerOptions } from '../../../lib/AbstractChatCompletionRunner';\nimport { ChatCompletionToolRunnerParams } from '../../../lib/ChatCompletionRunner';\nimport { ChatCompletionStreamingToolRunnerParams } from '../../../lib/ChatCompletionStreamingRunner';\nimport { ChatCompletionStream, type ChatCompletionStreamParams } from '../../../lib/ChatCompletionStream';\nimport { ExtractParsedContentFromParams, parseChatCompletion, validateInputTools } from '../../../lib/parser';\n\n/**\n * Given a list of messages comprising a conversation, the model will return a response.\n */\nexport class Completions extends APIResource {\n messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);\n\n /**\n * **Starting a new project?** We recommend trying\n * [Responses](https://platform.openai.com/docs/api-reference/responses) to take\n * advantage of the latest OpenAI platform features. Compare\n * [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).\n *\n * ---\n *\n * Creates a model response for the given chat conversation. Learn more in the\n * [text generation](https://platform.openai.com/docs/guides/text-generation),\n * [vision](https://platform.openai.com/docs/guides/vision), and\n * [audio](https://platform.openai.com/docs/guides/audio) guides.\n *\n * Parameter support can differ depending on the model used to generate the\n * response, particularly for newer reasoning models. Parameters that are only\n * supported for reasoning models are noted below. For the current state of\n * unsupported parameters in reasoning models,\n * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).\n *\n * Returns a chat completion object, or a streamed sequence of chat completion\n * chunk objects if the request is streamed.\n *\n * @example\n * ```ts\n * const chatCompletion = await client.chat.completions.create(\n * {\n * messages: [{ content: 'string', role: 'developer' }],\n * model: 'gpt-5.4',\n * },\n * );\n * ```\n */\n create(body: ChatCompletionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<ChatCompletion>;\n create(\n body: ChatCompletionCreateParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<ChatCompletionChunk>>;\n create(\n body: ChatCompletionCreateParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;\n create(\n body: ChatCompletionCreateParams,\n options?: RequestOptions,\n ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {\n return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as\n | APIPromise<ChatCompletion>\n | APIPromise<Stream<ChatCompletionChunk>>;\n }\n\n /**\n * Get a stored chat completion. Only Chat Completions that have been created with\n * the `store` parameter set to `true` will be returned.\n *\n * @example\n * ```ts\n * const chatCompletion =\n * await client.chat.completions.retrieve('completion_id');\n * ```\n */\n retrieve(completionID: string, options?: RequestOptions): APIPromise<ChatCompletion> {\n return this._client.get(path`/chat/completions/${completionID}`, options);\n }\n\n /**\n * Modify a stored chat completion. Only Chat Completions that have been created\n * with the `store` parameter set to `true` can be modified. Currently, the only\n * supported modification is to update the `metadata` field.\n *\n * @example\n * ```ts\n * const chatCompletion = await client.chat.completions.update(\n * 'completion_id',\n * { metadata: { foo: 'string' } },\n * );\n * ```\n */\n update(\n completionID: string,\n body: ChatCompletionUpdateParams,\n options?: RequestOptions,\n ): APIPromise<ChatCompletion> {\n return this._client.post(path`/chat/completions/${completionID}`, { body, ...options });\n }\n\n /**\n * List stored Chat Completions. Only Chat Completions that have been stored with\n * the `store` parameter set to `true` will be returned.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const chatCompletion of client.chat.completions.list()) {\n * // ...\n * }\n * ```\n */\n list(\n query: ChatCompletionListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<ChatCompletionsPage, ChatCompletion> {\n return this._client.getAPIList('/chat/completions', CursorPage<ChatCompletion>, { query, ...options });\n }\n\n /**\n * Delete a stored chat completion. Only Chat Completions that have been created\n * with the `store` parameter set to `true` can be deleted.\n *\n * @example\n * ```ts\n * const chatCompletionDeleted =\n * await client.chat.completions.delete('completion_id');\n * ```\n */\n delete(completionID: string, options?: RequestOptions): APIPromise<ChatCompletionDeleted> {\n return this._client.delete(path`/chat/completions/${completionID}`, options);\n }\n\n parse<Params extends ChatCompletionParseParams, ParsedT = ExtractParsedContentFromParams<Params>>(\n body: Params,\n options?: RequestOptions,\n ): APIPromise<ParsedChatCompletion<ParsedT>> {\n validateInputTools(body.tools);\n\n return this._client.chat.completions\n .create(body, {\n ...options,\n headers: {\n ...options?.headers,\n 'X-Stainless-Helper-Method': 'chat.completions.parse',\n },\n })\n ._thenUnwrap((completion) => parseChatCompletion(completion, body));\n }\n\n /**\n * A convenience helper for using tool calls with the /chat/completions endpoint\n * which automatically calls the JavaScript functions you provide and sends their\n * results back to the /chat/completions endpoint, looping as long as the model\n * requests function calls.\n *\n * For more details and examples, see\n * [the docs](https://github.com/openai/openai-node#automated-function-calls)\n */\n runTools<\n Params extends ChatCompletionToolRunnerParams<any>,\n ParsedT = ExtractParsedContentFromParams<Params>,\n >(body: Params, options?: RunnerOptions): ChatCompletionRunner<ParsedT>;\n\n runTools<\n Params extends ChatCompletionStreamingToolRunnerParams<any>,\n ParsedT = ExtractParsedContentFromParams<Params>,\n >(body: Params, options?: RunnerOptions): ChatCompletionStreamingRunner<ParsedT>;\n\n runTools<\n Params extends ChatCompletionToolRunnerParams<any> | ChatCompletionStreamingToolRunnerParams<any>,\n ParsedT = ExtractParsedContentFromParams<Params>,\n >(\n body: Params,\n options?: RunnerOptions,\n ): ChatCompletionRunner<ParsedT> | ChatCompletionStreamingRunner<ParsedT> {\n if (body.stream) {\n return ChatCompletionStreamingRunner.runTools(\n this._client,\n body as ChatCompletionStreamingToolRunnerParams<any>,\n options,\n );\n }\n\n return ChatCompletionRunner.runTools(this._client, body as ChatCompletionToolRunnerParams<any>, options);\n }\n\n /**\n * Creates a chat completion stream\n */\n stream<Params extends ChatCompletionStreamParams, ParsedT = ExtractParsedContentFromParams<Params>>(\n body: Params,\n options?: RequestOptions,\n ): ChatCompletionStream<ParsedT> {\n return ChatCompletionStream.createChatCompletion(this._client, body, options);\n }\n}\n\nexport interface ParsedFunction extends ChatCompletionMessageFunctionToolCall.Function {\n parsed_arguments?: unknown;\n}\n\nexport interface ParsedFunctionToolCall extends ChatCompletionMessageFunctionToolCall {\n function: ParsedFunction;\n}\n\nexport interface ParsedChatCompletionMessage<ParsedT> extends ChatCompletionMessage {\n parsed: ParsedT | null;\n tool_calls?: Array<ParsedFunctionToolCall>;\n}\n\nexport interface ParsedChoice<ParsedT> extends ChatCompletion.Choice {\n message: ParsedChatCompletionMessage<ParsedT>;\n}\n\nexport interface ParsedChatCompletion<ParsedT> extends ChatCompletion {\n choices: Array<ParsedChoice<ParsedT>>;\n}\n\nexport type ChatCompletionParseParams = ChatCompletionCreateParamsNonStreaming;\n\nexport { ChatCompletionStreamingRunner } from '../../../lib/ChatCompletionStreamingRunner';\nexport {\n type RunnableFunctionWithParse,\n type RunnableFunctionWithoutParse,\n ParsingToolFunction,\n} from '../../../lib/RunnableFunction';\nexport { type ChatCompletionToolRunnerParams } from '../../../lib/ChatCompletionRunner';\nexport { type ChatCompletionStreamingToolRunnerParams } from '../../../lib/ChatCompletionStreamingRunner';\nexport { ChatCompletionStream, type ChatCompletionStreamParams } from '../../../lib/ChatCompletionStream';\nexport { ChatCompletionRunner } from '../../../lib/ChatCompletionRunner';\n\nexport type ChatCompletionsPage = CursorPage<ChatCompletion>;\n\nexport type ChatCompletionStoreMessagesPage = CursorPage<ChatCompletionStoreMessage>;\n\n/**\n * Represents a chat completion response returned by model, based on the provided\n * input.\n */\nexport interface ChatCompletion {\n /**\n * A unique identifier for the chat completion.\n */\n id: string;\n\n /**\n * A list of chat completion choices. Can be more than one if `n` is greater\n * than 1.\n */\n choices: Array<ChatCompletion.Choice>;\n\n /**\n * The Unix timestamp (in seconds) of when the chat completion was created.\n */\n created: number;\n\n /**\n * The model used for the chat completion.\n */\n model: string;\n\n /**\n * The object type, which is always `chat.completion`.\n */\n object: 'chat.completion';\n\n /**\n * Specifies the processing type used for serving the request.\n *\n * - If set to 'auto', then the request will be processed with the service tier\n * configured in the Project settings. Unless otherwise configured, the Project\n * will use 'default'.\n * - If set to 'default', then the request will be processed with the standard\n * pricing and performance for the selected model.\n * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n * '[priority](https://openai.com/api-priority-processing/)', then the request\n * will be processed with the corresponding service tier.\n * - When not set, the default behavior is 'auto'.\n *\n * When the `service_tier` parameter is set, the response body will include the\n * `service_tier` value based on the processing mode actually used to serve the\n * request. This response value may be different from the value set in the\n * parameter.\n */\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n /**\n * @deprecated This fingerprint represents the backend configuration that the model\n * runs with.\n *\n * Can be used in conjunction with the `seed` request parameter to understand when\n * backend changes have been made that might impact determinism.\n */\n system_fingerprint?: string;\n\n /**\n * Usage statistics for the completion request.\n */\n usage?: CompletionsAPI.CompletionUsage;\n}\n\nexport namespace ChatCompletion {\n export interface Choice {\n /**\n * The reason the model stopped generating tokens. This will be `stop` if the model\n * hit a natural stop point or a provided stop sequence, `length` if the maximum\n * number of tokens specified in the request was reached, `content_filter` if\n * content was omitted due to a flag from our content filters, `tool_calls` if the\n * model called a tool, or `function_call` (deprecated) if the model called a\n * function.\n */\n finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';\n\n /**\n * The index of the choice in the list of choices.\n */\n index: number;\n\n /**\n * Log probability information for the choice.\n */\n logprobs: Choice.Logprobs | null;\n\n /**\n * A chat completion message generated by the model.\n */\n message: ChatCompletionsAPI.ChatCompletionMessage;\n }\n\n export namespace Choice {\n /**\n * Log probability information for the choice.\n */\n export interface Logprobs {\n /**\n * A list of message content tokens with log probability information.\n */\n content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n\n /**\n * A list of message refusal tokens with log probability information.\n */\n refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n }\n }\n}\n\n/**\n * Constrains the tools available to the model to a pre-defined set.\n */\nexport interface ChatCompletionAllowedToolChoice {\n /**\n * Constrains the tools available to the model to a pre-defined set.\n */\n allowed_tools: ChatCompletionAllowedTools;\n\n /**\n * Allowed tool configuration type. Always `allowed_tools`.\n */\n type: 'allowed_tools';\n}\n\n/**\n * Messages sent by the model in response to user messages.\n */\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * Data about a previous audio response from the model.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n audio?: ChatCompletionAssistantMessageParam.Audio | null;\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;\n\n /**\n * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n * function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The refusal message by the assistant.\n */\n refusal?: string | null;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * Data about a previous audio response from the model.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n export interface Audio {\n /**\n * Unique identifier for a previous audio response from the model.\n */\n id: string;\n }\n\n /**\n * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n * function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\n/**\n * If the audio output modality is requested, this object contains data about the\n * audio response from the model.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\nexport interface ChatCompletionAudio {\n /**\n * Unique identifier for this audio response.\n */\n id: string;\n\n /**\n * Base64 encoded audio bytes generated by the model, in the format specified in\n * the request.\n */\n data: string;\n\n /**\n * The Unix timestamp (in seconds) for when this audio response will no longer be\n * accessible on the server for use in multi-turn conversations.\n */\n expires_at: number;\n\n /**\n * Transcript of the audio generated by the model.\n */\n transcript: string;\n}\n\n/**\n * Parameters for audio output. Required when audio output is requested with\n * `modalities: [\"audio\"]`.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\nexport interface ChatCompletionAudioParam {\n /**\n * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,\n * or `pcm16`.\n */\n format: 'wav' | 'aac' | 'mp3' | 'flac' | 'opus' | 'pcm16';\n\n /**\n * The voice the model uses to respond. Supported built-in voices are `alloy`,\n * `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, `shimmer`,\n * `marin`, and `cedar`.\n */\n voice:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n}\n\n/**\n * Represents a streamed chunk of a chat completion response returned by the model,\n * based on the provided input.\n * [Learn more](https://platform.openai.com/docs/guides/streaming-responses).\n */\nexport interface ChatCompletionChunk {\n /**\n * A unique identifier for the chat completion. Each chunk has the same ID.\n */\n id: string;\n\n /**\n * A list of chat completion choices. Can contain more than one elements if `n` is\n * greater than 1. Can also be empty for the last chunk if you set\n * `stream_options: {\"include_usage\": true}`.\n */\n choices: Array<ChatCompletionChunk.Choice>;\n\n /**\n * The Unix timestamp (in seconds) of when the chat completion was created. Each\n * chunk has the same timestamp.\n */\n created: number;\n\n /**\n * The model to generate the completion.\n */\n model: string;\n\n /**\n * The object type, which is always `chat.completion.chunk`.\n */\n object: 'chat.completion.chunk';\n\n /**\n * Specifies the processing type used for serving the request.\n *\n * - If set to 'auto', then the request will be processed with the service tier\n * configured in the Project settings. Unless otherwise configured, the Project\n * will use 'default'.\n * - If set to 'default', then the request will be processed with the standard\n * pricing and performance for the selected model.\n * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n * '[priority](https://openai.com/api-priority-processing/)', then the request\n * will be processed with the corresponding service tier.\n * - When not set, the default behavior is 'auto'.\n *\n * When the `service_tier` parameter is set, the response body will include the\n * `service_tier` value based on the processing mode actually used to serve the\n * request. This response value may be different from the value set in the\n * parameter.\n */\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n /**\n * @deprecated This fingerprint represents the backend configuration that the model\n * runs with. Can be used in conjunction with the `seed` request parameter to\n * understand when backend changes have been made that might impact determinism.\n */\n system_fingerprint?: string;\n\n /**\n * An optional field that will only be present when you set\n * `stream_options: {\"include_usage\": true}` in your request. When present, it\n * contains a null value **except for the last chunk** which contains the token\n * usage statistics for the entire request.\n *\n * **NOTE:** If the stream is interrupted or cancelled, you may not receive the\n * final usage chunk which contains the total token usage for the request.\n */\n usage?: CompletionsAPI.CompletionUsage | null;\n}\n\nexport namespace ChatCompletionChunk {\n export interface Choice {\n /**\n * A chat completion delta generated by streamed model responses.\n */\n delta: Choice.Delta;\n\n /**\n * The reason the model stopped generating tokens. This will be `stop` if the model\n * hit a natural stop point or a provided stop sequence, `length` if the maximum\n * number of tokens specified in the request was reached, `content_filter` if\n * content was omitted due to a flag from our content filters, `tool_calls` if the\n * model called a tool, or `function_call` (deprecated) if the model called a\n * function.\n */\n finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;\n\n /**\n * The index of the choice in the list of choices.\n */\n index: number;\n\n /**\n * Log probability information for the choice.\n */\n logprobs?: Choice.Logprobs | null;\n }\n\n export namespace Choice {\n /**\n * A chat completion delta generated by streamed model responses.\n */\n export interface Delta {\n /**\n * The contents of the chunk message.\n */\n content?: string | null;\n\n /**\n * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n * function that should be called, as generated by the model.\n */\n function_call?: Delta.FunctionCall;\n\n /**\n * The refusal message generated by the model.\n */\n refusal?: string | null;\n\n /**\n * The role of the author of this message.\n */\n role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';\n\n tool_calls?: Array<Delta.ToolCall>;\n }\n\n export namespace Delta {\n /**\n * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n * function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments?: string;\n\n /**\n * The name of the function to call.\n */\n name?: string;\n }\n\n export interface ToolCall {\n index: number;\n\n /**\n * The ID of the tool call.\n */\n id?: string;\n\n function?: ToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type?: 'function';\n }\n\n export namespace ToolCall {\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments?: string;\n\n /**\n * The name of the function to call.\n */\n name?: string;\n }\n }\n }\n\n /**\n * Log probability information for the choice.\n */\n export interface Logprobs {\n /**\n * A list of message content tokens with log probability information.\n */\n content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n\n /**\n * A list of message refusal tokens with log probability information.\n */\n refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;\n }\n }\n}\n\n/**\n * Learn about\n * [text inputs](https://platform.openai.com/docs/guides/text-generation).\n */\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage\n | ChatCompletionContentPartInputAudio\n | ChatCompletionContentPart.File;\n\nexport namespace ChatCompletionContentPart {\n /**\n * Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text\n * generation.\n */\n export interface File {\n file: File.File;\n\n /**\n * The type of the content part. Always `file`.\n */\n type: 'file';\n }\n\n export namespace File {\n export interface File {\n /**\n * The base64 encoded file data, used when passing the file to the model as a\n * string.\n */\n file_data?: string;\n\n /**\n * The ID of an uploaded file to use as input.\n */\n file_id?: string;\n\n /**\n * The name of the file, used when passing the file to the model as a string.\n */\n filename?: string;\n }\n }\n}\n\n/**\n * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).\n */\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\n/**\n * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).\n */\nexport interface ChatCompletionContentPartInputAudio {\n input_audio: ChatCompletionContentPartInputAudio.InputAudio;\n\n /**\n * The type of the content part. Always `input_audio`.\n */\n type: 'input_audio';\n}\n\nexport namespace ChatCompletionContentPartInputAudio {\n export interface InputAudio {\n /**\n * Base64 encoded audio data.\n */\n data: string;\n\n /**\n * The format of the encoded audio data. Currently supports \"wav\" and \"mp3\".\n */\n format: 'wav' | 'mp3';\n }\n}\n\nexport interface ChatCompletionContentPartRefusal {\n /**\n * The refusal message generated by the model.\n */\n refusal: string;\n\n /**\n * The type of the content part.\n */\n type: 'refusal';\n}\n\n/**\n * Learn about\n * [text inputs](https://platform.openai.com/docs/guides/text-generation).\n */\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\n/**\n * A custom tool that processes input using a specified format.\n */\nexport interface ChatCompletionCustomTool {\n /**\n * Properties of the custom tool.\n */\n custom: ChatCompletionCustomTool.Custom;\n\n /**\n * The type of the custom tool. Always `custom`.\n */\n type: 'custom';\n}\n\nexport namespace ChatCompletionCustomTool {\n /**\n * Properties of the custom tool.\n */\n export interface Custom {\n /**\n * The name of the custom tool, used to identify it in tool calls.\n */\n name: string;\n\n /**\n * Optional description of the custom tool, used to provide more context.\n */\n description?: string;\n\n /**\n * The input format for the custom tool. Default is unconstrained text.\n */\n format?: Custom.Text | Custom.Grammar;\n }\n\n export namespace Custom {\n /**\n * Unconstrained free-form text.\n */\n export interface Text {\n /**\n * Unconstrained text format. Always `text`.\n */\n type: 'text';\n }\n\n /**\n * A grammar defined by the user.\n */\n export interface Grammar {\n /**\n * Your chosen grammar.\n */\n grammar: Grammar.Grammar;\n\n /**\n * Grammar format. Always `grammar`.\n */\n type: 'grammar';\n }\n\n export namespace Grammar {\n /**\n * Your chosen grammar.\n */\n export interface Grammar {\n /**\n * The grammar definition.\n */\n definition: string;\n\n /**\n * The syntax of the grammar definition. One of `lark` or `regex`.\n */\n syntax: 'lark' | 'regex';\n }\n }\n }\n}\n\nexport interface ChatCompletionDeleted {\n /**\n * The ID of the chat completion that was deleted.\n */\n id: string;\n\n /**\n * Whether the chat completion was deleted.\n */\n deleted: boolean;\n\n /**\n * The type of object being deleted.\n */\n object: 'chat.completion.deleted';\n}\n\n/**\n * Developer-provided instructions that the model should follow, regardless of\n * messages sent by the user. With o1 models and newer, `developer` messages\n * replace the previous `system` messages.\n */\nexport interface ChatCompletionDeveloperMessageParam {\n /**\n * The contents of the developer message.\n */\n content: string | Array<ChatCompletionContentPartText>;\n\n /**\n * The role of the messages author, in this case `developer`.\n */\n role: 'developer';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\n/**\n * Specifying a particular function via `{\"name\": \"my_function\"}` forces the model\n * to call that function.\n */\nexport interface ChatCompletionFunctionCallOption {\n /**\n * The name of the function to call.\n */\n name: string;\n}\n\n/**\n * @deprecated\n */\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The contents of the function message.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n\n/**\n * A function tool that can be used to generate a response.\n */\nexport interface ChatCompletionFunctionTool {\n function: Shared.FunctionDefinition;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\n/**\n * A chat completion message generated by the model.\n */\nexport interface ChatCompletionMessage {\n /**\n * The contents of the message.\n */\n content: string | null;\n\n /**\n * The refusal message generated by the model.\n */\n refusal: string | null;\n\n /**\n * The role of the author of this message.\n */\n role: 'assistant';\n\n /**\n * Annotations for the message, when applicable, as when using the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).\n */\n annotations?: Array<ChatCompletionMessage.Annotation>;\n\n /**\n * If the audio output modality is requested, this object contains data about the\n * audio response from the model.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n audio?: ChatCompletionAudio | null;\n\n /**\n * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n * function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionMessage.FunctionCall | null;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionMessage {\n /**\n * A URL citation when using web search.\n */\n export interface Annotation {\n /**\n * The type of the URL citation. Always `url_citation`.\n */\n type: 'url_citation';\n\n /**\n * A URL citation when using web search.\n */\n url_citation: Annotation.URLCitation;\n }\n\n export namespace Annotation {\n /**\n * A URL citation when using web search.\n */\n export interface URLCitation {\n /**\n * The index of the last character of the URL citation in the message.\n */\n end_index: number;\n\n /**\n * The index of the first character of the URL citation in the message.\n */\n start_index: number;\n\n /**\n * The title of the web resource.\n */\n title: string;\n\n /**\n * The URL of the web resource.\n */\n url: string;\n }\n }\n\n /**\n * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a\n * function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\n/**\n * A call to a custom tool created by the model.\n */\nexport interface ChatCompletionMessageCustomToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The custom tool that the model called.\n */\n custom: ChatCompletionMessageCustomToolCall.Custom;\n\n /**\n * The type of the tool. Always `custom`.\n */\n type: 'custom';\n}\n\nexport namespace ChatCompletionMessageCustomToolCall {\n /**\n * The custom tool that the model called.\n */\n export interface Custom {\n /**\n * The input for the custom tool call generated by the model.\n */\n input: string;\n\n /**\n * The name of the custom tool to call.\n */\n name: string;\n }\n}\n\n/**\n * A call to a function tool created by the model.\n */\nexport interface ChatCompletionMessageFunctionToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageFunctionToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageFunctionToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\n/**\n * Developer-provided instructions that the model should follow, regardless of\n * messages sent by the user. With o1 models and newer, `developer` messages\n * replace the previous `system` messages.\n */\nexport type ChatCompletionMessageParam =\n | ChatCompletionDeveloperMessageParam\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\n/**\n * A call to a function tool created by the model.\n */\nexport type ChatCompletionMessageToolCall =\n | ChatCompletionMessageFunctionToolCall\n | ChatCompletionMessageCustomToolCall;\n\nexport type ChatCompletionModality = 'text' | 'audio';\n\n/**\n * Specifies a tool the model should use. Use to force the model to call a specific\n * function.\n */\nexport interface ChatCompletionNamedToolChoice {\n function: ChatCompletionNamedToolChoice.Function;\n\n /**\n * For function calling, the type is always `function`.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionNamedToolChoice {\n export interface Function {\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\n/**\n * Specifies a tool the model should use. Use to force the model to call a specific\n * custom tool.\n */\nexport interface ChatCompletionNamedToolChoiceCustom {\n custom: ChatCompletionNamedToolChoiceCustom.Custom;\n\n /**\n * For custom tool calling, the type is always `custom`.\n */\n type: 'custom';\n}\n\nexport namespace ChatCompletionNamedToolChoiceCustom {\n export interface Custom {\n /**\n * The name of the custom tool to call.\n */\n name: string;\n }\n}\n\n/**\n * Static predicted output content, such as the content of a text file that is\n * being regenerated.\n */\nexport interface ChatCompletionPredictionContent {\n /**\n * The content that should be matched when generating a model response. If\n * generated tokens would match this content, the entire model response can be\n * returned much more quickly.\n */\n content: string | Array<ChatCompletionContentPartText>;\n\n /**\n * The type of the predicted content you want to provide. This type is currently\n * always `content`.\n */\n type: 'content';\n}\n\n/**\n * The role of the author of a message\n */\nexport type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';\n\n/**\n * A chat completion message generated by the model.\n */\nexport interface ChatCompletionStoreMessage extends ChatCompletionMessage {\n /**\n * The identifier of the chat message.\n */\n id: string;\n\n /**\n * If a content parts array was provided, this is an array of `text` and\n * `image_url` parts. Otherwise, null.\n */\n content_parts?: Array<ChatCompletionContentPartText | ChatCompletionContentPartImage> | null;\n}\n\n/**\n * Options for streaming response. Only set this when you set `stream: true`.\n */\nexport interface ChatCompletionStreamOptions {\n /**\n * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n * characters to an `obfuscation` field on streaming delta events to normalize\n * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n * fields are included by default, but add a small amount of overhead to the data\n * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n * you trust the network links between your application and the OpenAI API.\n */\n include_obfuscation?: boolean;\n\n /**\n * If set, an additional chunk will be streamed before the `data: [DONE]` message.\n * The `usage` field on this chunk shows the token usage statistics for the entire\n * request, and the `choices` field will always be an empty array.\n *\n * All other chunks will also include a `usage` field, but with a null value.\n * **NOTE:** If the stream is interrupted, you may not receive the final usage\n * chunk which contains the total token usage for the request.\n */\n include_usage?: boolean;\n}\n\n/**\n * Developer-provided instructions that the model should follow, regardless of\n * messages sent by the user. With o1 models and newer, use `developer` messages\n * for this purpose instead.\n */\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string | Array<ChatCompletionContentPartText>;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionTokenLogprob {\n /**\n * The token.\n */\n token: string;\n\n /**\n * A list of integers representing the UTF-8 bytes representation of the token.\n * Useful in instances where characters are represented by multiple tokens and\n * their byte representations must be combined to generate the correct text\n * representation. Can be `null` if there is no bytes representation for the token.\n */\n bytes: Array<number> | null;\n\n /**\n * The log probability of this token, if it is within the top 20 most likely\n * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very\n * unlikely.\n */\n logprob: number;\n\n /**\n * List of the most likely tokens and their log probability, at this token\n * position. In rare cases, there may be fewer than the number of requested\n * `top_logprobs` returned.\n */\n top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;\n}\n\nexport namespace ChatCompletionTokenLogprob {\n export interface TopLogprob {\n /**\n * The token.\n */\n token: string;\n\n /**\n * A list of integers representing the UTF-8 bytes representation of the token.\n * Useful in instances where characters are represented by multiple tokens and\n * their byte representations must be combined to generate the correct text\n * representation. Can be `null` if there is no bytes representation for the token.\n */\n bytes: Array<number> | null;\n\n /**\n * The log probability of this token, if it is within the top 20 most likely\n * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very\n * unlikely.\n */\n logprob: number;\n }\n}\n\n/**\n * A function tool that can be used to generate a response.\n */\nexport type ChatCompletionTool = ChatCompletionFunctionTool | ChatCompletionCustomTool;\n\n/**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tool and instead generates a message. `auto` means the model can\n * pick between generating a message or calling one or more tools. `required` means\n * the model must call one or more tools. Specifying a particular tool via\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n *\n * `none` is the default when no tools are present. `auto` is the default if tools\n * are present.\n */\nexport type ChatCompletionToolChoiceOption =\n | 'none'\n | 'auto'\n | 'required'\n | ChatCompletionAllowedToolChoice\n | ChatCompletionNamedToolChoice\n | ChatCompletionNamedToolChoiceCustom;\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string | Array<ChatCompletionContentPartText>;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\n/**\n * Messages sent by an end user, containing prompts or additional context\n * information.\n */\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\n/**\n * Constrains the tools available to the model to a pre-defined set.\n */\nexport interface ChatCompletionAllowedTools {\n /**\n * Constrains the tools available to the model to a pre-defined set.\n *\n * `auto` allows the model to pick from among the allowed tools and generate a\n * message.\n *\n * `required` requires the model to call one or more of the allowed tools.\n */\n mode: 'auto' | 'required';\n\n /**\n * A list of tool definitions that the model should be allowed to call.\n *\n * For the Chat Completions API, the list of tool definitions might look like:\n *\n * ```json\n * [\n * { \"type\": \"function\", \"function\": { \"name\": \"get_weather\" } },\n * { \"type\": \"function\", \"function\": { \"name\": \"get_time\" } }\n * ]\n * ```\n */\n tools: Array<{ [key: string]: unknown }>;\n}\n\nexport type ChatCompletionReasoningEffort = Shared.ReasoningEffort | null;\n\nexport type ChatCompletionCreateParams =\n | ChatCompletionCreateParamsNonStreaming\n | ChatCompletionCreateParamsStreaming;\n\nexport interface ChatCompletionCreateParamsBase {\n /**\n * A list of messages comprising the conversation so far. Depending on the\n * [model](https://platform.openai.com/docs/models) you use, different message\n * types (modalities) are supported, like\n * [text](https://platform.openai.com/docs/guides/text-generation),\n * [images](https://platform.openai.com/docs/guides/vision), and\n * [audio](https://platform.openai.com/docs/guides/audio).\n */\n messages: Array<ChatCompletionMessageParam>;\n\n /**\n * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model: (string & {}) | Shared.ChatModel;\n\n /**\n * Parameters for audio output. Required when audio output is requested with\n * `modalities: [\"audio\"]`.\n * [Learn more](https://platform.openai.com/docs/guides/audio).\n */\n audio?: ChatCompletionAudioParam | null;\n\n /**\n * Number between -2.0 and 2.0. Positive values penalize new tokens based on their\n * existing frequency in the text so far, decreasing the model's likelihood to\n * repeat the same line verbatim.\n */\n frequency_penalty?: number | null;\n\n /**\n * @deprecated Deprecated in favor of `tool_choice`.\n *\n * Controls which (if any) function is called by the model.\n *\n * `none` means the model will not call a function and instead generates a message.\n *\n * `auto` means the model can pick between generating a message or calling a\n * function.\n *\n * Specifying a particular function via `{\"name\": \"my_function\"}` forces the model\n * to call that function.\n *\n * `none` is the default when no functions are present. `auto` is the default if\n * functions are present.\n */\n function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;\n\n /**\n * @deprecated Deprecated in favor of `tools`.\n *\n * A list of functions the model may generate JSON inputs for.\n */\n functions?: Array<ChatCompletionCreateParams.Function>;\n\n /**\n * Modify the likelihood of specified tokens appearing in the completion.\n *\n * Accepts a JSON object that maps tokens (specified by their token ID in the\n * tokenizer) to an associated bias value from -100 to 100. Mathematically, the\n * bias is added to the logits generated by the model prior to sampling. The exact\n * effect will vary per model, but values between -1 and 1 should decrease or\n * increase likelihood of selection; values like -100 or 100 should result in a ban\n * or exclusive selection of the relevant token.\n */\n logit_bias?: { [key: string]: number } | null;\n\n /**\n * Whether to return log probabilities of the output tokens or not. If true,\n * returns the log probabilities of each output token returned in the `content` of\n * `message`.\n */\n logprobs?: boolean | null;\n\n /**\n * An upper bound for the number of tokens that can be generated for a completion,\n * including visible output tokens and\n * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n */\n max_completion_tokens?: number | null;\n\n /**\n * @deprecated The maximum number of [tokens](/tokenizer) that can be generated in\n * the chat completion. This value can be used to control\n * [costs](https://openai.com/api/pricing/) for text generated via API.\n *\n * This value is now deprecated in favor of `max_completion_tokens`, and is not\n * compatible with\n * [o-series models](https://platform.openai.com/docs/guides/reasoning).\n */\n max_tokens?: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * Output types that you would like the model to generate. Most models are capable\n * of generating text, which is the default:\n *\n * `[\"text\"]`\n *\n * The `gpt-4o-audio-preview` model can also be used to\n * [generate audio](https://platform.openai.com/docs/guides/audio). To request that\n * this model generate both text and audio responses, you can use:\n *\n * `[\"text\", \"audio\"]`\n */\n modalities?: Array<'text' | 'audio'> | null;\n\n /**\n * How many chat completion choices to generate for each input message. Note that\n * you will be charged based on the number of generated tokens across all of the\n * choices. Keep `n` as `1` to minimize costs.\n */\n n?: number | null;\n\n /**\n * Whether to enable\n * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n * during tool use.\n */\n parallel_tool_calls?: boolean;\n\n /**\n * Static predicted output content, such as the content of a text file that is\n * being regenerated.\n */\n prediction?: ChatCompletionPredictionContent | null;\n\n /**\n * Number between -2.0 and 2.0. Positive values penalize new tokens based on\n * whether they appear in the text so far, increasing the model's likelihood to\n * talk about new topics.\n */\n presence_penalty?: number | null;\n\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n prompt_cache_key?: string;\n\n /**\n * The retention policy for the prompt cache. Set to `24h` to enable extended\n * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n * of 24 hours.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n */\n prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * An object specifying the format that the model must output.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n response_format?:\n | Shared.ResponseFormatText\n | Shared.ResponseFormatJSONSchema\n | Shared.ResponseFormatJSONObject;\n\n /**\n * A stable identifier used to help detect users of your application that may be\n * violating OpenAI's usage policies. The IDs should be a string that uniquely\n * identifies each user, with a maximum length of 64 characters. We recommend\n * hashing their username or email address, in order to avoid sending us any\n * identifying information.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n safety_identifier?: string;\n\n /**\n * @deprecated This feature is in Beta. If specified, our system will make a best\n * effort to sample deterministically, such that repeated requests with the same\n * `seed` and parameters should return the same result. Determinism is not\n * guaranteed, and you should refer to the `system_fingerprint` response parameter\n * to monitor changes in the backend.\n */\n seed?: number | null;\n\n /**\n * Specifies the processing type used for serving the request.\n *\n * - If set to 'auto', then the request will be processed with the service tier\n * configured in the Project settings. Unless otherwise configured, the Project\n * will use 'default'.\n * - If set to 'default', then the request will be processed with the standard\n * pricing and performance for the selected model.\n * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n * '[priority](https://openai.com/api-priority-processing/)', then the request\n * will be processed with the corresponding service tier.\n * - When not set, the default behavior is 'auto'.\n *\n * When the `service_tier` parameter is set, the response body will include the\n * `service_tier` value based on the processing mode actually used to serve the\n * request. This response value may be different from the value set in the\n * parameter.\n */\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n /**\n * Not supported with latest reasoning models `o3` and `o4-mini`.\n *\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n */\n stop?: string | null | Array<string>;\n\n /**\n * Whether or not to store the output of this chat completion request for use in\n * our [model distillation](https://platform.openai.com/docs/guides/distillation)\n * or [evals](https://platform.openai.com/docs/guides/evals) products.\n *\n * Supports text and image inputs. Note: image inputs over 8MB will be dropped.\n */\n store?: boolean | null;\n\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)\n * for more information, along with the\n * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)\n * guide for more information on how to handle the streaming events.\n */\n stream?: boolean | null;\n\n /**\n * Options for streaming response. Only set this when you set `stream: true`.\n */\n stream_options?: ChatCompletionStreamOptions | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic. We generally recommend altering this or `top_p` but\n * not both.\n */\n temperature?: number | null;\n\n /**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tool and instead generates a message. `auto` means the model can\n * pick between generating a message or calling one or more tools. `required` means\n * the model must call one or more tools. Specifying a particular tool via\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n *\n * `none` is the default when no tools are present. `auto` is the default if tools\n * are present.\n */\n tool_choice?: ChatCompletionToolChoiceOption;\n\n /**\n * A list of tools the model may call. You can provide either\n * [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)\n * or [function tools](https://platform.openai.com/docs/guides/function-calling).\n */\n tools?: Array<ChatCompletionTool>;\n\n /**\n * An integer between 0 and 20 specifying the number of most likely tokens to\n * return at each token position, each with an associated log probability.\n * `logprobs` must be set to `true` if this parameter is used.\n */\n top_logprobs?: number | null;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or `temperature` but not both.\n */\n top_p?: number | null;\n\n /**\n * @deprecated This field is being replaced by `safety_identifier` and\n * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n * optimizations. A stable identifier for your end-users. Used to boost cache hit\n * rates by better bucketing similar requests and to help OpenAI detect and prevent\n * abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n user?: string;\n\n /**\n * Constrains the verbosity of the model's response. Lower values will result in\n * more concise responses, while higher values will result in more verbose\n * responses. Currently supported values are `low`, `medium`, and `high`.\n */\n verbosity?: 'low' | 'medium' | 'high' | null;\n\n /**\n * This tool searches the web for relevant results to use in a response. Learn more\n * about the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).\n */\n web_search_options?: ChatCompletionCreateParams.WebSearchOptions;\n}\n\nexport namespace ChatCompletionCreateParams {\n /**\n * @deprecated\n */\n export interface Function {\n /**\n * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain\n * underscores and dashes, with a maximum length of 64.\n */\n name: string;\n\n /**\n * A description of what the function does, used by the model to choose when and\n * how to call the function.\n */\n description?: string;\n\n /**\n * The parameters the functions accepts, described as a JSON Schema object. See the\n * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,\n * and the\n * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for\n * documentation about the format.\n *\n * Omitting `parameters` defines a function with an empty parameter list.\n */\n parameters?: Shared.FunctionParameters;\n }\n\n /**\n * This tool searches the web for relevant results to use in a response. Learn more\n * about the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).\n */\n export interface WebSearchOptions {\n /**\n * High level guidance for the amount of context window space to use for the\n * search. One of `low`, `medium`, or `high`. `medium` is the default.\n */\n search_context_size?: 'low' | 'medium' | 'high';\n\n /**\n * Approximate location parameters for the search.\n */\n user_location?: WebSearchOptions.UserLocation | null;\n }\n\n export namespace WebSearchOptions {\n /**\n * Approximate location parameters for the search.\n */\n export interface UserLocation {\n /**\n * Approximate location parameters for the search.\n */\n approximate: UserLocation.Approximate;\n\n /**\n * The type of location approximation. Always `approximate`.\n */\n type: 'approximate';\n }\n\n export namespace UserLocation {\n /**\n * Approximate location parameters for the search.\n */\n export interface Approximate {\n /**\n * Free text input for the city of the user, e.g. `San Francisco`.\n */\n city?: string;\n\n /**\n * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of\n * the user, e.g. `US`.\n */\n country?: string;\n\n /**\n * Free text input for the region of the user, e.g. `California`.\n */\n region?: string;\n\n /**\n * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the\n * user, e.g. `America/Los_Angeles`.\n */\n timezone?: string;\n }\n }\n }\n\n export type ChatCompletionCreateParamsNonStreaming =\n ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;\n export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;\n}\n\nexport interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)\n * for more information, along with the\n * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)\n * guide for more information on how to handle the streaming events.\n */\n stream?: false | null;\n}\n\nexport interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)\n * for more information, along with the\n * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)\n * guide for more information on how to handle the streaming events.\n */\n stream: true;\n}\n\nexport interface ChatCompletionUpdateParams {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n}\n\nexport interface ChatCompletionListParams extends CursorPageParams {\n /**\n * A list of metadata keys to filter the Chat Completions by. Example:\n *\n * `metadata[key1]=value1&metadata[key2]=value2`\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The model used to generate the Chat Completions.\n */\n model?: string;\n\n /**\n * Sort order for Chat Completions by timestamp. Use `asc` for ascending order or\n * `desc` for descending order. Defaults to `asc`.\n */\n order?: 'asc' | 'desc';\n}\n\nCompletions.Messages = Messages;\n\nexport declare namespace Completions {\n export {\n type ChatCompletion as ChatCompletion,\n type ChatCompletionAllowedToolChoice as ChatCompletionAllowedToolChoice,\n type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,\n type ChatCompletionAudio as ChatCompletionAudio,\n type ChatCompletionAudioParam as ChatCompletionAudioParam,\n type ChatCompletionChunk as ChatCompletionChunk,\n type ChatCompletionContentPart as ChatCompletionContentPart,\n type ChatCompletionContentPartImage as ChatCompletionContentPartImage,\n type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,\n type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,\n type ChatCompletionContentPartText as ChatCompletionContentPartText,\n type ChatCompletionCustomTool as ChatCompletionCustomTool,\n type ChatCompletionDeleted as ChatCompletionDeleted,\n type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,\n type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,\n type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,\n type ChatCompletionFunctionTool as ChatCompletionFunctionTool,\n type ChatCompletionMessage as ChatCompletionMessage,\n type ChatCompletionMessageCustomToolCall as ChatCompletionMessageCustomToolCall,\n type ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall,\n type ChatCompletionMessageParam as ChatCompletionMessageParam,\n type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,\n type ChatCompletionModality as ChatCompletionModality,\n type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,\n type ChatCompletionNamedToolChoiceCustom as ChatCompletionNamedToolChoiceCustom,\n type ChatCompletionPredictionContent as ChatCompletionPredictionContent,\n type ChatCompletionRole as ChatCompletionRole,\n type ChatCompletionStoreMessage as ChatCompletionStoreMessage,\n type ChatCompletionStreamOptions as ChatCompletionStreamOptions,\n type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,\n type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,\n type ChatCompletionTool as ChatCompletionTool,\n type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,\n type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,\n type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,\n type ChatCompletionAllowedTools as ChatCompletionAllowedTools,\n type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,\n type ChatCompletionsPage as ChatCompletionsPage,\n type ChatCompletionCreateParams as ChatCompletionCreateParams,\n type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,\n type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,\n type ChatCompletionUpdateParams as ChatCompletionUpdateParams,\n type ChatCompletionListParams as ChatCompletionListParams,\n };\n\n export { Messages as Messages, type MessageListParams as MessageListParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as CompletionsAPI from './completions/completions';\nimport {\n ChatCompletion,\n ChatCompletionAllowedToolChoice,\n ChatCompletionAllowedTools,\n ChatCompletionAssistantMessageParam,\n ChatCompletionAudio,\n ChatCompletionAudioParam,\n ChatCompletionChunk,\n ChatCompletionContentPart,\n ChatCompletionContentPartImage,\n ChatCompletionContentPartInputAudio,\n ChatCompletionContentPartRefusal,\n ChatCompletionContentPartText,\n ChatCompletionCreateParams,\n ChatCompletionCreateParamsNonStreaming,\n ChatCompletionCreateParamsStreaming,\n ChatCompletionCustomTool,\n ChatCompletionDeleted,\n ChatCompletionDeveloperMessageParam,\n ChatCompletionFunctionCallOption,\n ChatCompletionFunctionMessageParam,\n ChatCompletionFunctionTool,\n ChatCompletionListParams,\n ChatCompletionMessage,\n ChatCompletionMessageCustomToolCall,\n ChatCompletionMessageFunctionToolCall,\n ChatCompletionMessageParam,\n ChatCompletionMessageToolCall,\n ChatCompletionModality,\n ChatCompletionNamedToolChoice,\n ChatCompletionNamedToolChoiceCustom,\n ChatCompletionPredictionContent,\n ChatCompletionReasoningEffort,\n ChatCompletionRole,\n ChatCompletionStoreMessage,\n ChatCompletionStreamOptions,\n ChatCompletionSystemMessageParam,\n ChatCompletionTokenLogprob,\n ChatCompletionTool,\n ChatCompletionToolChoiceOption,\n ChatCompletionToolMessageParam,\n ChatCompletionUpdateParams,\n ChatCompletionUserMessageParam,\n ChatCompletionsPage,\n Completions,\n} from './completions/completions';\n\nexport class Chat extends APIResource {\n completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);\n}\n\nexport type ChatModel = Shared.ChatModel;\n\nChat.Completions = Completions;\n\nexport declare namespace Chat {\n export { type ChatModel as ChatModel };\n\n export {\n Completions as Completions,\n type ChatCompletion as ChatCompletion,\n type ChatCompletionAllowedToolChoice as ChatCompletionAllowedToolChoice,\n type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,\n type ChatCompletionAudio as ChatCompletionAudio,\n type ChatCompletionAudioParam as ChatCompletionAudioParam,\n type ChatCompletionChunk as ChatCompletionChunk,\n type ChatCompletionContentPart as ChatCompletionContentPart,\n type ChatCompletionContentPartImage as ChatCompletionContentPartImage,\n type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,\n type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,\n type ChatCompletionContentPartText as ChatCompletionContentPartText,\n type ChatCompletionCustomTool as ChatCompletionCustomTool,\n type ChatCompletionDeleted as ChatCompletionDeleted,\n type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,\n type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,\n type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,\n type ChatCompletionFunctionTool as ChatCompletionFunctionTool,\n type ChatCompletionMessage as ChatCompletionMessage,\n type ChatCompletionMessageCustomToolCall as ChatCompletionMessageCustomToolCall,\n type ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall,\n type ChatCompletionMessageParam as ChatCompletionMessageParam,\n type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,\n type ChatCompletionModality as ChatCompletionModality,\n type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,\n type ChatCompletionNamedToolChoiceCustom as ChatCompletionNamedToolChoiceCustom,\n type ChatCompletionPredictionContent as ChatCompletionPredictionContent,\n type ChatCompletionRole as ChatCompletionRole,\n type ChatCompletionStoreMessage as ChatCompletionStoreMessage,\n type ChatCompletionStreamOptions as ChatCompletionStreamOptions,\n type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,\n type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,\n type ChatCompletionTool as ChatCompletionTool,\n type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,\n type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,\n type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,\n type ChatCompletionAllowedTools as ChatCompletionAllowedTools,\n type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,\n type ChatCompletionsPage as ChatCompletionsPage,\n type ChatCompletionCreateParams as ChatCompletionCreateParams,\n type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,\n type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,\n type ChatCompletionUpdateParams as ChatCompletionUpdateParams,\n type ChatCompletionListParams as ChatCompletionListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { isReadonlyArray } from './utils/values';\n\ntype HeaderValue = string | undefined | null;\nexport type HeadersLike =\n | Headers\n | readonly HeaderValue[][]\n | Record<string, HeaderValue | readonly HeaderValue[]>\n | undefined\n | null\n | NullableHeaders;\n\nconst brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');\n\n/**\n * @internal\n * Users can pass explicit nulls to unset default headers. When we parse them\n * into a standard headers type we need to preserve that information.\n */\nexport type NullableHeaders = {\n /** Brand check, prevent users from creating a NullableHeaders. */\n [brand_privateNullableHeaders]: true;\n /** Parsed headers. */\n values: Headers;\n /** Set of lowercase header names explicitly set to null. */\n nulls: Set<string>;\n};\n\nfunction* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [string, string | null]> {\n if (!headers) return;\n\n if (brand_privateNullableHeaders in headers) {\n const { values, nulls } = headers;\n yield* values.entries();\n for (const name of nulls) {\n yield [name, null];\n }\n return;\n }\n\n let shouldClear = false;\n let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;\n if (headers instanceof Headers) {\n iter = headers.entries();\n } else if (isReadonlyArray(headers)) {\n iter = headers;\n } else {\n shouldClear = true;\n iter = Object.entries(headers ?? {});\n }\n for (let row of iter) {\n const name = row[0];\n if (typeof name !== 'string') throw new TypeError('expected header name to be a string');\n const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];\n let didClear = false;\n for (const value of values) {\n if (value === undefined) continue;\n\n // Objects keys always overwrite older headers, they never append.\n // Yield a null to clear the header before adding the new values.\n if (shouldClear && !didClear) {\n didClear = true;\n yield [name, null];\n }\n yield [name, value];\n }\n }\n}\n\nexport const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {\n const targetHeaders = new Headers();\n const nullHeaders = new Set<string>();\n for (const headers of newHeaders) {\n const seenHeaders = new Set<string>();\n for (const [name, value] of iterateHeaders(headers)) {\n const lowerName = name.toLowerCase();\n if (!seenHeaders.has(lowerName)) {\n targetHeaders.delete(name);\n seenHeaders.add(lowerName);\n }\n if (value === null) {\n targetHeaders.delete(name);\n nullHeaders.add(lowerName);\n } else {\n targetHeaders.append(name, value);\n nullHeaders.delete(lowerName);\n }\n }\n }\n return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };\n};\n\nexport const isEmptyHeaders = (headers: HeadersLike) => {\n for (const _ of iterateHeaders(headers)) return false;\n return true;\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport { APIPromise } from '../../core/api-promise';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\n\n/**\n * Turn audio into text or text into audio.\n */\nexport class Speech extends APIResource {\n /**\n * Generates audio from the input text.\n *\n * Returns the audio file content, or a stream of audio events.\n *\n * @example\n * ```ts\n * const speech = await client.audio.speech.create({\n * input: 'input',\n * model: 'string',\n * voice: 'ash',\n * });\n *\n * const content = await speech.blob();\n * console.log(content);\n * ```\n */\n create(body: SpeechCreateParams, options?: RequestOptions): APIPromise<Response> {\n return this._client.post('/audio/speech', {\n body,\n ...options,\n headers: buildHeaders([{ Accept: 'application/octet-stream' }, options?.headers]),\n __binaryResponse: true,\n });\n }\n}\n\nexport type SpeechModel = 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts' | 'gpt-4o-mini-tts-2025-12-15';\n\nexport interface SpeechCreateParams {\n /**\n * The text to generate audio for. The maximum length is 4096 characters.\n */\n input: string;\n\n /**\n * One of the available [TTS models](https://platform.openai.com/docs/models#tts):\n * `tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.\n */\n model: (string & {}) | SpeechModel;\n\n /**\n * The voice to use when generating the audio. Supported built-in voices are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,\n * `shimmer`, `verse`, `marin`, and `cedar`. Previews of the voices are available\n * in the\n * [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).\n */\n voice:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n\n /**\n * Control the voice of your generated audio with additional instructions. Does not\n * work with `tts-1` or `tts-1-hd`.\n */\n instructions?: string;\n\n /**\n * The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,\n * `wav`, and `pcm`.\n */\n response_format?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';\n\n /**\n * The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is\n * the default.\n */\n speed?: number;\n\n /**\n * The format to stream the audio in. Supported formats are `sse` and `audio`.\n * `sse` is not supported for `tts-1` or `tts-1-hd`.\n */\n stream_format?: 'sse' | 'audio';\n}\n\nexport declare namespace Speech {\n export { type SpeechModel as SpeechModel, type SpeechCreateParams as SpeechCreateParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as TranscriptionsAPI from './transcriptions';\nimport * as AudioAPI from './audio';\nimport { APIPromise } from '../../core/api-promise';\nimport { Stream } from '../../core/streaming';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { multipartFormRequestOptions } from '../../internal/uploads';\n\n/**\n * Turn audio into text or text into audio.\n */\nexport class Transcriptions extends APIResource {\n /**\n * Transcribes audio into the input language.\n *\n * Returns a transcription object in `json`, `diarized_json`, or `verbose_json`\n * format, or a stream of transcript events.\n *\n * @example\n * ```ts\n * const transcription =\n * await client.audio.transcriptions.create({\n * file: fs.createReadStream('speech.mp3'),\n * model: 'gpt-4o-transcribe',\n * });\n * ```\n */\n create(\n body: TranscriptionCreateParamsNonStreaming<'json' | undefined>,\n options?: RequestOptions,\n ): APIPromise<Transcription>;\n create(\n body: TranscriptionCreateParamsNonStreaming<'verbose_json'>,\n options?: RequestOptions,\n ): APIPromise<TranscriptionVerbose>;\n create(\n body: TranscriptionCreateParamsNonStreaming<'srt' | 'vtt' | 'text'>,\n options?: RequestOptions,\n ): APIPromise<string>;\n create(body: TranscriptionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Transcription>;\n create(\n body: TranscriptionCreateParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<TranscriptionStreamEvent>>;\n create(\n body: TranscriptionCreateParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<TranscriptionCreateResponse | string | Stream<TranscriptionStreamEvent>>;\n create(\n body: TranscriptionCreateParams,\n options?: RequestOptions,\n ): APIPromise<TranscriptionCreateResponse | string | Stream<TranscriptionStreamEvent>> {\n return this._client.post(\n '/audio/transcriptions',\n multipartFormRequestOptions(\n {\n body,\n ...options,\n stream: body.stream ?? false,\n __metadata: { model: body.model },\n },\n this._client,\n ),\n );\n }\n}\n\n/**\n * Represents a transcription response returned by model, based on the provided\n * input.\n */\nexport interface Transcription {\n /**\n * The transcribed text.\n */\n text: string;\n\n /**\n * The log probabilities of the tokens in the transcription. Only returned with the\n * models `gpt-4o-transcribe` and `gpt-4o-mini-transcribe` if `logprobs` is added\n * to the `include` array.\n */\n logprobs?: Array<Transcription.Logprob>;\n\n /**\n * Token usage statistics for the request.\n */\n usage?: Transcription.Tokens | Transcription.Duration;\n}\n\nexport namespace Transcription {\n export interface Logprob {\n /**\n * The token in the transcription.\n */\n token?: string;\n\n /**\n * The bytes of the token.\n */\n bytes?: Array<number>;\n\n /**\n * The log probability of the token.\n */\n logprob?: number;\n }\n\n /**\n * Usage statistics for models billed by token usage.\n */\n export interface Tokens {\n /**\n * Number of input tokens billed for this request.\n */\n input_tokens: number;\n\n /**\n * Number of output tokens generated.\n */\n output_tokens: number;\n\n /**\n * Total number of tokens used (input + output).\n */\n total_tokens: number;\n\n /**\n * The type of the usage object. Always `tokens` for this variant.\n */\n type: 'tokens';\n\n /**\n * Details about the input tokens billed for this request.\n */\n input_token_details?: Tokens.InputTokenDetails;\n }\n\n export namespace Tokens {\n /**\n * Details about the input tokens billed for this request.\n */\n export interface InputTokenDetails {\n /**\n * Number of audio tokens billed for this request.\n */\n audio_tokens?: number;\n\n /**\n * Number of text tokens billed for this request.\n */\n text_tokens?: number;\n }\n }\n\n /**\n * Usage statistics for models billed by audio input duration.\n */\n export interface Duration {\n /**\n * Duration of the input audio in seconds.\n */\n seconds: number;\n\n /**\n * The type of the usage object. Always `duration` for this variant.\n */\n type: 'duration';\n }\n}\n\n/**\n * Represents a diarized transcription response returned by the model, including\n * the combined transcript and speaker-segment annotations.\n */\nexport interface TranscriptionDiarized {\n /**\n * Duration of the input audio in seconds.\n */\n duration: number;\n\n /**\n * Segments of the transcript annotated with timestamps and speaker labels.\n */\n segments: Array<TranscriptionDiarizedSegment>;\n\n /**\n * The type of task that was run. Always `transcribe`.\n */\n task: 'transcribe';\n\n /**\n * The concatenated transcript text for the entire audio input.\n */\n text: string;\n\n /**\n * Token or duration usage statistics for the request.\n */\n usage?: TranscriptionDiarized.Tokens | TranscriptionDiarized.Duration;\n}\n\nexport namespace TranscriptionDiarized {\n /**\n * Usage statistics for models billed by token usage.\n */\n export interface Tokens {\n /**\n * Number of input tokens billed for this request.\n */\n input_tokens: number;\n\n /**\n * Number of output tokens generated.\n */\n output_tokens: number;\n\n /**\n * Total number of tokens used (input + output).\n */\n total_tokens: number;\n\n /**\n * The type of the usage object. Always `tokens` for this variant.\n */\n type: 'tokens';\n\n /**\n * Details about the input tokens billed for this request.\n */\n input_token_details?: Tokens.InputTokenDetails;\n }\n\n export namespace Tokens {\n /**\n * Details about the input tokens billed for this request.\n */\n export interface InputTokenDetails {\n /**\n * Number of audio tokens billed for this request.\n */\n audio_tokens?: number;\n\n /**\n * Number of text tokens billed for this request.\n */\n text_tokens?: number;\n }\n }\n\n /**\n * Usage statistics for models billed by audio input duration.\n */\n export interface Duration {\n /**\n * Duration of the input audio in seconds.\n */\n seconds: number;\n\n /**\n * The type of the usage object. Always `duration` for this variant.\n */\n type: 'duration';\n }\n}\n\n/**\n * A segment of diarized transcript text with speaker metadata.\n */\nexport interface TranscriptionDiarizedSegment {\n /**\n * Unique identifier for the segment.\n */\n id: string;\n\n /**\n * End timestamp of the segment in seconds.\n */\n end: number;\n\n /**\n * Speaker label for this segment. When known speakers are provided, the label\n * matches `known_speaker_names[]`. Otherwise speakers are labeled sequentially\n * using capital letters (`A`, `B`, ...).\n */\n speaker: string;\n\n /**\n * Start timestamp of the segment in seconds.\n */\n start: number;\n\n /**\n * Transcript text for this segment.\n */\n text: string;\n\n /**\n * The type of the segment. Always `transcript.text.segment`.\n */\n type: 'transcript.text.segment';\n}\n\nexport type TranscriptionInclude = 'logprobs';\n\nexport interface TranscriptionSegment {\n /**\n * Unique identifier of the segment.\n */\n id: number;\n\n /**\n * Average logprob of the segment. If the value is lower than -1, consider the\n * logprobs failed.\n */\n avg_logprob: number;\n\n /**\n * Compression ratio of the segment. If the value is greater than 2.4, consider the\n * compression failed.\n */\n compression_ratio: number;\n\n /**\n * End time of the segment in seconds.\n */\n end: number;\n\n /**\n * Probability of no speech in the segment. If the value is higher than 1.0 and the\n * `avg_logprob` is below -1, consider this segment silent.\n */\n no_speech_prob: number;\n\n /**\n * Seek offset of the segment.\n */\n seek: number;\n\n /**\n * Start time of the segment in seconds.\n */\n start: number;\n\n /**\n * Temperature parameter used for generating the segment.\n */\n temperature: number;\n\n /**\n * Text content of the segment.\n */\n text: string;\n\n /**\n * Array of token IDs for the text content.\n */\n tokens: Array<number>;\n}\n\n/**\n * Emitted when a diarized transcription returns a completed segment with speaker\n * information. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with `stream` set to `true` and `response_format` set to `diarized_json`.\n */\nexport type TranscriptionStreamEvent =\n | TranscriptionTextSegmentEvent\n | TranscriptionTextDeltaEvent\n | TranscriptionTextDoneEvent;\n\n/**\n * Emitted when there is an additional text delta. This is also the first event\n * emitted when the transcription starts. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with the `Stream` parameter set to `true`.\n */\nexport interface TranscriptionTextDeltaEvent {\n /**\n * The text delta that was additionally transcribed.\n */\n delta: string;\n\n /**\n * The type of the event. Always `transcript.text.delta`.\n */\n type: 'transcript.text.delta';\n\n /**\n * The log probabilities of the delta. Only included if you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with the `include[]` parameter set to `logprobs`.\n */\n logprobs?: Array<TranscriptionTextDeltaEvent.Logprob>;\n\n /**\n * Identifier of the diarized segment that this delta belongs to. Only present when\n * using `gpt-4o-transcribe-diarize`.\n */\n segment_id?: string;\n}\n\nexport namespace TranscriptionTextDeltaEvent {\n export interface Logprob {\n /**\n * The token that was used to generate the log probability.\n */\n token?: string;\n\n /**\n * The bytes that were used to generate the log probability.\n */\n bytes?: Array<number>;\n\n /**\n * The log probability of the token.\n */\n logprob?: number;\n }\n}\n\n/**\n * Emitted when the transcription is complete. Contains the complete transcription\n * text. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with the `Stream` parameter set to `true`.\n */\nexport interface TranscriptionTextDoneEvent {\n /**\n * The text that was transcribed.\n */\n text: string;\n\n /**\n * The type of the event. Always `transcript.text.done`.\n */\n type: 'transcript.text.done';\n\n /**\n * The log probabilities of the individual tokens in the transcription. Only\n * included if you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with the `include[]` parameter set to `logprobs`.\n */\n logprobs?: Array<TranscriptionTextDoneEvent.Logprob>;\n\n /**\n * Usage statistics for models billed by token usage.\n */\n usage?: TranscriptionTextDoneEvent.Usage;\n}\n\nexport namespace TranscriptionTextDoneEvent {\n export interface Logprob {\n /**\n * The token that was used to generate the log probability.\n */\n token?: string;\n\n /**\n * The bytes that were used to generate the log probability.\n */\n bytes?: Array<number>;\n\n /**\n * The log probability of the token.\n */\n logprob?: number;\n }\n\n /**\n * Usage statistics for models billed by token usage.\n */\n export interface Usage {\n /**\n * Number of input tokens billed for this request.\n */\n input_tokens: number;\n\n /**\n * Number of output tokens generated.\n */\n output_tokens: number;\n\n /**\n * Total number of tokens used (input + output).\n */\n total_tokens: number;\n\n /**\n * The type of the usage object. Always `tokens` for this variant.\n */\n type: 'tokens';\n\n /**\n * Details about the input tokens billed for this request.\n */\n input_token_details?: Usage.InputTokenDetails;\n }\n\n export namespace Usage {\n /**\n * Details about the input tokens billed for this request.\n */\n export interface InputTokenDetails {\n /**\n * Number of audio tokens billed for this request.\n */\n audio_tokens?: number;\n\n /**\n * Number of text tokens billed for this request.\n */\n text_tokens?: number;\n }\n }\n}\n\n/**\n * Emitted when a diarized transcription returns a completed segment with speaker\n * information. Only emitted when you\n * [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription)\n * with `stream` set to `true` and `response_format` set to `diarized_json`.\n */\nexport interface TranscriptionTextSegmentEvent {\n /**\n * Unique identifier for the segment.\n */\n id: string;\n\n /**\n * End timestamp of the segment in seconds.\n */\n end: number;\n\n /**\n * Speaker label for this segment.\n */\n speaker: string;\n\n /**\n * Start timestamp of the segment in seconds.\n */\n start: number;\n\n /**\n * Transcript text for this segment.\n */\n text: string;\n\n /**\n * The type of the event. Always `transcript.text.segment`.\n */\n type: 'transcript.text.segment';\n}\n\n/**\n * Represents a verbose json transcription response returned by model, based on the\n * provided input.\n */\nexport interface TranscriptionVerbose {\n /**\n * The duration of the input audio.\n */\n duration: number;\n\n /**\n * The language of the input audio.\n */\n language: string;\n\n /**\n * The transcribed text.\n */\n text: string;\n\n /**\n * Segments of the transcribed text and their corresponding details.\n */\n segments?: Array<TranscriptionSegment>;\n\n /**\n * Usage statistics for models billed by audio input duration.\n */\n usage?: TranscriptionVerbose.Usage;\n\n /**\n * Extracted words and their corresponding timestamps.\n */\n words?: Array<TranscriptionWord>;\n}\n\nexport namespace TranscriptionVerbose {\n /**\n * Usage statistics for models billed by audio input duration.\n */\n export interface Usage {\n /**\n * Duration of the input audio in seconds.\n */\n seconds: number;\n\n /**\n * The type of the usage object. Always `duration` for this variant.\n */\n type: 'duration';\n }\n}\n\nexport interface TranscriptionWord {\n /**\n * End time of the word in seconds.\n */\n end: number;\n\n /**\n * Start time of the word in seconds.\n */\n start: number;\n\n /**\n * The text content of the word.\n */\n word: string;\n}\n\n/**\n * Represents a transcription response returned by model, based on the provided\n * input.\n */\nexport type TranscriptionCreateResponse = Transcription | TranscriptionDiarized | TranscriptionVerbose;\n\nexport type TranscriptionCreateParams<\n ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> = TranscriptionCreateParamsNonStreaming<ResponseFormat> | TranscriptionCreateParamsStreaming;\n\nexport interface TranscriptionCreateParamsBase<\n ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> {\n /**\n * The audio file object (not file name) to transcribe, in one of these formats:\n * flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.\n */\n file: Uploadable;\n\n /**\n * ID of the model to use. The options are `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`, `whisper-1`\n * (which is powered by our open source Whisper V2 model), and\n * `gpt-4o-transcribe-diarize`.\n */\n model: (string & {}) | AudioAPI.AudioModel;\n\n /**\n * Controls how the audio is cut into chunks. When set to `\"auto\"`, the server\n * first normalizes loudness and then uses voice activity detection (VAD) to choose\n * boundaries. `server_vad` object can be provided to tweak VAD detection\n * parameters manually. If unset, the audio is transcribed as a single block.\n * Required when using `gpt-4o-transcribe-diarize` for inputs longer than 30\n * seconds.\n */\n chunking_strategy?: 'auto' | TranscriptionCreateParams.VadConfig | null;\n\n /**\n * Additional information to include in the transcription response. `logprobs` will\n * return the log probabilities of the tokens in the response to understand the\n * model's confidence in the transcription. `logprobs` only works with\n * response_format set to `json` and only with the models `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, and `gpt-4o-mini-transcribe-2025-12-15`. This field is\n * not supported when using `gpt-4o-transcribe-diarize`.\n */\n include?: Array<TranscriptionInclude>;\n\n /**\n * Optional list of speaker names that correspond to the audio samples provided in\n * `known_speaker_references[]`. Each entry should be a short identifier (for\n * example `customer` or `agent`). Up to 4 speakers are supported.\n */\n known_speaker_names?: Array<string>;\n\n /**\n * Optional list of audio samples (as\n * [data URLs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs))\n * that contain known speaker references matching `known_speaker_names[]`. Each\n * sample must be between 2 and 10 seconds, and can use any of the same input audio\n * formats supported by `file`.\n */\n known_speaker_references?: Array<string>;\n\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. The\n * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)\n * should match the audio language. This field is not supported when using\n * `gpt-4o-transcribe-diarize`.\n */\n prompt?: string;\n\n /**\n * The format of the output, in one of these options: `json`, `text`, `srt`,\n * `verbose_json`, `vtt`, or `diarized_json`. For `gpt-4o-transcribe` and\n * `gpt-4o-mini-transcribe`, the only supported format is `json`. For\n * `gpt-4o-transcribe-diarize`, the supported formats are `json`, `text`, and\n * `diarized_json`, with `diarized_json` required to receive speaker annotations.\n */\n response_format?: ResponseFormat;\n\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)\n * for more information.\n *\n * Note: Streaming is not supported for the `whisper-1` model and will be ignored.\n */\n stream?: boolean | null;\n\n /**\n * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the\n * output more random, while lower values like 0.2 will make it more focused and\n * deterministic. If set to 0, the model will use\n * [log probability](https://en.wikipedia.org/wiki/Log_probability) to\n * automatically increase the temperature until certain thresholds are hit.\n */\n temperature?: number;\n\n /**\n * The timestamp granularities to populate for this transcription.\n * `response_format` must be set `verbose_json` to use timestamp granularities.\n * Either or both of these options are supported: `word`, or `segment`. Note: There\n * is no additional latency for segment timestamps, but generating word timestamps\n * incurs additional latency. This option is not available for\n * `gpt-4o-transcribe-diarize`.\n */\n timestamp_granularities?: Array<'word' | 'segment'>;\n}\n\nexport namespace TranscriptionCreateParams {\n export interface VadConfig {\n /**\n * Must be set to `server_vad` to enable manual chunking using server side VAD.\n */\n type: 'server_vad';\n\n /**\n * Amount of audio to include before the VAD detected speech (in milliseconds).\n */\n prefix_padding_ms?: number;\n\n /**\n * Duration of silence to detect speech stop (in milliseconds). With shorter values\n * the model will respond more quickly, but may jump in on short pauses from the\n * user.\n */\n silence_duration_ms?: number;\n\n /**\n * Sensitivity threshold (0.0 to 1.0) for voice activity detection. A higher\n * threshold will require louder audio to activate the model, and thus might\n * perform better in noisy environments.\n */\n threshold?: number;\n }\n\n export type TranscriptionCreateParamsNonStreaming = TranscriptionsAPI.TranscriptionCreateParamsNonStreaming;\n export type TranscriptionCreateParamsStreaming = TranscriptionsAPI.TranscriptionCreateParamsStreaming;\n}\n\nexport interface TranscriptionCreateParamsNonStreaming<\n ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> extends TranscriptionCreateParamsBase<ResponseFormat> {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)\n * for more information.\n *\n * Note: Streaming is not supported for the `whisper-1` model and will be ignored.\n */\n stream?: false | null;\n}\n\nexport interface TranscriptionCreateParamsStreaming extends TranscriptionCreateParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section of the Speech-to-Text guide](https://platform.openai.com/docs/guides/speech-to-text?lang=curl#streaming-transcriptions)\n * for more information.\n *\n * Note: Streaming is not supported for the `whisper-1` model and will be ignored.\n */\n stream: true;\n}\n\nexport declare namespace Transcriptions {\n export {\n type Transcription as Transcription,\n type TranscriptionDiarized as TranscriptionDiarized,\n type TranscriptionDiarizedSegment as TranscriptionDiarizedSegment,\n type TranscriptionInclude as TranscriptionInclude,\n type TranscriptionSegment as TranscriptionSegment,\n type TranscriptionStreamEvent as TranscriptionStreamEvent,\n type TranscriptionTextDeltaEvent as TranscriptionTextDeltaEvent,\n type TranscriptionTextDoneEvent as TranscriptionTextDoneEvent,\n type TranscriptionTextSegmentEvent as TranscriptionTextSegmentEvent,\n type TranscriptionVerbose as TranscriptionVerbose,\n type TranscriptionWord as TranscriptionWord,\n type TranscriptionCreateResponse as TranscriptionCreateResponse,\n type TranscriptionCreateParams as TranscriptionCreateParams,\n type TranscriptionCreateParamsNonStreaming as TranscriptionCreateParamsNonStreaming,\n type TranscriptionCreateParamsStreaming as TranscriptionCreateParamsStreaming,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as AudioAPI from './audio';\nimport * as TranscriptionsAPI from './transcriptions';\nimport { APIPromise } from '../../core/api-promise';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { multipartFormRequestOptions } from '../../internal/uploads';\n\n/**\n * Turn audio into text or text into audio.\n */\nexport class Translations extends APIResource {\n /**\n * Translates audio into English.\n *\n * @example\n * ```ts\n * const translation = await client.audio.translations.create({\n * file: fs.createReadStream('speech.mp3'),\n * model: 'whisper-1',\n * });\n * ```\n */\n create(\n body: TranslationCreateParams<'json' | undefined>,\n options?: RequestOptions,\n ): APIPromise<Translation>;\n create(\n body: TranslationCreateParams<'verbose_json'>,\n options?: RequestOptions,\n ): APIPromise<TranslationVerbose>;\n create(body: TranslationCreateParams<'text' | 'srt' | 'vtt'>, options?: RequestOptions): APIPromise<string>;\n create(body: TranslationCreateParams, options?: RequestOptions): APIPromise<Translation>;\n create(\n body: TranslationCreateParams,\n options?: RequestOptions,\n ): APIPromise<TranslationCreateResponse | string> {\n return this._client.post(\n '/audio/translations',\n multipartFormRequestOptions({ body, ...options, __metadata: { model: body.model } }, this._client),\n );\n }\n}\n\nexport interface Translation {\n text: string;\n}\n\nexport interface TranslationVerbose {\n /**\n * The duration of the input audio.\n */\n duration: number;\n\n /**\n * The language of the output translation (always `english`).\n */\n language: string;\n\n /**\n * The translated text.\n */\n text: string;\n\n /**\n * Segments of the translated text and their corresponding details.\n */\n segments?: Array<TranscriptionsAPI.TranscriptionSegment>;\n}\n\nexport type TranslationCreateResponse = Translation | TranslationVerbose;\n\nexport interface TranslationCreateParams<\n ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined,\n> {\n /**\n * The audio file object (not file name) translate, in one of these formats: flac,\n * mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.\n */\n file: Uploadable;\n\n /**\n * ID of the model to use. Only `whisper-1` (which is powered by our open source\n * Whisper V2 model) is currently available.\n */\n model: (string & {}) | AudioAPI.AudioModel;\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. The\n * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)\n * should be in English.\n */\n prompt?: string;\n\n /**\n * The format of the output, in one of these options: `json`, `text`, `srt`,\n * `verbose_json`, or `vtt`.\n */\n response_format?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt';\n\n /**\n * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the\n * output more random, while lower values like 0.2 will make it more focused and\n * deterministic. If set to 0, the model will use\n * [log probability](https://en.wikipedia.org/wiki/Log_probability) to\n * automatically increase the temperature until certain thresholds are hit.\n */\n temperature?: number;\n}\n\nexport declare namespace Translations {\n export {\n type Translation as Translation,\n type TranslationVerbose as TranslationVerbose,\n type TranslationCreateResponse as TranslationCreateResponse,\n type TranslationCreateParams as TranslationCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as SpeechAPI from './speech';\nimport { Speech, SpeechCreateParams, SpeechModel } from './speech';\nimport * as TranscriptionsAPI from './transcriptions';\nimport {\n Transcription,\n TranscriptionCreateParams,\n TranscriptionCreateParamsNonStreaming,\n TranscriptionCreateParamsStreaming,\n TranscriptionCreateResponse,\n TranscriptionDiarized,\n TranscriptionDiarizedSegment,\n TranscriptionInclude,\n TranscriptionSegment,\n TranscriptionStreamEvent,\n TranscriptionTextDeltaEvent,\n TranscriptionTextDoneEvent,\n TranscriptionTextSegmentEvent,\n TranscriptionVerbose,\n TranscriptionWord,\n Transcriptions,\n} from './transcriptions';\nimport * as TranslationsAPI from './translations';\nimport {\n Translation,\n TranslationCreateParams,\n TranslationCreateResponse,\n TranslationVerbose,\n Translations,\n} from './translations';\n\nexport class Audio extends APIResource {\n transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this._client);\n translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this._client);\n speech: SpeechAPI.Speech = new SpeechAPI.Speech(this._client);\n}\n\nexport type AudioModel =\n | 'whisper-1'\n | 'gpt-4o-transcribe'\n | 'gpt-4o-mini-transcribe'\n | 'gpt-4o-mini-transcribe-2025-12-15'\n | 'gpt-4o-transcribe-diarize';\n\n/**\n * The format of the output, in one of these options: `json`, `text`, `srt`,\n * `verbose_json`, `vtt`, or `diarized_json`. For `gpt-4o-transcribe` and\n * `gpt-4o-mini-transcribe`, the only supported format is `json`. For\n * `gpt-4o-transcribe-diarize`, the supported formats are `json`, `text`, and\n * `diarized_json`, with `diarized_json` required to receive speaker annotations.\n */\nexport type AudioResponseFormat = 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt' | 'diarized_json';\n\nAudio.Transcriptions = Transcriptions;\nAudio.Translations = Translations;\nAudio.Speech = Speech;\n\nexport declare namespace Audio {\n export { type AudioModel as AudioModel, type AudioResponseFormat as AudioResponseFormat };\n\n export {\n Transcriptions as Transcriptions,\n type Transcription as Transcription,\n type TranscriptionDiarized as TranscriptionDiarized,\n type TranscriptionDiarizedSegment as TranscriptionDiarizedSegment,\n type TranscriptionInclude as TranscriptionInclude,\n type TranscriptionSegment as TranscriptionSegment,\n type TranscriptionStreamEvent as TranscriptionStreamEvent,\n type TranscriptionTextDeltaEvent as TranscriptionTextDeltaEvent,\n type TranscriptionTextDoneEvent as TranscriptionTextDoneEvent,\n type TranscriptionTextSegmentEvent as TranscriptionTextSegmentEvent,\n type TranscriptionVerbose as TranscriptionVerbose,\n type TranscriptionWord as TranscriptionWord,\n type TranscriptionCreateResponse as TranscriptionCreateResponse,\n type TranscriptionCreateParams as TranscriptionCreateParams,\n type TranscriptionCreateParamsNonStreaming as TranscriptionCreateParamsNonStreaming,\n type TranscriptionCreateParamsStreaming as TranscriptionCreateParamsStreaming,\n };\n\n export {\n Translations as Translations,\n type Translation as Translation,\n type TranslationVerbose as TranslationVerbose,\n type TranslationCreateResponse as TranslationCreateResponse,\n type TranslationCreateParams as TranslationCreateParams,\n };\n\n export { Speech as Speech, type SpeechModel as SpeechModel, type SpeechCreateParams as SpeechCreateParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport * as BatchesAPI from './batches';\nimport * as Shared from './shared';\nimport { APIPromise } from '../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../core/pagination';\nimport { RequestOptions } from '../internal/request-options';\nimport { path } from '../internal/utils/path';\n\n/**\n * Create large batches of API requests to run asynchronously.\n */\nexport class Batches extends APIResource {\n /**\n * Creates and executes a batch from an uploaded file of requests\n */\n create(body: BatchCreateParams, options?: RequestOptions): APIPromise<Batch> {\n return this._client.post('/batches', { body, ...options });\n }\n\n /**\n * Retrieves a batch.\n */\n retrieve(batchID: string, options?: RequestOptions): APIPromise<Batch> {\n return this._client.get(path`/batches/${batchID}`, options);\n }\n\n /**\n * List your organization's batches.\n */\n list(\n query: BatchListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<BatchesPage, Batch> {\n return this._client.getAPIList('/batches', CursorPage<Batch>, { query, ...options });\n }\n\n /**\n * Cancels an in-progress batch. The batch will be in status `cancelling` for up to\n * 10 minutes, before changing to `cancelled`, where it will have partial results\n * (if any) available in the output file.\n */\n cancel(batchID: string, options?: RequestOptions): APIPromise<Batch> {\n return this._client.post(path`/batches/${batchID}/cancel`, options);\n }\n}\n\nexport type BatchesPage = CursorPage<Batch>;\n\nexport interface Batch {\n id: string;\n\n /**\n * The time frame within which the batch should be processed.\n */\n completion_window: string;\n\n /**\n * The Unix timestamp (in seconds) for when the batch was created.\n */\n created_at: number;\n\n /**\n * The OpenAI API endpoint used by the batch.\n */\n endpoint: string;\n\n /**\n * The ID of the input file for the batch.\n */\n input_file_id: string;\n\n /**\n * The object type, which is always `batch`.\n */\n object: 'batch';\n\n /**\n * The current status of the batch.\n */\n status:\n | 'validating'\n | 'failed'\n | 'in_progress'\n | 'finalizing'\n | 'completed'\n | 'expired'\n | 'cancelling'\n | 'cancelled';\n\n /**\n * The Unix timestamp (in seconds) for when the batch was cancelled.\n */\n cancelled_at?: number;\n\n /**\n * The Unix timestamp (in seconds) for when the batch started cancelling.\n */\n cancelling_at?: number;\n\n /**\n * The Unix timestamp (in seconds) for when the batch was completed.\n */\n completed_at?: number;\n\n /**\n * The ID of the file containing the outputs of requests with errors.\n */\n error_file_id?: string;\n\n errors?: Batch.Errors;\n\n /**\n * The Unix timestamp (in seconds) for when the batch expired.\n */\n expired_at?: number;\n\n /**\n * The Unix timestamp (in seconds) for when the batch will expire.\n */\n expires_at?: number;\n\n /**\n * The Unix timestamp (in seconds) for when the batch failed.\n */\n failed_at?: number;\n\n /**\n * The Unix timestamp (in seconds) for when the batch started finalizing.\n */\n finalizing_at?: number;\n\n /**\n * The Unix timestamp (in seconds) for when the batch started processing.\n */\n in_progress_at?: number;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * Model ID used to process the batch, like `gpt-5-2025-08-07`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model?: string;\n\n /**\n * The ID of the file containing the outputs of successfully executed requests.\n */\n output_file_id?: string;\n\n /**\n * The request counts for different statuses within the batch.\n */\n request_counts?: BatchRequestCounts;\n\n /**\n * Represents token usage details including input tokens, output tokens, a\n * breakdown of output tokens, and the total tokens used. Only populated on batches\n * created after September 7, 2025.\n */\n usage?: BatchUsage;\n}\n\nexport namespace Batch {\n export interface Errors {\n data?: Array<BatchesAPI.BatchError>;\n\n /**\n * The object type, which is always `list`.\n */\n object?: string;\n }\n}\n\nexport interface BatchError {\n /**\n * An error code identifying the error type.\n */\n code?: string;\n\n /**\n * The line number of the input file where the error occurred, if applicable.\n */\n line?: number | null;\n\n /**\n * A human-readable message providing more details about the error.\n */\n message?: string;\n\n /**\n * The name of the parameter that caused the error, if applicable.\n */\n param?: string | null;\n}\n\n/**\n * The request counts for different statuses within the batch.\n */\nexport interface BatchRequestCounts {\n /**\n * Number of requests that have been completed successfully.\n */\n completed: number;\n\n /**\n * Number of requests that have failed.\n */\n failed: number;\n\n /**\n * Total number of requests in the batch.\n */\n total: number;\n}\n\n/**\n * Represents token usage details including input tokens, output tokens, a\n * breakdown of output tokens, and the total tokens used. Only populated on batches\n * created after September 7, 2025.\n */\nexport interface BatchUsage {\n /**\n * The number of input tokens.\n */\n input_tokens: number;\n\n /**\n * A detailed breakdown of the input tokens.\n */\n input_tokens_details: BatchUsage.InputTokensDetails;\n\n /**\n * The number of output tokens.\n */\n output_tokens: number;\n\n /**\n * A detailed breakdown of the output tokens.\n */\n output_tokens_details: BatchUsage.OutputTokensDetails;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n}\n\nexport namespace BatchUsage {\n /**\n * A detailed breakdown of the input tokens.\n */\n export interface InputTokensDetails {\n /**\n * The number of tokens that were retrieved from the cache.\n * [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).\n */\n cached_tokens: number;\n }\n\n /**\n * A detailed breakdown of the output tokens.\n */\n export interface OutputTokensDetails {\n /**\n * The number of reasoning tokens.\n */\n reasoning_tokens: number;\n }\n}\n\nexport interface BatchCreateParams {\n /**\n * The time frame within which the batch should be processed. Currently only `24h`\n * is supported.\n */\n completion_window: '24h';\n\n /**\n * The endpoint to be used for all requests in the batch. Currently\n * `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, `/v1/completions`,\n * `/v1/moderations`, `/v1/images/generations`, and `/v1/images/edits` are\n * supported. Note that `/v1/embeddings` batches are also restricted to a maximum\n * of 50,000 embedding inputs across all requests in the batch.\n */\n endpoint:\n | '/v1/responses'\n | '/v1/chat/completions'\n | '/v1/embeddings'\n | '/v1/completions'\n | '/v1/moderations'\n | '/v1/images/generations'\n | '/v1/images/edits';\n\n /**\n * The ID of an uploaded file that contains requests for the new batch.\n *\n * See [upload file](https://platform.openai.com/docs/api-reference/files/create)\n * for how to upload a file.\n *\n * Your input file must be formatted as a\n * [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),\n * and must be uploaded with the purpose `batch`. The file can contain up to 50,000\n * requests, and can be up to 200 MB in size.\n */\n input_file_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The expiration policy for the output and/or error file that are generated for a\n * batch.\n */\n output_expires_after?: BatchCreateParams.OutputExpiresAfter;\n}\n\nexport namespace BatchCreateParams {\n /**\n * The expiration policy for the output and/or error file that are generated for a\n * batch.\n */\n export interface OutputExpiresAfter {\n /**\n * Anchor timestamp after which the expiration policy applies. Supported anchors:\n * `created_at`. Note that the anchor is the file creation time, not the time the\n * batch is created.\n */\n anchor: 'created_at';\n\n /**\n * The number of seconds after the anchor time that the file will expire. Must be\n * between 3600 (1 hour) and 2592000 (30 days).\n */\n seconds: number;\n }\n}\n\nexport interface BatchListParams extends CursorPageParams {}\n\nexport declare namespace Batches {\n export {\n type Batch as Batch,\n type BatchError as BatchError,\n type BatchRequestCounts as BatchRequestCounts,\n type BatchUsage as BatchUsage,\n type BatchesPage as BatchesPage,\n type BatchCreateParams as BatchCreateParams,\n type BatchListParams as BatchListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as MessagesAPI from './threads/messages';\nimport * as ThreadsAPI from './threads/threads';\nimport * as RunsAPI from './threads/runs/runs';\nimport * as StepsAPI from './threads/runs/steps';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\nimport { AssistantStream } from '../../lib/AssistantStream';\n\n/**\n * Build Assistants that can call models and use tools.\n */\nexport class Assistants extends APIResource {\n /**\n * Create an assistant with a model and instructions.\n *\n * @deprecated\n */\n create(body: AssistantCreateParams, options?: RequestOptions): APIPromise<Assistant> {\n return this._client.post('/assistants', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Retrieves an assistant.\n *\n * @deprecated\n */\n retrieve(assistantID: string, options?: RequestOptions): APIPromise<Assistant> {\n return this._client.get(path`/assistants/${assistantID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Modifies an assistant.\n *\n * @deprecated\n */\n update(assistantID: string, body: AssistantUpdateParams, options?: RequestOptions): APIPromise<Assistant> {\n return this._client.post(path`/assistants/${assistantID}`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Returns a list of assistants.\n *\n * @deprecated\n */\n list(\n query: AssistantListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<AssistantsPage, Assistant> {\n return this._client.getAPIList('/assistants', CursorPage<Assistant>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Delete an assistant.\n *\n * @deprecated\n */\n delete(assistantID: string, options?: RequestOptions): APIPromise<AssistantDeleted> {\n return this._client.delete(path`/assistants/${assistantID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n}\n\nexport type AssistantsPage = CursorPage<Assistant>;\n\n/**\n * @deprecated Represents an `assistant` that can call the model and use tools.\n */\nexport interface Assistant {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the assistant was created.\n */\n created_at: number;\n\n /**\n * The description of the assistant. The maximum length is 512 characters.\n */\n description: string | null;\n\n /**\n * The system instructions that the assistant uses. The maximum length is 256,000\n * characters.\n */\n instructions: string | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * ID of the model to use. You can use the\n * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n * see all of your available models, or see our\n * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n * them.\n */\n model: string;\n\n /**\n * The name of the assistant. The maximum length is 256 characters.\n */\n name: string | null;\n\n /**\n * The object type, which is always `assistant`.\n */\n object: 'assistant';\n\n /**\n * A list of tool enabled on the assistant. There can be a maximum of 128 tools per\n * assistant. Tools can be of types `code_interpreter`, `file_search`, or\n * `function`.\n */\n tools: Array<AssistantTool>;\n\n /**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic.\n */\n temperature?: number | null;\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n tool_resources?: Assistant.ToolResources | null;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or temperature but not both.\n */\n top_p?: number | null;\n}\n\nexport namespace Assistant {\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter`` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The ID of the\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this assistant. There can be a maximum of 1 vector store attached to\n * the assistant.\n */\n vector_store_ids?: Array<string>;\n }\n }\n}\n\nexport interface AssistantDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'assistant.deleted';\n}\n\n/**\n * Represents an event emitted when streaming a Run.\n *\n * Each event in a server-sent events stream has an `event` and `data` property:\n *\n * ```\n * event: thread.created\n * data: {\"id\": \"thread_123\", \"object\": \"thread\", ...}\n * ```\n *\n * We emit events whenever a new object is created, transitions to a new state, or\n * is being streamed in parts (deltas). For example, we emit `thread.run.created`\n * when a new run is created, `thread.run.completed` when a run completes, and so\n * on. When an Assistant chooses to create a message during a run, we emit a\n * `thread.message.created event`, a `thread.message.in_progress` event, many\n * `thread.message.delta` events, and finally a `thread.message.completed` event.\n *\n * We may add additional events over time, so we recommend handling unknown events\n * gracefully in your code. See the\n * [Assistants API quickstart](https://platform.openai.com/docs/assistants/overview)\n * to learn how to integrate the Assistants API with streaming.\n */\nexport type AssistantStreamEvent =\n | AssistantStreamEvent.ThreadCreated\n | AssistantStreamEvent.ThreadRunCreated\n | AssistantStreamEvent.ThreadRunQueued\n | AssistantStreamEvent.ThreadRunInProgress\n | AssistantStreamEvent.ThreadRunRequiresAction\n | AssistantStreamEvent.ThreadRunCompleted\n | AssistantStreamEvent.ThreadRunIncomplete\n | AssistantStreamEvent.ThreadRunFailed\n | AssistantStreamEvent.ThreadRunCancelling\n | AssistantStreamEvent.ThreadRunCancelled\n | AssistantStreamEvent.ThreadRunExpired\n | AssistantStreamEvent.ThreadRunStepCreated\n | AssistantStreamEvent.ThreadRunStepInProgress\n | AssistantStreamEvent.ThreadRunStepDelta\n | AssistantStreamEvent.ThreadRunStepCompleted\n | AssistantStreamEvent.ThreadRunStepFailed\n | AssistantStreamEvent.ThreadRunStepCancelled\n | AssistantStreamEvent.ThreadRunStepExpired\n | AssistantStreamEvent.ThreadMessageCreated\n | AssistantStreamEvent.ThreadMessageInProgress\n | AssistantStreamEvent.ThreadMessageDelta\n | AssistantStreamEvent.ThreadMessageCompleted\n | AssistantStreamEvent.ThreadMessageIncomplete\n | AssistantStreamEvent.ErrorEvent;\n\nexport namespace AssistantStreamEvent {\n /**\n * Occurs when a new\n * [thread](https://platform.openai.com/docs/api-reference/threads/object) is\n * created.\n */\n export interface ThreadCreated {\n /**\n * Represents a thread that contains\n * [messages](https://platform.openai.com/docs/api-reference/messages).\n */\n data: ThreadsAPI.Thread;\n\n event: 'thread.created';\n\n /**\n * Whether to enable input audio transcription.\n */\n enabled?: boolean;\n }\n\n /**\n * Occurs when a new\n * [run](https://platform.openai.com/docs/api-reference/runs/object) is created.\n */\n export interface ThreadRunCreated {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.created';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to a `queued` status.\n */\n export interface ThreadRunQueued {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.queued';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to an `in_progress` status.\n */\n export interface ThreadRunInProgress {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.in_progress';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to a `requires_action` status.\n */\n export interface ThreadRunRequiresAction {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.requires_action';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * is completed.\n */\n export interface ThreadRunCompleted {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.completed';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * ends with status `incomplete`.\n */\n export interface ThreadRunIncomplete {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.incomplete';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * fails.\n */\n export interface ThreadRunFailed {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.failed';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to a `cancelling` status.\n */\n export interface ThreadRunCancelling {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.cancelling';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * is cancelled.\n */\n export interface ThreadRunCancelled {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.cancelled';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * expires.\n */\n export interface ThreadRunExpired {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.expired';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is created.\n */\n export interface ThreadRunStepCreated {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.created';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * moves to an `in_progress` state.\n */\n export interface ThreadRunStepInProgress {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.in_progress';\n }\n\n /**\n * Occurs when parts of a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * are being streamed.\n */\n export interface ThreadRunStepDelta {\n /**\n * Represents a run step delta i.e. any changed fields on a run step during\n * streaming.\n */\n data: StepsAPI.RunStepDeltaEvent;\n\n event: 'thread.run.step.delta';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is completed.\n */\n export interface ThreadRunStepCompleted {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.completed';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * fails.\n */\n export interface ThreadRunStepFailed {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.failed';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is cancelled.\n */\n export interface ThreadRunStepCancelled {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.cancelled';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * expires.\n */\n export interface ThreadRunStepExpired {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.expired';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n * created.\n */\n export interface ThreadMessageCreated {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.created';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) moves\n * to an `in_progress` state.\n */\n export interface ThreadMessageInProgress {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.in_progress';\n }\n\n /**\n * Occurs when parts of a\n * [Message](https://platform.openai.com/docs/api-reference/messages/object) are\n * being streamed.\n */\n export interface ThreadMessageDelta {\n /**\n * Represents a message delta i.e. any changed fields on a message during\n * streaming.\n */\n data: MessagesAPI.MessageDeltaEvent;\n\n event: 'thread.message.delta';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n * completed.\n */\n export interface ThreadMessageCompleted {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.completed';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) ends\n * before it is completed.\n */\n export interface ThreadMessageIncomplete {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.incomplete';\n }\n\n /**\n * Occurs when an\n * [error](https://platform.openai.com/docs/guides/error-codes#api-errors) occurs.\n * This can happen due to an internal server error or a timeout.\n */\n export interface ErrorEvent {\n data: Shared.ErrorObject;\n\n event: 'error';\n }\n}\n\nexport type AssistantTool = CodeInterpreterTool | FileSearchTool | FunctionTool;\n\nexport interface CodeInterpreterTool {\n /**\n * The type of tool being defined: `code_interpreter`\n */\n type: 'code_interpreter';\n}\n\nexport interface FileSearchTool {\n /**\n * The type of tool being defined: `file_search`\n */\n type: 'file_search';\n\n /**\n * Overrides for the file search tool.\n */\n file_search?: FileSearchTool.FileSearch;\n}\n\nexport namespace FileSearchTool {\n /**\n * Overrides for the file search tool.\n */\n export interface FileSearch {\n /**\n * The maximum number of results the file search tool should output. The default is\n * 20 for `gpt-4*` models and 5 for `gpt-3.5-turbo`. This number should be between\n * 1 and 50 inclusive.\n *\n * Note that the file search tool may output fewer than `max_num_results` results.\n * See the\n * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n * for more information.\n */\n max_num_results?: number;\n\n /**\n * The ranking options for the file search. If not specified, the file search tool\n * will use the `auto` ranker and a score_threshold of 0.\n *\n * See the\n * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n * for more information.\n */\n ranking_options?: FileSearch.RankingOptions;\n }\n\n export namespace FileSearch {\n /**\n * The ranking options for the file search. If not specified, the file search tool\n * will use the `auto` ranker and a score_threshold of 0.\n *\n * See the\n * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n * for more information.\n */\n export interface RankingOptions {\n /**\n * The score threshold for the file search. All values must be a floating point\n * number between 0 and 1.\n */\n score_threshold: number;\n\n /**\n * The ranker to use for the file search. If not specified will use the `auto`\n * ranker.\n */\n ranker?: 'auto' | 'default_2024_08_21';\n }\n }\n}\n\nexport interface FunctionTool {\n function: Shared.FunctionDefinition;\n\n /**\n * The type of tool being defined: `function`\n */\n type: 'function';\n}\n\n/**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n * created.\n */\nexport type MessageStreamEvent =\n | MessageStreamEvent.ThreadMessageCreated\n | MessageStreamEvent.ThreadMessageInProgress\n | MessageStreamEvent.ThreadMessageDelta\n | MessageStreamEvent.ThreadMessageCompleted\n | MessageStreamEvent.ThreadMessageIncomplete;\n\nexport namespace MessageStreamEvent {\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n * created.\n */\n export interface ThreadMessageCreated {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.created';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) moves\n * to an `in_progress` state.\n */\n export interface ThreadMessageInProgress {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.in_progress';\n }\n\n /**\n * Occurs when parts of a\n * [Message](https://platform.openai.com/docs/api-reference/messages/object) are\n * being streamed.\n */\n export interface ThreadMessageDelta {\n /**\n * Represents a message delta i.e. any changed fields on a message during\n * streaming.\n */\n data: MessagesAPI.MessageDeltaEvent;\n\n event: 'thread.message.delta';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) is\n * completed.\n */\n export interface ThreadMessageCompleted {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.completed';\n }\n\n /**\n * Occurs when a\n * [message](https://platform.openai.com/docs/api-reference/messages/object) ends\n * before it is completed.\n */\n export interface ThreadMessageIncomplete {\n /**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: MessagesAPI.Message;\n\n event: 'thread.message.incomplete';\n }\n}\n\n/**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is created.\n */\nexport type RunStepStreamEvent =\n | RunStepStreamEvent.ThreadRunStepCreated\n | RunStepStreamEvent.ThreadRunStepInProgress\n | RunStepStreamEvent.ThreadRunStepDelta\n | RunStepStreamEvent.ThreadRunStepCompleted\n | RunStepStreamEvent.ThreadRunStepFailed\n | RunStepStreamEvent.ThreadRunStepCancelled\n | RunStepStreamEvent.ThreadRunStepExpired;\n\nexport namespace RunStepStreamEvent {\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is created.\n */\n export interface ThreadRunStepCreated {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.created';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * moves to an `in_progress` state.\n */\n export interface ThreadRunStepInProgress {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.in_progress';\n }\n\n /**\n * Occurs when parts of a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * are being streamed.\n */\n export interface ThreadRunStepDelta {\n /**\n * Represents a run step delta i.e. any changed fields on a run step during\n * streaming.\n */\n data: StepsAPI.RunStepDeltaEvent;\n\n event: 'thread.run.step.delta';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is completed.\n */\n export interface ThreadRunStepCompleted {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.completed';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * fails.\n */\n export interface ThreadRunStepFailed {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.failed';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * is cancelled.\n */\n export interface ThreadRunStepCancelled {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.cancelled';\n }\n\n /**\n * Occurs when a\n * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object)\n * expires.\n */\n export interface ThreadRunStepExpired {\n /**\n * Represents a step in execution of a run.\n */\n data: StepsAPI.RunStep;\n\n event: 'thread.run.step.expired';\n }\n}\n\n/**\n * Occurs when a new\n * [run](https://platform.openai.com/docs/api-reference/runs/object) is created.\n */\nexport type RunStreamEvent =\n | RunStreamEvent.ThreadRunCreated\n | RunStreamEvent.ThreadRunQueued\n | RunStreamEvent.ThreadRunInProgress\n | RunStreamEvent.ThreadRunRequiresAction\n | RunStreamEvent.ThreadRunCompleted\n | RunStreamEvent.ThreadRunIncomplete\n | RunStreamEvent.ThreadRunFailed\n | RunStreamEvent.ThreadRunCancelling\n | RunStreamEvent.ThreadRunCancelled\n | RunStreamEvent.ThreadRunExpired;\n\nexport namespace RunStreamEvent {\n /**\n * Occurs when a new\n * [run](https://platform.openai.com/docs/api-reference/runs/object) is created.\n */\n export interface ThreadRunCreated {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.created';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to a `queued` status.\n */\n export interface ThreadRunQueued {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.queued';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to an `in_progress` status.\n */\n export interface ThreadRunInProgress {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.in_progress';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to a `requires_action` status.\n */\n export interface ThreadRunRequiresAction {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.requires_action';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * is completed.\n */\n export interface ThreadRunCompleted {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.completed';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * ends with status `incomplete`.\n */\n export interface ThreadRunIncomplete {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.incomplete';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * fails.\n */\n export interface ThreadRunFailed {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.failed';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * moves to a `cancelling` status.\n */\n export interface ThreadRunCancelling {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.cancelling';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * is cancelled.\n */\n export interface ThreadRunCancelled {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.cancelled';\n }\n\n /**\n * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)\n * expires.\n */\n export interface ThreadRunExpired {\n /**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\n data: RunsAPI.Run;\n\n event: 'thread.run.expired';\n }\n}\n\n/**\n * Occurs when a new\n * [thread](https://platform.openai.com/docs/api-reference/threads/object) is\n * created.\n */\nexport interface ThreadStreamEvent {\n /**\n * Represents a thread that contains\n * [messages](https://platform.openai.com/docs/api-reference/messages).\n */\n data: ThreadsAPI.Thread;\n\n event: 'thread.created';\n\n /**\n * Whether to enable input audio transcription.\n */\n enabled?: boolean;\n}\n\nexport interface AssistantCreateParams {\n /**\n * ID of the model to use. You can use the\n * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n * see all of your available models, or see our\n * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n * them.\n */\n model: (string & {}) | Shared.ChatModel;\n\n /**\n * The description of the assistant. The maximum length is 512 characters.\n */\n description?: string | null;\n\n /**\n * The system instructions that the assistant uses. The maximum length is 256,000\n * characters.\n */\n instructions?: string | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The name of the assistant. The maximum length is 256 characters.\n */\n name?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic.\n */\n temperature?: number | null;\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n tool_resources?: AssistantCreateParams.ToolResources | null;\n\n /**\n * A list of tool enabled on the assistant. There can be a maximum of 128 tools per\n * assistant. Tools can be of types `code_interpreter`, `file_search`, or\n * `function`.\n */\n tools?: Array<AssistantTool>;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or temperature but not both.\n */\n top_p?: number | null;\n}\n\nexport namespace AssistantCreateParams {\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this assistant. There can be a maximum of 1 vector store attached to\n * the assistant.\n */\n vector_store_ids?: Array<string>;\n\n /**\n * A helper to create a\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * with file_ids and attach it to this assistant. There can be a maximum of 1\n * vector store attached to the assistant.\n */\n vector_stores?: Array<FileSearch.VectorStore>;\n }\n\n export namespace FileSearch {\n export interface VectorStore {\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy.\n */\n chunking_strategy?: VectorStore.Auto | VectorStore.Static;\n\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n * add to the vector store. For vector stores created before Nov 2025, there can be\n * a maximum of 10,000 files in a vector store. For vector stores created starting\n * in Nov 2025, the limit is 100,000,000 files.\n */\n file_ids?: Array<string>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n export namespace VectorStore {\n /**\n * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n * `800` and `chunk_overlap_tokens` of `400`.\n */\n export interface Auto {\n /**\n * Always `auto`.\n */\n type: 'auto';\n }\n\n export interface Static {\n static: Static.Static;\n\n /**\n * Always `static`.\n */\n type: 'static';\n }\n\n export namespace Static {\n export interface Static {\n /**\n * The number of tokens that overlap between chunks. The default value is `400`.\n *\n * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n */\n chunk_overlap_tokens: number;\n\n /**\n * The maximum number of tokens in each chunk. The default value is `800`. The\n * minimum value is `100` and the maximum value is `4096`.\n */\n max_chunk_size_tokens: number;\n }\n }\n }\n }\n }\n}\n\nexport interface AssistantUpdateParams {\n /**\n * The description of the assistant. The maximum length is 512 characters.\n */\n description?: string | null;\n\n /**\n * The system instructions that the assistant uses. The maximum length is 256,000\n * characters.\n */\n instructions?: string | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * ID of the model to use. You can use the\n * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n * see all of your available models, or see our\n * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n * them.\n */\n model?:\n | (string & {})\n | 'gpt-5'\n | 'gpt-5-mini'\n | 'gpt-5-nano'\n | 'gpt-5-2025-08-07'\n | 'gpt-5-mini-2025-08-07'\n | 'gpt-5-nano-2025-08-07'\n | 'gpt-4.1'\n | 'gpt-4.1-mini'\n | 'gpt-4.1-nano'\n | 'gpt-4.1-2025-04-14'\n | 'gpt-4.1-mini-2025-04-14'\n | 'gpt-4.1-nano-2025-04-14'\n | 'o3-mini'\n | 'o3-mini-2025-01-31'\n | 'o1'\n | 'o1-2024-12-17'\n | 'gpt-4o'\n | 'gpt-4o-2024-11-20'\n | 'gpt-4o-2024-08-06'\n | 'gpt-4o-2024-05-13'\n | 'gpt-4o-mini'\n | 'gpt-4o-mini-2024-07-18'\n | 'gpt-4.5-preview'\n | 'gpt-4.5-preview-2025-02-27'\n | 'gpt-4-turbo'\n | 'gpt-4-turbo-2024-04-09'\n | 'gpt-4-0125-preview'\n | 'gpt-4-turbo-preview'\n | 'gpt-4-1106-preview'\n | 'gpt-4-vision-preview'\n | 'gpt-4'\n | 'gpt-4-0314'\n | 'gpt-4-0613'\n | 'gpt-4-32k'\n | 'gpt-4-32k-0314'\n | 'gpt-4-32k-0613'\n | 'gpt-3.5-turbo'\n | 'gpt-3.5-turbo-16k'\n | 'gpt-3.5-turbo-0613'\n | 'gpt-3.5-turbo-1106'\n | 'gpt-3.5-turbo-0125'\n | 'gpt-3.5-turbo-16k-0613';\n\n /**\n * The name of the assistant. The maximum length is 256 characters.\n */\n name?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic.\n */\n temperature?: number | null;\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n tool_resources?: AssistantUpdateParams.ToolResources | null;\n\n /**\n * A list of tool enabled on the assistant. There can be a maximum of 128 tools per\n * assistant. Tools can be of types `code_interpreter`, `file_search`, or\n * `function`.\n */\n tools?: Array<AssistantTool>;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or temperature but not both.\n */\n top_p?: number | null;\n}\n\nexport namespace AssistantUpdateParams {\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * Overrides the list of\n * [file](https://platform.openai.com/docs/api-reference/files) IDs made available\n * to the `code_interpreter` tool. There can be a maximum of 20 files associated\n * with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * Overrides the\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this assistant. There can be a maximum of 1 vector store attached to\n * the assistant.\n */\n vector_store_ids?: Array<string>;\n }\n }\n}\n\nexport interface AssistantListParams extends CursorPageParams {\n /**\n * A cursor for use in pagination. `before` is an object ID that defines your place\n * in the list. For instance, if you make a list request and receive 100 objects,\n * starting with obj_foo, your subsequent call can include before=obj_foo in order\n * to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport declare namespace Assistants {\n export {\n type Assistant as Assistant,\n type AssistantDeleted as AssistantDeleted,\n type AssistantStreamEvent as AssistantStreamEvent,\n type AssistantTool as AssistantTool,\n type CodeInterpreterTool as CodeInterpreterTool,\n type FileSearchTool as FileSearchTool,\n type FunctionTool as FunctionTool,\n type MessageStreamEvent as MessageStreamEvent,\n type RunStepStreamEvent as RunStepStreamEvent,\n type RunStreamEvent as RunStreamEvent,\n type ThreadStreamEvent as ThreadStreamEvent,\n type AssistantsPage as AssistantsPage,\n type AssistantCreateParams as AssistantCreateParams,\n type AssistantUpdateParams as AssistantUpdateParams,\n type AssistantListParams as AssistantListParams,\n };\n\n export { AssistantStream };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\n\nexport class Sessions extends APIResource {\n /**\n * Create an ephemeral API token for use in client-side applications with the\n * Realtime API. Can be configured with the same session parameters as the\n * `session.update` client event.\n *\n * It responds with a session object, plus a `client_secret` key which contains a\n * usable ephemeral API token that can be used to authenticate browser clients for\n * the Realtime API.\n *\n * @example\n * ```ts\n * const session =\n * await client.beta.realtime.sessions.create();\n * ```\n */\n create(body: SessionCreateParams, options?: RequestOptions): APIPromise<SessionCreateResponse> {\n return this._client.post('/realtime/sessions', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n}\n\n/**\n * Realtime session object configuration.\n */\nexport interface Session {\n /**\n * Unique identifier for the session that looks like `sess_1234567890abcdef`.\n */\n id?: string;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n input_audio_transcription?: Session.InputAudioTranscription;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_response_output_tokens?: number | 'inf';\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17';\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n * For `pcm16`, output audio is sampled at a rate of 24kHz.\n */\n output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n * between model turns, not while a response is in progress.\n */\n speed?: number;\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n * temperature of 0.8 is highly recommended for best performance.\n */\n temperature?: number;\n\n /**\n * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n * a function.\n */\n tool_choice?: string;\n\n /**\n * Tools (functions) available to the model.\n */\n tools?: Array<Session.Tool>;\n\n /**\n * Configuration options for tracing. Set to null to disable tracing. Once tracing\n * is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: 'auto' | Session.TracingConfiguration;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n turn_detection?: Session.TurnDetection;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\nexport namespace Session {\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: 'near_field' | 'far_field';\n }\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n export interface InputAudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription, current options are `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, and `whisper-1`.\n */\n model?: string;\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. For `whisper-1`, the\n * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n * \"expect words related to technology\".\n */\n prompt?: string;\n }\n\n export interface Tool {\n /**\n * The description of the function, including guidance on when and how to call it,\n * and guidance about what to tell the user when calling (if anything).\n */\n description?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * Parameters of the function in JSON Schema.\n */\n parameters?: unknown;\n\n /**\n * The type of the tool, i.e. `function`.\n */\n type?: 'function';\n }\n\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * traces dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the traces\n * dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the traces dashboard.\n */\n workflow_name?: string;\n }\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n export interface TurnDetection {\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection.\n */\n type?: 'server_vad' | 'semantic_vad';\n }\n}\n\n/**\n * A new Realtime session configuration, with an ephemeral key. Default TTL for\n * keys is one minute.\n */\nexport interface SessionCreateResponse {\n /**\n * Ephemeral key returned by the API.\n */\n client_secret: SessionCreateResponse.ClientSecret;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n */\n input_audio_format?: string;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously and should be treated as rough guidance rather than the\n * representation understood by the model.\n */\n input_audio_transcription?: SessionCreateResponse.InputAudioTranscription;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_response_output_tokens?: number | 'inf';\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n */\n output_audio_format?: string;\n\n /**\n * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n * between model turns, not while a response is in progress.\n */\n speed?: number;\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.\n */\n temperature?: number;\n\n /**\n * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n * a function.\n */\n tool_choice?: string;\n\n /**\n * Tools (functions) available to the model.\n */\n tools?: Array<SessionCreateResponse.Tool>;\n\n /**\n * Configuration options for tracing. Set to null to disable tracing. Once tracing\n * is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: 'auto' | SessionCreateResponse.TracingConfiguration;\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n turn_detection?: SessionCreateResponse.TurnDetection;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\nexport namespace SessionCreateResponse {\n /**\n * Ephemeral key returned by the API.\n */\n export interface ClientSecret {\n /**\n * Timestamp for when the token expires. Currently, all tokens expire after one\n * minute.\n */\n expires_at: number;\n\n /**\n * Ephemeral key usable in client environments to authenticate connections to the\n * Realtime API. Use this in client-side environments rather than a standard API\n * token, which should only be used server-side.\n */\n value: string;\n }\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously and should be treated as rough guidance rather than the\n * representation understood by the model.\n */\n export interface InputAudioTranscription {\n /**\n * The model to use for transcription.\n */\n model?: string;\n }\n\n export interface Tool {\n /**\n * The description of the function, including guidance on when and how to call it,\n * and guidance about what to tell the user when calling (if anything).\n */\n description?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * Parameters of the function in JSON Schema.\n */\n parameters?: unknown;\n\n /**\n * The type of the tool, i.e. `function`.\n */\n type?: 'function';\n }\n\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * traces dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the traces\n * dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the traces dashboard.\n */\n workflow_name?: string;\n }\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n export interface TurnDetection {\n /**\n * Amount of audio to include before the VAD detected speech (in milliseconds).\n * Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n * With shorter values the model will respond more quickly, but may jump in on\n * short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n * threshold will require louder audio to activate the model, and thus might\n * perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection, only `server_vad` is currently supported.\n */\n type?: string;\n }\n}\n\nexport interface SessionCreateParams {\n /**\n * Configuration options for the generated client secret.\n */\n client_secret?: SessionCreateParams.ClientSecret;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: SessionCreateParams.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n input_audio_transcription?: SessionCreateParams.InputAudioTranscription;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_response_output_tokens?: number | 'inf';\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17';\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n * For `pcm16`, output audio is sampled at a rate of 24kHz.\n */\n output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n * between model turns, not while a response is in progress.\n */\n speed?: number;\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n * temperature of 0.8 is highly recommended for best performance.\n */\n temperature?: number;\n\n /**\n * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n * a function.\n */\n tool_choice?: string;\n\n /**\n * Tools (functions) available to the model.\n */\n tools?: Array<SessionCreateParams.Tool>;\n\n /**\n * Configuration options for tracing. Set to null to disable tracing. Once tracing\n * is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: 'auto' | SessionCreateParams.TracingConfiguration;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n turn_detection?: SessionCreateParams.TurnDetection;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\nexport namespace SessionCreateParams {\n /**\n * Configuration options for the generated client secret.\n */\n export interface ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n expires_after?: ClientSecret.ExpiresAfter;\n }\n\n export namespace ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n export interface ExpiresAfter {\n /**\n * The anchor point for the ephemeral token expiration. Only `created_at` is\n * currently supported.\n */\n anchor: 'created_at';\n\n /**\n * The number of seconds from the anchor point to the expiration. Select a value\n * between `10` and `7200`.\n */\n seconds?: number;\n }\n }\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: 'near_field' | 'far_field';\n }\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n export interface InputAudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription, current options are `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, and `whisper-1`.\n */\n model?: string;\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. For `whisper-1`, the\n * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n * \"expect words related to technology\".\n */\n prompt?: string;\n }\n\n export interface Tool {\n /**\n * The description of the function, including guidance on when and how to call it,\n * and guidance about what to tell the user when calling (if anything).\n */\n description?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * Parameters of the function in JSON Schema.\n */\n parameters?: unknown;\n\n /**\n * The type of the tool, i.e. `function`.\n */\n type?: 'function';\n }\n\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * traces dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the traces\n * dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the traces dashboard.\n */\n workflow_name?: string;\n }\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n export interface TurnDetection {\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection.\n */\n type?: 'server_vad' | 'semantic_vad';\n }\n}\n\nexport declare namespace Sessions {\n export {\n type Session as Session,\n type SessionCreateResponse as SessionCreateResponse,\n type SessionCreateParams as SessionCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\n\nexport class TranscriptionSessions extends APIResource {\n /**\n * Create an ephemeral API token for use in client-side applications with the\n * Realtime API specifically for realtime transcriptions. Can be configured with\n * the same session parameters as the `transcription_session.update` client event.\n *\n * It responds with a session object, plus a `client_secret` key which contains a\n * usable ephemeral API token that can be used to authenticate browser clients for\n * the Realtime API.\n *\n * @example\n * ```ts\n * const transcriptionSession =\n * await client.beta.realtime.transcriptionSessions.create();\n * ```\n */\n create(body: TranscriptionSessionCreateParams, options?: RequestOptions): APIPromise<TranscriptionSession> {\n return this._client.post('/realtime/transcription_sessions', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n}\n\n/**\n * A new Realtime transcription session configuration.\n *\n * When a session is created on the server via REST API, the session object also\n * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n * not present when a session is updated via the WebSocket API.\n */\nexport interface TranscriptionSession {\n /**\n * Ephemeral key returned by the API. Only present when the session is created on\n * the server via REST API.\n */\n client_secret: TranscriptionSession.ClientSecret;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n */\n input_audio_format?: string;\n\n /**\n * Configuration of the transcription model.\n */\n input_audio_transcription?: TranscriptionSession.InputAudioTranscription;\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n turn_detection?: TranscriptionSession.TurnDetection;\n}\n\nexport namespace TranscriptionSession {\n /**\n * Ephemeral key returned by the API. Only present when the session is created on\n * the server via REST API.\n */\n export interface ClientSecret {\n /**\n * Timestamp for when the token expires. Currently, all tokens expire after one\n * minute.\n */\n expires_at: number;\n\n /**\n * Ephemeral key usable in client environments to authenticate connections to the\n * Realtime API. Use this in client-side environments rather than a standard API\n * token, which should only be used server-side.\n */\n value: string;\n }\n\n /**\n * Configuration of the transcription model.\n */\n export interface InputAudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription. Can be `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, or `whisper-1`.\n */\n model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. The\n * [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)\n * should match the audio language.\n */\n prompt?: string;\n }\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n export interface TurnDetection {\n /**\n * Amount of audio to include before the VAD detected speech (in milliseconds).\n * Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n * With shorter values the model will respond more quickly, but may jump in on\n * short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n * threshold will require louder audio to activate the model, and thus might\n * perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection, only `server_vad` is currently supported.\n */\n type?: string;\n }\n}\n\nexport interface TranscriptionSessionCreateParams {\n /**\n * Configuration options for the generated client secret.\n */\n client_secret?: TranscriptionSessionCreateParams.ClientSecret;\n\n /**\n * The set of items to include in the transcription. Current available items are:\n *\n * - `item.input_audio_transcription.logprobs`\n */\n include?: Array<string>;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: TranscriptionSessionCreateParams.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription. The client can optionally set the\n * language and prompt for transcription, these offer additional guidance to the\n * transcription service.\n */\n input_audio_transcription?: TranscriptionSessionCreateParams.InputAudioTranscription;\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n turn_detection?: TranscriptionSessionCreateParams.TurnDetection;\n}\n\nexport namespace TranscriptionSessionCreateParams {\n /**\n * Configuration options for the generated client secret.\n */\n export interface ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n expires_at?: ClientSecret.ExpiresAt;\n }\n\n export namespace ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n export interface ExpiresAt {\n /**\n * The anchor point for the ephemeral token expiration. Only `created_at` is\n * currently supported.\n */\n anchor?: 'created_at';\n\n /**\n * The number of seconds from the anchor point to the expiration. Select a value\n * between `10` and `7200`.\n */\n seconds?: number;\n }\n }\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: 'near_field' | 'far_field';\n }\n\n /**\n * Configuration for input audio transcription. The client can optionally set the\n * language and prompt for transcription, these offer additional guidance to the\n * transcription service.\n */\n export interface InputAudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription, current options are `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, and `whisper-1`.\n */\n model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. For `whisper-1`, the\n * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n * \"expect words related to technology\".\n */\n prompt?: string;\n }\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n export interface TurnDetection {\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs. Not available for transcription sessions.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs. Not available for transcription sessions.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection.\n */\n type?: 'server_vad' | 'semantic_vad';\n }\n}\n\nexport declare namespace TranscriptionSessions {\n export {\n type TranscriptionSession as TranscriptionSession,\n type TranscriptionSessionCreateParams as TranscriptionSessionCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as RealtimeAPI from './realtime';\nimport * as Shared from '../../shared';\nimport * as SessionsAPI from './sessions';\nimport {\n Session as SessionsAPISession,\n SessionCreateParams,\n SessionCreateResponse,\n Sessions,\n} from './sessions';\nimport * as TranscriptionSessionsAPI from './transcription-sessions';\nimport {\n TranscriptionSession,\n TranscriptionSessionCreateParams,\n TranscriptionSessions,\n} from './transcription-sessions';\n\n/**\n * @deprecated Realtime has now launched and is generally available. The old beta API is now deprecated.\n */\nexport class Realtime extends APIResource {\n sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);\n transcriptionSessions: TranscriptionSessionsAPI.TranscriptionSessions =\n new TranscriptionSessionsAPI.TranscriptionSessions(this._client);\n}\n\n/**\n * Returned when a conversation is created. Emitted right after session creation.\n */\nexport interface ConversationCreatedEvent {\n /**\n * The conversation resource.\n */\n conversation: ConversationCreatedEvent.Conversation;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The event type, must be `conversation.created`.\n */\n type: 'conversation.created';\n}\n\nexport namespace ConversationCreatedEvent {\n /**\n * The conversation resource.\n */\n export interface Conversation {\n /**\n * The unique ID of the conversation.\n */\n id?: string;\n\n /**\n * The object type, must be `realtime.conversation`.\n */\n object?: 'realtime.conversation';\n }\n}\n\n/**\n * The item to add to the conversation.\n */\nexport interface ConversationItem {\n /**\n * The unique ID of the item, this can be generated by the client to help manage\n * server-side context, but is not required because the server will generate one if\n * not provided.\n */\n id?: string;\n\n /**\n * The arguments of the function call (for `function_call` items).\n */\n arguments?: string;\n\n /**\n * The ID of the function call (for `function_call` and `function_call_output`\n * items). If passed on a `function_call_output` item, the server will check that a\n * `function_call` item with the same ID exists in the conversation history.\n */\n call_id?: string;\n\n /**\n * The content of the message, applicable for `message` items.\n *\n * - Message items of role `system` support only `input_text` content\n * - Message items of role `user` support `input_text` and `input_audio` content\n * - Message items of role `assistant` support `text` content.\n */\n content?: Array<ConversationItemContent>;\n\n /**\n * The name of the function being called (for `function_call` items).\n */\n name?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`.\n */\n object?: 'realtime.item';\n\n /**\n * The output of the function call (for `function_call_output` items).\n */\n output?: string;\n\n /**\n * The role of the message sender (`user`, `assistant`, `system`), only applicable\n * for `message` items.\n */\n role?: 'user' | 'assistant' | 'system';\n\n /**\n * The status of the item (`completed`, `incomplete`, `in_progress`). These have no\n * effect on the conversation, but are accepted for consistency with the\n * `conversation.item.created` event.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n\n /**\n * The type of the item (`message`, `function_call`, `function_call_output`).\n */\n type?: 'message' | 'function_call' | 'function_call_output';\n}\n\nexport interface ConversationItemContent {\n /**\n * ID of a previous conversation item to reference (for `item_reference` content\n * types in `response.create` events). These can reference both client and server\n * created items.\n */\n id?: string;\n\n /**\n * Base64-encoded audio bytes, used for `input_audio` content type.\n */\n audio?: string;\n\n /**\n * The text content, used for `input_text` and `text` content types.\n */\n text?: string;\n\n /**\n * The transcript of the audio, used for `input_audio` and `audio` content types.\n */\n transcript?: string;\n\n /**\n * The content type (`input_text`, `input_audio`, `item_reference`, `text`,\n * `audio`).\n */\n type?: 'input_text' | 'input_audio' | 'item_reference' | 'text' | 'audio';\n}\n\n/**\n * Add a new Item to the Conversation's context, including messages, function\n * calls, and function call responses. This event can be used both to populate a\n * \"history\" of the conversation and to add new items mid-stream, but has the\n * current limitation that it cannot populate assistant audio messages.\n *\n * If successful, the server will respond with a `conversation.item.created` event,\n * otherwise an `error` event will be sent.\n */\nexport interface ConversationItemCreateEvent {\n /**\n * The item to add to the conversation.\n */\n item: ConversationItem;\n\n /**\n * The event type, must be `conversation.item.create`.\n */\n type: 'conversation.item.create';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n\n /**\n * The ID of the preceding item after which the new item will be inserted. If not\n * set, the new item will be appended to the end of the conversation. If set to\n * `root`, the new item will be added to the beginning of the conversation. If set\n * to an existing ID, it allows an item to be inserted mid-conversation. If the ID\n * cannot be found, an error will be returned and the item will not be added.\n */\n previous_item_id?: string;\n}\n\n/**\n * Returned when a conversation item is created. There are several scenarios that\n * produce this event:\n *\n * - The server is generating a Response, which if successful will produce either\n * one or two Items, which will be of type `message` (role `assistant`) or type\n * `function_call`.\n * - The input audio buffer has been committed, either by the client or the server\n * (in `server_vad` mode). The server will take the content of the input audio\n * buffer and add it to a new user message Item.\n * - The client has sent a `conversation.item.create` event to add a new Item to\n * the Conversation.\n */\nexport interface ConversationItemCreatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The item to add to the conversation.\n */\n item: ConversationItem;\n\n /**\n * The event type, must be `conversation.item.created`.\n */\n type: 'conversation.item.created';\n\n /**\n * The ID of the preceding item in the Conversation context, allows the client to\n * understand the order of the conversation. Can be `null` if the item has no\n * predecessor.\n */\n previous_item_id?: string | null;\n}\n\n/**\n * Send this event when you want to remove any item from the conversation history.\n * The server will respond with a `conversation.item.deleted` event, unless the\n * item does not exist in the conversation history, in which case the server will\n * respond with an error.\n */\nexport interface ConversationItemDeleteEvent {\n /**\n * The ID of the item to delete.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.delete`.\n */\n type: 'conversation.item.delete';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when an item in the conversation is deleted by the client with a\n * `conversation.item.delete` event. This event is used to synchronize the server's\n * understanding of the conversation history with the client's view.\n */\nexport interface ConversationItemDeletedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item that was deleted.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.deleted`.\n */\n type: 'conversation.item.deleted';\n}\n\n/**\n * This event is the output of audio transcription for user audio written to the\n * user audio buffer. Transcription begins when the input audio buffer is committed\n * by the client or server (in `server_vad` mode). Transcription runs\n * asynchronously with Response creation, so this event may come before or after\n * the Response events.\n *\n * Realtime API models accept audio natively, and thus input transcription is a\n * separate process run on a separate ASR (Automatic Speech Recognition) model. The\n * transcript may diverge somewhat from the model's interpretation, and should be\n * treated as a rough guide.\n */\nexport interface ConversationItemInputAudioTranscriptionCompletedEvent {\n /**\n * The index of the content part containing the audio.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item containing the audio.\n */\n item_id: string;\n\n /**\n * The transcribed text.\n */\n transcript: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.completed`.\n */\n type: 'conversation.item.input_audio_transcription.completed';\n\n /**\n * Usage statistics for the transcription.\n */\n usage:\n | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageTokens\n | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageDuration;\n\n /**\n * The log probabilities of the transcription.\n */\n logprobs?: Array<ConversationItemInputAudioTranscriptionCompletedEvent.Logprob> | null;\n}\n\nexport namespace ConversationItemInputAudioTranscriptionCompletedEvent {\n /**\n * Usage statistics for models billed by token usage.\n */\n export interface TranscriptTextUsageTokens {\n /**\n * Number of input tokens billed for this request.\n */\n input_tokens: number;\n\n /**\n * Number of output tokens generated.\n */\n output_tokens: number;\n\n /**\n * Total number of tokens used (input + output).\n */\n total_tokens: number;\n\n /**\n * The type of the usage object. Always `tokens` for this variant.\n */\n type: 'tokens';\n\n /**\n * Details about the input tokens billed for this request.\n */\n input_token_details?: TranscriptTextUsageTokens.InputTokenDetails;\n }\n\n export namespace TranscriptTextUsageTokens {\n /**\n * Details about the input tokens billed for this request.\n */\n export interface InputTokenDetails {\n /**\n * Number of audio tokens billed for this request.\n */\n audio_tokens?: number;\n\n /**\n * Number of text tokens billed for this request.\n */\n text_tokens?: number;\n }\n }\n\n /**\n * Usage statistics for models billed by audio input duration.\n */\n export interface TranscriptTextUsageDuration {\n /**\n * Duration of the input audio in seconds.\n */\n seconds: number;\n\n /**\n * The type of the usage object. Always `duration` for this variant.\n */\n type: 'duration';\n }\n\n /**\n * A log probability object.\n */\n export interface Logprob {\n /**\n * The token that was used to generate the log probability.\n */\n token: string;\n\n /**\n * The bytes that were used to generate the log probability.\n */\n bytes: Array<number>;\n\n /**\n * The log probability of the token.\n */\n logprob: number;\n }\n}\n\n/**\n * Returned when the text value of an input audio transcription content part is\n * updated.\n */\nexport interface ConversationItemInputAudioTranscriptionDeltaEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.delta`.\n */\n type: 'conversation.item.input_audio_transcription.delta';\n\n /**\n * The index of the content part in the item's content array.\n */\n content_index?: number;\n\n /**\n * The text delta.\n */\n delta?: string;\n\n /**\n * The log probabilities of the transcription.\n */\n logprobs?: Array<ConversationItemInputAudioTranscriptionDeltaEvent.Logprob> | null;\n}\n\nexport namespace ConversationItemInputAudioTranscriptionDeltaEvent {\n /**\n * A log probability object.\n */\n export interface Logprob {\n /**\n * The token that was used to generate the log probability.\n */\n token: string;\n\n /**\n * The bytes that were used to generate the log probability.\n */\n bytes: Array<number>;\n\n /**\n * The log probability of the token.\n */\n logprob: number;\n }\n}\n\n/**\n * Returned when input audio transcription is configured, and a transcription\n * request for a user message failed. These events are separate from other `error`\n * events so that the client can identify the related Item.\n */\nexport interface ConversationItemInputAudioTranscriptionFailedEvent {\n /**\n * The index of the content part containing the audio.\n */\n content_index: number;\n\n /**\n * Details of the transcription error.\n */\n error: ConversationItemInputAudioTranscriptionFailedEvent.Error;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.failed`.\n */\n type: 'conversation.item.input_audio_transcription.failed';\n}\n\nexport namespace ConversationItemInputAudioTranscriptionFailedEvent {\n /**\n * Details of the transcription error.\n */\n export interface Error {\n /**\n * Error code, if any.\n */\n code?: string;\n\n /**\n * A human-readable error message.\n */\n message?: string;\n\n /**\n * Parameter related to the error, if any.\n */\n param?: string;\n\n /**\n * The type of error.\n */\n type?: string;\n }\n}\n\n/**\n * Send this event when you want to retrieve the server's representation of a\n * specific item in the conversation history. This is useful, for example, to\n * inspect user audio after noise cancellation and VAD. The server will respond\n * with a `conversation.item.retrieved` event, unless the item does not exist in\n * the conversation history, in which case the server will respond with an error.\n */\nexport interface ConversationItemRetrieveEvent {\n /**\n * The ID of the item to retrieve.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.retrieve`.\n */\n type: 'conversation.item.retrieve';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Send this event to truncate a previous assistant message’s audio. The server\n * will produce audio faster than realtime, so this event is useful when the user\n * interrupts to truncate audio that has already been sent to the client but not\n * yet played. This will synchronize the server's understanding of the audio with\n * the client's playback.\n *\n * Truncating audio will delete the server-side text transcript to ensure there is\n * not text in the context that hasn't been heard by the user.\n *\n * If successful, the server will respond with a `conversation.item.truncated`\n * event.\n */\nexport interface ConversationItemTruncateEvent {\n /**\n * Inclusive duration up to which audio is truncated, in milliseconds. If the\n * audio_end_ms is greater than the actual audio duration, the server will respond\n * with an error.\n */\n audio_end_ms: number;\n\n /**\n * The index of the content part to truncate. Set this to 0.\n */\n content_index: number;\n\n /**\n * The ID of the assistant message item to truncate. Only assistant message items\n * can be truncated.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.truncate`.\n */\n type: 'conversation.item.truncate';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when an earlier assistant audio message item is truncated by the client\n * with a `conversation.item.truncate` event. This event is used to synchronize the\n * server's understanding of the audio with the client's playback.\n *\n * This action will truncate the audio and remove the server-side text transcript\n * to ensure there is no text in the context that hasn't been heard by the user.\n */\nexport interface ConversationItemTruncatedEvent {\n /**\n * The duration up to which the audio was truncated, in milliseconds.\n */\n audio_end_ms: number;\n\n /**\n * The index of the content part that was truncated.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the assistant message item that was truncated.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.truncated`.\n */\n type: 'conversation.item.truncated';\n}\n\n/**\n * The item to add to the conversation.\n */\nexport interface ConversationItemWithReference {\n /**\n * For an item of type (`message` | `function_call` | `function_call_output`) this\n * field allows the client to assign the unique ID of the item. It is not required\n * because the server will generate one if not provided.\n *\n * For an item of type `item_reference`, this field is required and is a reference\n * to any item that has previously existed in the conversation.\n */\n id?: string;\n\n /**\n * The arguments of the function call (for `function_call` items).\n */\n arguments?: string;\n\n /**\n * The ID of the function call (for `function_call` and `function_call_output`\n * items). If passed on a `function_call_output` item, the server will check that a\n * `function_call` item with the same ID exists in the conversation history.\n */\n call_id?: string;\n\n /**\n * The content of the message, applicable for `message` items.\n *\n * - Message items of role `system` support only `input_text` content\n * - Message items of role `user` support `input_text` and `input_audio` content\n * - Message items of role `assistant` support `text` content.\n */\n content?: Array<ConversationItemWithReference.Content>;\n\n /**\n * The name of the function being called (for `function_call` items).\n */\n name?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`.\n */\n object?: 'realtime.item';\n\n /**\n * The output of the function call (for `function_call_output` items).\n */\n output?: string;\n\n /**\n * The role of the message sender (`user`, `assistant`, `system`), only applicable\n * for `message` items.\n */\n role?: 'user' | 'assistant' | 'system';\n\n /**\n * The status of the item (`completed`, `incomplete`, `in_progress`). These have no\n * effect on the conversation, but are accepted for consistency with the\n * `conversation.item.created` event.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n\n /**\n * The type of the item (`message`, `function_call`, `function_call_output`,\n * `item_reference`).\n */\n type?: 'message' | 'function_call' | 'function_call_output' | 'item_reference';\n}\n\nexport namespace ConversationItemWithReference {\n export interface Content {\n /**\n * ID of a previous conversation item to reference (for `item_reference` content\n * types in `response.create` events). These can reference both client and server\n * created items.\n */\n id?: string;\n\n /**\n * Base64-encoded audio bytes, used for `input_audio` content type.\n */\n audio?: string;\n\n /**\n * The text content, used for `input_text` and `text` content types.\n */\n text?: string;\n\n /**\n * The transcript of the audio, used for `input_audio` content type.\n */\n transcript?: string;\n\n /**\n * The content type (`input_text`, `input_audio`, `item_reference`, `text`).\n */\n type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';\n }\n}\n\n/**\n * Returned when an error occurs, which could be a client problem or a server\n * problem. Most errors are recoverable and the session will stay open, we\n * recommend to implementors to monitor and log error messages by default.\n */\nexport interface ErrorEvent {\n /**\n * Details of the error.\n */\n error: ErrorEvent.Error;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The event type, must be `error`.\n */\n type: 'error';\n}\n\nexport namespace ErrorEvent {\n /**\n * Details of the error.\n */\n export interface Error {\n /**\n * A human-readable error message.\n */\n message: string;\n\n /**\n * The type of error (e.g., \"invalid_request_error\", \"server_error\").\n */\n type: string;\n\n /**\n * Error code, if any.\n */\n code?: string | null;\n\n /**\n * The event_id of the client event that caused the error, if applicable.\n */\n event_id?: string | null;\n\n /**\n * Parameter related to the error, if any.\n */\n param?: string | null;\n }\n}\n\n/**\n * Send this event to append audio bytes to the input audio buffer. The audio\n * buffer is temporary storage you can write to and later commit. In Server VAD\n * mode, the audio buffer is used to detect speech and the server will decide when\n * to commit. When Server VAD is disabled, you must commit the audio buffer\n * manually.\n *\n * The client may choose how much audio to place in each event up to a maximum of\n * 15 MiB, for example streaming smaller chunks from the client may allow the VAD\n * to be more responsive. Unlike made other client events, the server will not send\n * a confirmation response to this event.\n */\nexport interface InputAudioBufferAppendEvent {\n /**\n * Base64-encoded audio bytes. This must be in the format specified by the\n * `input_audio_format` field in the session configuration.\n */\n audio: string;\n\n /**\n * The event type, must be `input_audio_buffer.append`.\n */\n type: 'input_audio_buffer.append';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Send this event to clear the audio bytes in the buffer. The server will respond\n * with an `input_audio_buffer.cleared` event.\n */\nexport interface InputAudioBufferClearEvent {\n /**\n * The event type, must be `input_audio_buffer.clear`.\n */\n type: 'input_audio_buffer.clear';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when the input audio buffer is cleared by the client with a\n * `input_audio_buffer.clear` event.\n */\nexport interface InputAudioBufferClearedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.cleared`.\n */\n type: 'input_audio_buffer.cleared';\n}\n\n/**\n * Send this event to commit the user input audio buffer, which will create a new\n * user message item in the conversation. This event will produce an error if the\n * input audio buffer is empty. When in Server VAD mode, the client does not need\n * to send this event, the server will commit the audio buffer automatically.\n *\n * Committing the input audio buffer will trigger input audio transcription (if\n * enabled in session configuration), but it will not create a response from the\n * model. The server will respond with an `input_audio_buffer.committed` event.\n */\nexport interface InputAudioBufferCommitEvent {\n /**\n * The event type, must be `input_audio_buffer.commit`.\n */\n type: 'input_audio_buffer.commit';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when an input audio buffer is committed, either by the client or\n * automatically in server VAD mode. The `item_id` property is the ID of the user\n * message item that will be created, thus a `conversation.item.created` event will\n * also be sent to the client.\n */\nexport interface InputAudioBufferCommittedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item that will be created.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.committed`.\n */\n type: 'input_audio_buffer.committed';\n\n /**\n * The ID of the preceding item after which the new item will be inserted. Can be\n * `null` if the item has no predecessor.\n */\n previous_item_id?: string | null;\n}\n\n/**\n * Sent by the server when in `server_vad` mode to indicate that speech has been\n * detected in the audio buffer. This can happen any time audio is added to the\n * buffer (unless speech is already detected). The client may want to use this\n * event to interrupt audio playback or provide visual feedback to the user.\n *\n * The client should expect to receive a `input_audio_buffer.speech_stopped` event\n * when speech stops. The `item_id` property is the ID of the user message item\n * that will be created when speech stops and will also be included in the\n * `input_audio_buffer.speech_stopped` event (unless the client manually commits\n * the audio buffer during VAD activation).\n */\nexport interface InputAudioBufferSpeechStartedEvent {\n /**\n * Milliseconds from the start of all audio written to the buffer during the\n * session when speech was first detected. This will correspond to the beginning of\n * audio sent to the model, and thus includes the `prefix_padding_ms` configured in\n * the Session.\n */\n audio_start_ms: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item that will be created when speech stops.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.speech_started`.\n */\n type: 'input_audio_buffer.speech_started';\n}\n\n/**\n * Returned in `server_vad` mode when the server detects the end of speech in the\n * audio buffer. The server will also send an `conversation.item.created` event\n * with the user message item that is created from the audio buffer.\n */\nexport interface InputAudioBufferSpeechStoppedEvent {\n /**\n * Milliseconds since the session started when speech stopped. This will correspond\n * to the end of audio sent to the model, and thus includes the\n * `min_silence_duration_ms` configured in the Session.\n */\n audio_end_ms: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item that will be created.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.speech_stopped`.\n */\n type: 'input_audio_buffer.speech_stopped';\n}\n\n/**\n * Emitted at the beginning of a Response to indicate the updated rate limits. When\n * a Response is created some tokens will be \"reserved\" for the output tokens, the\n * rate limits shown here reflect that reservation, which is then adjusted\n * accordingly once the Response is completed.\n */\nexport interface RateLimitsUpdatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * List of rate limit information.\n */\n rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;\n\n /**\n * The event type, must be `rate_limits.updated`.\n */\n type: 'rate_limits.updated';\n}\n\nexport namespace RateLimitsUpdatedEvent {\n export interface RateLimit {\n /**\n * The maximum allowed value for the rate limit.\n */\n limit?: number;\n\n /**\n * The name of the rate limit (`requests`, `tokens`).\n */\n name?: 'requests' | 'tokens';\n\n /**\n * The remaining value before the limit is reached.\n */\n remaining?: number;\n\n /**\n * Seconds until the rate limit resets.\n */\n reset_seconds?: number;\n }\n}\n\n/**\n * A realtime client event.\n */\nexport type RealtimeClientEvent =\n | ConversationItemCreateEvent\n | ConversationItemDeleteEvent\n | ConversationItemRetrieveEvent\n | ConversationItemTruncateEvent\n | InputAudioBufferAppendEvent\n | InputAudioBufferClearEvent\n | RealtimeClientEvent.OutputAudioBufferClear\n | InputAudioBufferCommitEvent\n | ResponseCancelEvent\n | ResponseCreateEvent\n | SessionUpdateEvent\n | TranscriptionSessionUpdate;\n\nexport namespace RealtimeClientEvent {\n /**\n * **WebRTC Only:** Emit to cut off the current audio response. This will trigger\n * the server to stop generating audio and emit a `output_audio_buffer.cleared`\n * event. This event should be preceded by a `response.cancel` client event to stop\n * the generation of the current response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferClear {\n /**\n * The event type, must be `output_audio_buffer.clear`.\n */\n type: 'output_audio_buffer.clear';\n\n /**\n * The unique ID of the client event used for error handling.\n */\n event_id?: string;\n }\n}\n\n/**\n * The response resource.\n */\nexport interface RealtimeResponse {\n /**\n * The unique ID of the response.\n */\n id?: string;\n\n /**\n * Which conversation the response is added to, determined by the `conversation`\n * field in the `response.create` event. If `auto`, the response will be added to\n * the default conversation and the value of `conversation_id` will be an id like\n * `conv_1234`. If `none`, the response will not be added to any conversation and\n * the value of `conversation_id` will be `null`. If responses are being triggered\n * by server VAD, the response will be added to the default conversation, thus the\n * `conversation_id` will be an id like `conv_1234`.\n */\n conversation_id?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls, that was used in this response.\n */\n max_output_tokens?: number | 'inf';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The set of modalities the model used to respond. If there are multiple\n * modalities, the model will pick one, for example if `modalities` is\n * `[\"text\", \"audio\"]`, the model could be responding in either text or audio.\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The object type, must be `realtime.response`.\n */\n object?: 'realtime.response';\n\n /**\n * The list of output items generated by the response.\n */\n output?: Array<ConversationItem>;\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n */\n output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * The final status of the response (`completed`, `cancelled`, `failed`, or\n * `incomplete`, `in_progress`).\n */\n status?: 'completed' | 'cancelled' | 'failed' | 'incomplete' | 'in_progress';\n\n /**\n * Additional details about the status.\n */\n status_details?: RealtimeResponseStatus;\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.\n */\n temperature?: number;\n\n /**\n * Usage statistics for the Response, this will correspond to billing. A Realtime\n * API session will maintain a conversation context and append new Items to the\n * Conversation, thus output from previous turns (text and audio tokens) will\n * become the input for later turns.\n */\n usage?: RealtimeResponseUsage;\n\n /**\n * The voice the model used to respond. Current voice options are `alloy`, `ash`,\n * `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n}\n\n/**\n * Additional details about the status.\n */\nexport interface RealtimeResponseStatus {\n /**\n * A description of the error that caused the response to fail, populated when the\n * `status` is `failed`.\n */\n error?: RealtimeResponseStatus.Error;\n\n /**\n * The reason the Response did not complete. For a `cancelled` Response, one of\n * `turn_detected` (the server VAD detected a new start of speech) or\n * `client_cancelled` (the client sent a cancel event). For an `incomplete`\n * Response, one of `max_output_tokens` or `content_filter` (the server-side safety\n * filter activated and cut off the response).\n */\n reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';\n\n /**\n * The type of error that caused the response to fail, corresponding with the\n * `status` field (`completed`, `cancelled`, `incomplete`, `failed`).\n */\n type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';\n}\n\nexport namespace RealtimeResponseStatus {\n /**\n * A description of the error that caused the response to fail, populated when the\n * `status` is `failed`.\n */\n export interface Error {\n /**\n * Error code, if any.\n */\n code?: string;\n\n /**\n * The type of error.\n */\n type?: string;\n }\n}\n\n/**\n * Usage statistics for the Response, this will correspond to billing. A Realtime\n * API session will maintain a conversation context and append new Items to the\n * Conversation, thus output from previous turns (text and audio tokens) will\n * become the input for later turns.\n */\nexport interface RealtimeResponseUsage {\n /**\n * Details about the input tokens used in the Response.\n */\n input_token_details?: RealtimeResponseUsage.InputTokenDetails;\n\n /**\n * The number of input tokens used in the Response, including text and audio\n * tokens.\n */\n input_tokens?: number;\n\n /**\n * Details about the output tokens used in the Response.\n */\n output_token_details?: RealtimeResponseUsage.OutputTokenDetails;\n\n /**\n * The number of output tokens sent in the Response, including text and audio\n * tokens.\n */\n output_tokens?: number;\n\n /**\n * The total number of tokens in the Response including input and output text and\n * audio tokens.\n */\n total_tokens?: number;\n}\n\nexport namespace RealtimeResponseUsage {\n /**\n * Details about the input tokens used in the Response.\n */\n export interface InputTokenDetails {\n /**\n * The number of audio tokens used in the Response.\n */\n audio_tokens?: number;\n\n /**\n * The number of cached tokens used in the Response.\n */\n cached_tokens?: number;\n\n /**\n * The number of text tokens used in the Response.\n */\n text_tokens?: number;\n }\n\n /**\n * Details about the output tokens used in the Response.\n */\n export interface OutputTokenDetails {\n /**\n * The number of audio tokens used in the Response.\n */\n audio_tokens?: number;\n\n /**\n * The number of text tokens used in the Response.\n */\n text_tokens?: number;\n }\n}\n\n/**\n * A realtime server event.\n */\nexport type RealtimeServerEvent =\n | ConversationCreatedEvent\n | ConversationItemCreatedEvent\n | ConversationItemDeletedEvent\n | ConversationItemInputAudioTranscriptionCompletedEvent\n | ConversationItemInputAudioTranscriptionDeltaEvent\n | ConversationItemInputAudioTranscriptionFailedEvent\n | RealtimeServerEvent.ConversationItemRetrieved\n | ConversationItemTruncatedEvent\n | ErrorEvent\n | InputAudioBufferClearedEvent\n | InputAudioBufferCommittedEvent\n | InputAudioBufferSpeechStartedEvent\n | InputAudioBufferSpeechStoppedEvent\n | RateLimitsUpdatedEvent\n | ResponseAudioDeltaEvent\n | ResponseAudioDoneEvent\n | ResponseAudioTranscriptDeltaEvent\n | ResponseAudioTranscriptDoneEvent\n | ResponseContentPartAddedEvent\n | ResponseContentPartDoneEvent\n | ResponseCreatedEvent\n | ResponseDoneEvent\n | ResponseFunctionCallArgumentsDeltaEvent\n | ResponseFunctionCallArgumentsDoneEvent\n | ResponseOutputItemAddedEvent\n | ResponseOutputItemDoneEvent\n | ResponseTextDeltaEvent\n | ResponseTextDoneEvent\n | SessionCreatedEvent\n | SessionUpdatedEvent\n | TranscriptionSessionUpdatedEvent\n | RealtimeServerEvent.OutputAudioBufferStarted\n | RealtimeServerEvent.OutputAudioBufferStopped\n | RealtimeServerEvent.OutputAudioBufferCleared;\n\nexport namespace RealtimeServerEvent {\n /**\n * Returned when a conversation item is retrieved with\n * `conversation.item.retrieve`.\n */\n export interface ConversationItemRetrieved {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The item to add to the conversation.\n */\n item: RealtimeAPI.ConversationItem;\n\n /**\n * The event type, must be `conversation.item.retrieved`.\n */\n type: 'conversation.item.retrieved';\n }\n\n /**\n * **WebRTC Only:** Emitted when the server begins streaming audio to the client.\n * This event is emitted after an audio content part has been added\n * (`response.content_part.added`) to the response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferStarted {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The unique ID of the response that produced the audio.\n */\n response_id: string;\n\n /**\n * The event type, must be `output_audio_buffer.started`.\n */\n type: 'output_audio_buffer.started';\n }\n\n /**\n * **WebRTC Only:** Emitted when the output audio buffer has been completely\n * drained on the server, and no more audio is forthcoming. This event is emitted\n * after the full response data has been sent to the client (`response.done`).\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferStopped {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The unique ID of the response that produced the audio.\n */\n response_id: string;\n\n /**\n * The event type, must be `output_audio_buffer.stopped`.\n */\n type: 'output_audio_buffer.stopped';\n }\n\n /**\n * **WebRTC Only:** Emitted when the output audio buffer is cleared. This happens\n * either in VAD mode when the user has interrupted\n * (`input_audio_buffer.speech_started`), or when the client has emitted the\n * `output_audio_buffer.clear` event to manually cut off the current audio\n * response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferCleared {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The unique ID of the response that produced the audio.\n */\n response_id: string;\n\n /**\n * The event type, must be `output_audio_buffer.cleared`.\n */\n type: 'output_audio_buffer.cleared';\n }\n}\n\n/**\n * Returned when the model-generated audio is updated.\n */\nexport interface ResponseAudioDeltaEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * Base64-encoded audio data delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.audio.delta`.\n */\n type: 'response.audio.delta';\n}\n\n/**\n * Returned when the model-generated audio is done. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseAudioDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.audio.done`.\n */\n type: 'response.audio.done';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is updated.\n */\nexport interface ResponseAudioTranscriptDeltaEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The transcript delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.audio_transcript.delta`.\n */\n type: 'response.audio_transcript.delta';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is done\n * streaming. Also emitted when a Response is interrupted, incomplete, or\n * cancelled.\n */\nexport interface ResponseAudioTranscriptDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The final transcript of the audio.\n */\n transcript: string;\n\n /**\n * The event type, must be `response.audio_transcript.done`.\n */\n type: 'response.audio_transcript.done';\n}\n\n/**\n * Send this event to cancel an in-progress response. The server will respond with\n * a `response.done` event with a status of `response.status=cancelled`. If there\n * is no response to cancel, the server will respond with an error.\n */\nexport interface ResponseCancelEvent {\n /**\n * The event type, must be `response.cancel`.\n */\n type: 'response.cancel';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n\n /**\n * A specific response ID to cancel - if not provided, will cancel an in-progress\n * response in the default conversation.\n */\n response_id?: string;\n}\n\n/**\n * Returned when a new content part is added to an assistant message item during\n * response generation.\n */\nexport interface ResponseContentPartAddedEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item to which the content part was added.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The content part that was added.\n */\n part: ResponseContentPartAddedEvent.Part;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.content_part.added`.\n */\n type: 'response.content_part.added';\n}\n\nexport namespace ResponseContentPartAddedEvent {\n /**\n * The content part that was added.\n */\n export interface Part {\n /**\n * Base64-encoded audio data (if type is \"audio\").\n */\n audio?: string;\n\n /**\n * The text content (if type is \"text\").\n */\n text?: string;\n\n /**\n * The transcript of the audio (if type is \"audio\").\n */\n transcript?: string;\n\n /**\n * The content type (\"text\", \"audio\").\n */\n type?: 'text' | 'audio';\n }\n}\n\n/**\n * Returned when a content part is done streaming in an assistant message item.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseContentPartDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The content part that is done.\n */\n part: ResponseContentPartDoneEvent.Part;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.content_part.done`.\n */\n type: 'response.content_part.done';\n}\n\nexport namespace ResponseContentPartDoneEvent {\n /**\n * The content part that is done.\n */\n export interface Part {\n /**\n * Base64-encoded audio data (if type is \"audio\").\n */\n audio?: string;\n\n /**\n * The text content (if type is \"text\").\n */\n text?: string;\n\n /**\n * The transcript of the audio (if type is \"audio\").\n */\n transcript?: string;\n\n /**\n * The content type (\"text\", \"audio\").\n */\n type?: 'text' | 'audio';\n }\n}\n\n/**\n * This event instructs the server to create a Response, which means triggering\n * model inference. When in Server VAD mode, the server will create Responses\n * automatically.\n *\n * A Response will include at least one Item, and may have two, in which case the\n * second will be a function call. These Items will be appended to the conversation\n * history.\n *\n * The server will respond with a `response.created` event, events for Items and\n * content created, and finally a `response.done` event to indicate the Response is\n * complete.\n *\n * The `response.create` event includes inference configuration like\n * `instructions`, and `temperature`. These fields will override the Session's\n * configuration for this Response only.\n */\nexport interface ResponseCreateEvent {\n /**\n * The event type, must be `response.create`.\n */\n type: 'response.create';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n\n /**\n * Create a new Realtime response with these parameters\n */\n response?: ResponseCreateEvent.Response;\n}\n\nexport namespace ResponseCreateEvent {\n /**\n * Create a new Realtime response with these parameters\n */\n export interface Response {\n /**\n * Controls which conversation the response is added to. Currently supports `auto`\n * and `none`, with `auto` as the default value. The `auto` value means that the\n * contents of the response will be added to the default conversation. Set this to\n * `none` to create an out-of-band response which will not add items to default\n * conversation.\n */\n conversation?: (string & {}) | 'auto' | 'none';\n\n /**\n * Input items to include in the prompt for the model. Using this field creates a\n * new context for this Response instead of using the default conversation. An\n * empty array `[]` will clear the context for this Response. Note that this can\n * include references to items from the default conversation.\n */\n input?: Array<RealtimeAPI.ConversationItemWithReference>;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_response_output_tokens?: number | 'inf';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n */\n output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.\n */\n temperature?: number;\n\n /**\n * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n * a function, like `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}`.\n */\n tool_choice?: string;\n\n /**\n * Tools (functions) available to the model.\n */\n tools?: Array<Response.Tool>;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n }\n\n export namespace Response {\n export interface Tool {\n /**\n * The description of the function, including guidance on when and how to call it,\n * and guidance about what to tell the user when calling (if anything).\n */\n description?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * Parameters of the function in JSON Schema.\n */\n parameters?: unknown;\n\n /**\n * The type of the tool, i.e. `function`.\n */\n type?: 'function';\n }\n }\n}\n\n/**\n * Returned when a new Response is created. The first event of response creation,\n * where the response is in an initial state of `in_progress`.\n */\nexport interface ResponseCreatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The response resource.\n */\n response: RealtimeResponse;\n\n /**\n * The event type, must be `response.created`.\n */\n type: 'response.created';\n}\n\n/**\n * Returned when a Response is done streaming. Always emitted, no matter the final\n * state. The Response object included in the `response.done` event will include\n * all output Items in the Response but will omit the raw audio data.\n */\nexport interface ResponseDoneEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The response resource.\n */\n response: RealtimeResponse;\n\n /**\n * The event type, must be `response.done`.\n */\n type: 'response.done';\n}\n\n/**\n * Returned when the model-generated function call arguments are updated.\n */\nexport interface ResponseFunctionCallArgumentsDeltaEvent {\n /**\n * The ID of the function call.\n */\n call_id: string;\n\n /**\n * The arguments delta as a JSON string.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the function call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.function_call_arguments.delta`.\n */\n type: 'response.function_call_arguments.delta';\n}\n\n/**\n * Returned when the model-generated function call arguments are done streaming.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseFunctionCallArgumentsDoneEvent {\n /**\n * The final arguments as a JSON string.\n */\n arguments: string;\n\n /**\n * The ID of the function call.\n */\n call_id: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the function call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.function_call_arguments.done`.\n */\n type: 'response.function_call_arguments.done';\n}\n\n/**\n * Returned when a new Item is created during Response generation.\n */\nexport interface ResponseOutputItemAddedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The item to add to the conversation.\n */\n item: ConversationItem;\n\n /**\n * The index of the output item in the Response.\n */\n output_index: number;\n\n /**\n * The ID of the Response to which the item belongs.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_item.added`.\n */\n type: 'response.output_item.added';\n}\n\n/**\n * Returned when an Item is done streaming. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseOutputItemDoneEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The item to add to the conversation.\n */\n item: ConversationItem;\n\n /**\n * The index of the output item in the Response.\n */\n output_index: number;\n\n /**\n * The ID of the Response to which the item belongs.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_item.done`.\n */\n type: 'response.output_item.done';\n}\n\n/**\n * Returned when the text value of a \"text\" content part is updated.\n */\nexport interface ResponseTextDeltaEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The text delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.text.delta`.\n */\n type: 'response.text.delta';\n}\n\n/**\n * Returned when the text value of a \"text\" content part is done streaming. Also\n * emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseTextDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The final text content.\n */\n text: string;\n\n /**\n * The event type, must be `response.text.done`.\n */\n type: 'response.text.done';\n}\n\n/**\n * Returned when a Session is created. Emitted automatically when a new connection\n * is established as the first server event. This event will contain the default\n * Session configuration.\n */\nexport interface SessionCreatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * Realtime session object configuration.\n */\n session: SessionsAPI.Session;\n\n /**\n * The event type, must be `session.created`.\n */\n type: 'session.created';\n}\n\n/**\n * Send this event to update the session’s default configuration. The client may\n * send this event at any time to update any field, except for `voice`. However,\n * note that once a session has been initialized with a particular `model`, it\n * can’t be changed to another model using `session.update`.\n *\n * When the server receives a `session.update`, it will respond with a\n * `session.updated` event showing the full, effective configuration. Only the\n * fields that are present are updated. To clear a field like `instructions`, pass\n * an empty string.\n */\nexport interface SessionUpdateEvent {\n /**\n * Realtime session object configuration.\n */\n session: SessionUpdateEvent.Session;\n\n /**\n * The event type, must be `session.update`.\n */\n type: 'session.update';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\nexport namespace SessionUpdateEvent {\n /**\n * Realtime session object configuration.\n */\n export interface Session {\n /**\n * Configuration options for the generated client secret.\n */\n client_secret?: Session.ClientSecret;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n input_audio_transcription?: Session.InputAudioTranscription;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_response_output_tokens?: number | 'inf';\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17';\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n * For `pcm16`, output audio is sampled at a rate of 24kHz.\n */\n output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n * between model turns, not while a response is in progress.\n */\n speed?: number;\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n * temperature of 0.8 is highly recommended for best performance.\n */\n temperature?: number;\n\n /**\n * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n * a function.\n */\n tool_choice?: string;\n\n /**\n * Tools (functions) available to the model.\n */\n tools?: Array<Session.Tool>;\n\n /**\n * Configuration options for tracing. Set to null to disable tracing. Once tracing\n * is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: 'auto' | Session.TracingConfiguration;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n turn_detection?: Session.TurnDetection;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';\n }\n\n export namespace Session {\n /**\n * Configuration options for the generated client secret.\n */\n export interface ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n expires_after?: ClientSecret.ExpiresAfter;\n }\n\n export namespace ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n export interface ExpiresAfter {\n /**\n * The anchor point for the ephemeral token expiration. Only `created_at` is\n * currently supported.\n */\n anchor: 'created_at';\n\n /**\n * The number of seconds from the anchor point to the expiration. Select a value\n * between `10` and `7200`.\n */\n seconds?: number;\n }\n }\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: 'near_field' | 'far_field';\n }\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n export interface InputAudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription, current options are `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, and `whisper-1`.\n */\n model?: string;\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. For `whisper-1`, the\n * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n * \"expect words related to technology\".\n */\n prompt?: string;\n }\n\n export interface Tool {\n /**\n * The description of the function, including guidance on when and how to call it,\n * and guidance about what to tell the user when calling (if anything).\n */\n description?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * Parameters of the function in JSON Schema.\n */\n parameters?: unknown;\n\n /**\n * The type of the tool, i.e. `function`.\n */\n type?: 'function';\n }\n\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * traces dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the traces\n * dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the traces dashboard.\n */\n workflow_name?: string;\n }\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n export interface TurnDetection {\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection.\n */\n type?: 'server_vad' | 'semantic_vad';\n }\n }\n}\n\n/**\n * Returned when a session is updated with a `session.update` event, unless there\n * is an error.\n */\nexport interface SessionUpdatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * Realtime session object configuration.\n */\n session: SessionsAPI.Session;\n\n /**\n * The event type, must be `session.updated`.\n */\n type: 'session.updated';\n}\n\n/**\n * Send this event to update a transcription session.\n */\nexport interface TranscriptionSessionUpdate {\n /**\n * Realtime transcription session object configuration.\n */\n session: TranscriptionSessionUpdate.Session;\n\n /**\n * The event type, must be `transcription_session.update`.\n */\n type: 'transcription_session.update';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\nexport namespace TranscriptionSessionUpdate {\n /**\n * Realtime transcription session object configuration.\n */\n export interface Session {\n /**\n * Configuration options for the generated client secret.\n */\n client_secret?: Session.ClientSecret;\n\n /**\n * The set of items to include in the transcription. Current available items are:\n *\n * - `item.input_audio_transcription.logprobs`\n */\n include?: Array<string>;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription. The client can optionally set the\n * language and prompt for transcription, these offer additional guidance to the\n * transcription service.\n */\n input_audio_transcription?: Session.InputAudioTranscription;\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n turn_detection?: Session.TurnDetection;\n }\n\n export namespace Session {\n /**\n * Configuration options for the generated client secret.\n */\n export interface ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n expires_at?: ClientSecret.ExpiresAt;\n }\n\n export namespace ClientSecret {\n /**\n * Configuration for the ephemeral token expiration.\n */\n export interface ExpiresAt {\n /**\n * The anchor point for the ephemeral token expiration. Only `created_at` is\n * currently supported.\n */\n anchor?: 'created_at';\n\n /**\n * The number of seconds from the anchor point to the expiration. Select a value\n * between `10` and `7200`.\n */\n seconds?: number;\n }\n }\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: 'near_field' | 'far_field';\n }\n\n /**\n * Configuration for input audio transcription. The client can optionally set the\n * language and prompt for transcription, these offer additional guidance to the\n * transcription service.\n */\n export interface InputAudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription, current options are `gpt-4o-transcribe`,\n * `gpt-4o-mini-transcribe`, and `whisper-1`.\n */\n model?: 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'whisper-1';\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. For `whisper-1`, the\n * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n * For `gpt-4o-transcribe` models, the prompt is a free text string, for example\n * \"expect words related to technology\".\n */\n prompt?: string;\n }\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response. Server VAD means that the model will detect the start and end of\n * speech based on audio volume and respond at the end of user speech. Semantic VAD\n * is more advanced and uses a turn detection model (in conjunction with VAD) to\n * semantically estimate whether the user has finished speaking, then dynamically\n * sets a timeout based on this probability. For example, if user audio trails off\n * with \"uhhm\", the model will score a low probability of turn end and wait longer\n * for the user to continue speaking. This can be useful for more natural\n * conversations, but may have a higher latency.\n */\n export interface TurnDetection {\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs. Not available for transcription sessions.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs. Not available for transcription sessions.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection.\n */\n type?: 'server_vad' | 'semantic_vad';\n }\n }\n}\n\n/**\n * Returned when a transcription session is updated with a\n * `transcription_session.update` event, unless there is an error.\n */\nexport interface TranscriptionSessionUpdatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A new Realtime transcription session configuration.\n *\n * When a session is created on the server via REST API, the session object also\n * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n * not present when a session is updated via the WebSocket API.\n */\n session: TranscriptionSessionsAPI.TranscriptionSession;\n\n /**\n * The event type, must be `transcription_session.updated`.\n */\n type: 'transcription_session.updated';\n}\n\nRealtime.Sessions = Sessions;\nRealtime.TranscriptionSessions = TranscriptionSessions;\n\nexport declare namespace Realtime {\n export {\n type ConversationCreatedEvent as ConversationCreatedEvent,\n type ConversationItem as ConversationItem,\n type ConversationItemContent as ConversationItemContent,\n type ConversationItemCreateEvent as ConversationItemCreateEvent,\n type ConversationItemCreatedEvent as ConversationItemCreatedEvent,\n type ConversationItemDeleteEvent as ConversationItemDeleteEvent,\n type ConversationItemDeletedEvent as ConversationItemDeletedEvent,\n type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent,\n type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent,\n type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent,\n type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent,\n type ConversationItemTruncateEvent as ConversationItemTruncateEvent,\n type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent,\n type ConversationItemWithReference as ConversationItemWithReference,\n type ErrorEvent as ErrorEvent,\n type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent,\n type InputAudioBufferClearEvent as InputAudioBufferClearEvent,\n type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent,\n type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent,\n type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent,\n type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent,\n type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent,\n type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent,\n type RealtimeClientEvent as RealtimeClientEvent,\n type RealtimeResponse as RealtimeResponse,\n type RealtimeResponseStatus as RealtimeResponseStatus,\n type RealtimeResponseUsage as RealtimeResponseUsage,\n type RealtimeServerEvent as RealtimeServerEvent,\n type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n type ResponseCancelEvent as ResponseCancelEvent,\n type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n type ResponseCreateEvent as ResponseCreateEvent,\n type ResponseCreatedEvent as ResponseCreatedEvent,\n type ResponseDoneEvent as ResponseDoneEvent,\n type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n type ResponseTextDoneEvent as ResponseTextDoneEvent,\n type SessionCreatedEvent as SessionCreatedEvent,\n type SessionUpdateEvent as SessionUpdateEvent,\n type SessionUpdatedEvent as SessionUpdatedEvent,\n type TranscriptionSessionUpdate as TranscriptionSessionUpdate,\n type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent,\n };\n\n export {\n Sessions as Sessions,\n type SessionsAPISession as Session,\n type SessionCreateResponse as SessionCreateResponse,\n type SessionCreateParams as SessionCreateParams,\n };\n\n export {\n TranscriptionSessions as TranscriptionSessions,\n type TranscriptionSession as TranscriptionSession,\n type TranscriptionSessionCreateParams as TranscriptionSessionCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ThreadsAPI from './threads';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Sessions extends APIResource {\n /**\n * Create a ChatKit session.\n *\n * @example\n * ```ts\n * const chatSession =\n * await client.beta.chatkit.sessions.create({\n * user: 'x',\n * workflow: { id: 'id' },\n * });\n * ```\n */\n create(body: SessionCreateParams, options?: RequestOptions): APIPromise<ThreadsAPI.ChatSession> {\n return this._client.post('/chatkit/sessions', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n });\n }\n\n /**\n * Cancel an active ChatKit session and return its most recent metadata.\n *\n * Cancelling prevents new requests from using the issued client secret.\n *\n * @example\n * ```ts\n * const chatSession =\n * await client.beta.chatkit.sessions.cancel('cksess_123');\n * ```\n */\n cancel(sessionID: string, options?: RequestOptions): APIPromise<ThreadsAPI.ChatSession> {\n return this._client.post(path`/chatkit/sessions/${sessionID}/cancel`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n });\n }\n}\n\nexport interface SessionCreateParams {\n /**\n * A free-form string that identifies your end user; ensures this Session can\n * access other objects that have the same `user` scope.\n */\n user: string;\n\n /**\n * Workflow that powers the session.\n */\n workflow: ThreadsAPI.ChatSessionWorkflowParam;\n\n /**\n * Optional overrides for ChatKit runtime configuration features\n */\n chatkit_configuration?: ThreadsAPI.ChatSessionChatKitConfigurationParam;\n\n /**\n * Optional override for session expiration timing in seconds from creation.\n * Defaults to 10 minutes.\n */\n expires_after?: ThreadsAPI.ChatSessionExpiresAfterParam;\n\n /**\n * Optional override for per-minute request limits. When omitted, defaults to 10.\n */\n rate_limits?: ThreadsAPI.ChatSessionRateLimitsParam;\n}\n\nexport declare namespace Sessions {\n export { type SessionCreateParams as SessionCreateParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ChatKitAPI from './chatkit';\nimport { APIPromise } from '../../../core/api-promise';\nimport {\n ConversationCursorPage,\n type ConversationCursorPageParams,\n PagePromise,\n} from '../../../core/pagination';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Threads extends APIResource {\n /**\n * Retrieve a ChatKit thread by its identifier.\n *\n * @example\n * ```ts\n * const chatkitThread =\n * await client.beta.chatkit.threads.retrieve('cthr_123');\n * ```\n */\n retrieve(threadID: string, options?: RequestOptions): APIPromise<ChatKitThread> {\n return this._client.get(path`/chatkit/threads/${threadID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n });\n }\n\n /**\n * List ChatKit threads with optional pagination and user filters.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const chatkitThread of client.beta.chatkit.threads.list()) {\n * // ...\n * }\n * ```\n */\n list(\n query: ThreadListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<ChatKitThreadsPage, ChatKitThread> {\n return this._client.getAPIList('/chatkit/threads', ConversationCursorPage<ChatKitThread>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n });\n }\n\n /**\n * Delete a ChatKit thread along with its items and stored attachments.\n *\n * @example\n * ```ts\n * const thread = await client.beta.chatkit.threads.delete(\n * 'cthr_123',\n * );\n * ```\n */\n delete(threadID: string, options?: RequestOptions): APIPromise<ThreadDeleteResponse> {\n return this._client.delete(path`/chatkit/threads/${threadID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),\n });\n }\n\n /**\n * List items that belong to a ChatKit thread.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const thread of client.beta.chatkit.threads.listItems(\n * 'cthr_123',\n * )) {\n * // ...\n * }\n * ```\n */\n listItems(\n threadID: string,\n query: ThreadListItemsParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<\n ChatKitThreadItemListDataPage,\n | ChatKitThreadUserMessageItem\n | ChatKitThreadAssistantMessageItem\n | ChatKitWidgetItem\n | ChatKitThreadItemList.ChatKitClientToolCall\n | ChatKitThreadItemList.ChatKitTask\n | ChatKitThreadItemList.ChatKitTaskGroup\n > {\n return this._client.getAPIList(\n path`/chatkit/threads/${threadID}/items`,\n ConversationCursorPage<\n | ChatKitThreadUserMessageItem\n | ChatKitThreadAssistantMessageItem\n | ChatKitWidgetItem\n | ChatKitThreadItemList.ChatKitClientToolCall\n | ChatKitThreadItemList.ChatKitTask\n | ChatKitThreadItemList.ChatKitTaskGroup\n >,\n { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) },\n );\n }\n}\n\nexport type ChatKitThreadsPage = ConversationCursorPage<ChatKitThread>;\n\nexport type ChatKitThreadItemListDataPage = ConversationCursorPage<\n | ChatKitThreadUserMessageItem\n | ChatKitThreadAssistantMessageItem\n | ChatKitWidgetItem\n | ChatKitThreadItemList.ChatKitClientToolCall\n | ChatKitThreadItemList.ChatKitTask\n | ChatKitThreadItemList.ChatKitTaskGroup\n>;\n\n/**\n * Represents a ChatKit session and its resolved configuration.\n */\nexport interface ChatSession {\n /**\n * Identifier for the ChatKit session.\n */\n id: string;\n\n /**\n * Resolved ChatKit feature configuration for the session.\n */\n chatkit_configuration: ChatSessionChatKitConfiguration;\n\n /**\n * Ephemeral client secret that authenticates session requests.\n */\n client_secret: string;\n\n /**\n * Unix timestamp (in seconds) for when the session expires.\n */\n expires_at: number;\n\n /**\n * Convenience copy of the per-minute request limit.\n */\n max_requests_per_1_minute: number;\n\n /**\n * Type discriminator that is always `chatkit.session`.\n */\n object: 'chatkit.session';\n\n /**\n * Resolved rate limit values.\n */\n rate_limits: ChatSessionRateLimits;\n\n /**\n * Current lifecycle state of the session.\n */\n status: ChatSessionStatus;\n\n /**\n * User identifier associated with the session.\n */\n user: string;\n\n /**\n * Workflow metadata for the session.\n */\n workflow: ChatKitAPI.ChatKitWorkflow;\n}\n\n/**\n * Automatic thread title preferences for the session.\n */\nexport interface ChatSessionAutomaticThreadTitling {\n /**\n * Whether automatic thread titling is enabled.\n */\n enabled: boolean;\n}\n\n/**\n * ChatKit configuration for the session.\n */\nexport interface ChatSessionChatKitConfiguration {\n /**\n * Automatic thread titling preferences.\n */\n automatic_thread_titling: ChatSessionAutomaticThreadTitling;\n\n /**\n * Upload settings for the session.\n */\n file_upload: ChatSessionFileUpload;\n\n /**\n * History retention configuration.\n */\n history: ChatSessionHistory;\n}\n\n/**\n * Optional per-session configuration settings for ChatKit behavior.\n */\nexport interface ChatSessionChatKitConfigurationParam {\n /**\n * Configuration for automatic thread titling. When omitted, automatic thread\n * titling is enabled by default.\n */\n automatic_thread_titling?: ChatSessionChatKitConfigurationParam.AutomaticThreadTitling;\n\n /**\n * Configuration for upload enablement and limits. When omitted, uploads are\n * disabled by default (max_files 10, max_file_size 512 MB).\n */\n file_upload?: ChatSessionChatKitConfigurationParam.FileUpload;\n\n /**\n * Configuration for chat history retention. When omitted, history is enabled by\n * default with no limit on recent_threads (null).\n */\n history?: ChatSessionChatKitConfigurationParam.History;\n}\n\nexport namespace ChatSessionChatKitConfigurationParam {\n /**\n * Configuration for automatic thread titling. When omitted, automatic thread\n * titling is enabled by default.\n */\n export interface AutomaticThreadTitling {\n /**\n * Enable automatic thread title generation. Defaults to true.\n */\n enabled?: boolean;\n }\n\n /**\n * Configuration for upload enablement and limits. When omitted, uploads are\n * disabled by default (max_files 10, max_file_size 512 MB).\n */\n export interface FileUpload {\n /**\n * Enable uploads for this session. Defaults to false.\n */\n enabled?: boolean;\n\n /**\n * Maximum size in megabytes for each uploaded file. Defaults to 512 MB, which is\n * the maximum allowable size.\n */\n max_file_size?: number;\n\n /**\n * Maximum number of files that can be uploaded to the session. Defaults to 10.\n */\n max_files?: number;\n }\n\n /**\n * Configuration for chat history retention. When omitted, history is enabled by\n * default with no limit on recent_threads (null).\n */\n export interface History {\n /**\n * Enables chat users to access previous ChatKit threads. Defaults to true.\n */\n enabled?: boolean;\n\n /**\n * Number of recent ChatKit threads users have access to. Defaults to unlimited\n * when unset.\n */\n recent_threads?: number;\n }\n}\n\n/**\n * Controls when the session expires relative to an anchor timestamp.\n */\nexport interface ChatSessionExpiresAfterParam {\n /**\n * Base timestamp used to calculate expiration. Currently fixed to `created_at`.\n */\n anchor: 'created_at';\n\n /**\n * Number of seconds after the anchor when the session expires.\n */\n seconds: number;\n}\n\n/**\n * Upload permissions and limits applied to the session.\n */\nexport interface ChatSessionFileUpload {\n /**\n * Indicates if uploads are enabled for the session.\n */\n enabled: boolean;\n\n /**\n * Maximum upload size in megabytes.\n */\n max_file_size: number | null;\n\n /**\n * Maximum number of uploads allowed during the session.\n */\n max_files: number | null;\n}\n\n/**\n * History retention preferences returned for the session.\n */\nexport interface ChatSessionHistory {\n /**\n * Indicates if chat history is persisted for the session.\n */\n enabled: boolean;\n\n /**\n * Number of prior threads surfaced in history views. Defaults to null when all\n * history is retained.\n */\n recent_threads: number | null;\n}\n\n/**\n * Active per-minute request limit for the session.\n */\nexport interface ChatSessionRateLimits {\n /**\n * Maximum allowed requests per one-minute window.\n */\n max_requests_per_1_minute: number;\n}\n\n/**\n * Controls request rate limits for the session.\n */\nexport interface ChatSessionRateLimitsParam {\n /**\n * Maximum number of requests allowed per minute for the session. Defaults to 10.\n */\n max_requests_per_1_minute?: number;\n}\n\nexport type ChatSessionStatus = 'active' | 'expired' | 'cancelled';\n\n/**\n * Workflow reference and overrides applied to the chat session.\n */\nexport interface ChatSessionWorkflowParam {\n /**\n * Identifier for the workflow invoked by the session.\n */\n id: string;\n\n /**\n * State variables forwarded to the workflow. Keys may be up to 64 characters,\n * values must be primitive types, and the map defaults to an empty object.\n */\n state_variables?: { [key: string]: string | boolean | number };\n\n /**\n * Optional tracing overrides for the workflow invocation. When omitted, tracing is\n * enabled by default.\n */\n tracing?: ChatSessionWorkflowParam.Tracing;\n\n /**\n * Specific workflow version to run. Defaults to the latest deployed version.\n */\n version?: string;\n}\n\nexport namespace ChatSessionWorkflowParam {\n /**\n * Optional tracing overrides for the workflow invocation. When omitted, tracing is\n * enabled by default.\n */\n export interface Tracing {\n /**\n * Whether tracing is enabled during the session. Defaults to true.\n */\n enabled?: boolean;\n }\n}\n\n/**\n * Attachment metadata included on thread items.\n */\nexport interface ChatKitAttachment {\n /**\n * Identifier for the attachment.\n */\n id: string;\n\n /**\n * MIME type of the attachment.\n */\n mime_type: string;\n\n /**\n * Original display name for the attachment.\n */\n name: string;\n\n /**\n * Preview URL for rendering the attachment inline.\n */\n preview_url: string | null;\n\n /**\n * Attachment discriminator.\n */\n type: 'image' | 'file';\n}\n\n/**\n * Assistant response text accompanied by optional annotations.\n */\nexport interface ChatKitResponseOutputText {\n /**\n * Ordered list of annotations attached to the response text.\n */\n annotations: Array<ChatKitResponseOutputText.File | ChatKitResponseOutputText.URL>;\n\n /**\n * Assistant generated text.\n */\n text: string;\n\n /**\n * Type discriminator that is always `output_text`.\n */\n type: 'output_text';\n}\n\nexport namespace ChatKitResponseOutputText {\n /**\n * Annotation that references an uploaded file.\n */\n export interface File {\n /**\n * File attachment referenced by the annotation.\n */\n source: File.Source;\n\n /**\n * Type discriminator that is always `file` for this annotation.\n */\n type: 'file';\n }\n\n export namespace File {\n /**\n * File attachment referenced by the annotation.\n */\n export interface Source {\n /**\n * Filename referenced by the annotation.\n */\n filename: string;\n\n /**\n * Type discriminator that is always `file`.\n */\n type: 'file';\n }\n }\n\n /**\n * Annotation that references a URL.\n */\n export interface URL {\n /**\n * URL referenced by the annotation.\n */\n source: URL.Source;\n\n /**\n * Type discriminator that is always `url` for this annotation.\n */\n type: 'url';\n }\n\n export namespace URL {\n /**\n * URL referenced by the annotation.\n */\n export interface Source {\n /**\n * Type discriminator that is always `url`.\n */\n type: 'url';\n\n /**\n * URL referenced by the annotation.\n */\n url: string;\n }\n }\n}\n\n/**\n * Represents a ChatKit thread and its current status.\n */\nexport interface ChatKitThread {\n /**\n * Identifier of the thread.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) for when the thread was created.\n */\n created_at: number;\n\n /**\n * Type discriminator that is always `chatkit.thread`.\n */\n object: 'chatkit.thread';\n\n /**\n * Current status for the thread. Defaults to `active` for newly created threads.\n */\n status: ChatKitThread.Active | ChatKitThread.Locked | ChatKitThread.Closed;\n\n /**\n * Optional human-readable title for the thread. Defaults to null when no title has\n * been generated.\n */\n title: string | null;\n\n /**\n * Free-form string that identifies your end user who owns the thread.\n */\n user: string;\n}\n\nexport namespace ChatKitThread {\n /**\n * Indicates that a thread is active.\n */\n export interface Active {\n /**\n * Status discriminator that is always `active`.\n */\n type: 'active';\n }\n\n /**\n * Indicates that a thread is locked and cannot accept new input.\n */\n export interface Locked {\n /**\n * Reason that the thread was locked. Defaults to null when no reason is recorded.\n */\n reason: string | null;\n\n /**\n * Status discriminator that is always `locked`.\n */\n type: 'locked';\n }\n\n /**\n * Indicates that a thread has been closed.\n */\n export interface Closed {\n /**\n * Reason that the thread was closed. Defaults to null when no reason is recorded.\n */\n reason: string | null;\n\n /**\n * Status discriminator that is always `closed`.\n */\n type: 'closed';\n }\n}\n\n/**\n * Assistant-authored message within a thread.\n */\nexport interface ChatKitThreadAssistantMessageItem {\n /**\n * Identifier of the thread item.\n */\n id: string;\n\n /**\n * Ordered assistant response segments.\n */\n content: Array<ChatKitResponseOutputText>;\n\n /**\n * Unix timestamp (in seconds) for when the item was created.\n */\n created_at: number;\n\n /**\n * Type discriminator that is always `chatkit.thread_item`.\n */\n object: 'chatkit.thread_item';\n\n /**\n * Identifier of the parent thread.\n */\n thread_id: string;\n\n /**\n * Type discriminator that is always `chatkit.assistant_message`.\n */\n type: 'chatkit.assistant_message';\n}\n\n/**\n * A paginated list of thread items rendered for the ChatKit API.\n */\nexport interface ChatKitThreadItemList {\n /**\n * A list of items\n */\n data: Array<\n | ChatKitThreadUserMessageItem\n | ChatKitThreadAssistantMessageItem\n | ChatKitWidgetItem\n | ChatKitThreadItemList.ChatKitClientToolCall\n | ChatKitThreadItemList.ChatKitTask\n | ChatKitThreadItemList.ChatKitTaskGroup\n >;\n\n /**\n * The ID of the first item in the list.\n */\n first_id: string | null;\n\n /**\n * Whether there are more items available.\n */\n has_more: boolean;\n\n /**\n * The ID of the last item in the list.\n */\n last_id: string | null;\n\n /**\n * The type of object returned, must be `list`.\n */\n object: 'list';\n}\n\nexport namespace ChatKitThreadItemList {\n /**\n * Record of a client side tool invocation initiated by the assistant.\n */\n export interface ChatKitClientToolCall {\n /**\n * Identifier of the thread item.\n */\n id: string;\n\n /**\n * JSON-encoded arguments that were sent to the tool.\n */\n arguments: string;\n\n /**\n * Identifier for the client tool call.\n */\n call_id: string;\n\n /**\n * Unix timestamp (in seconds) for when the item was created.\n */\n created_at: number;\n\n /**\n * Tool name that was invoked.\n */\n name: string;\n\n /**\n * Type discriminator that is always `chatkit.thread_item`.\n */\n object: 'chatkit.thread_item';\n\n /**\n * JSON-encoded output captured from the tool. Defaults to null while execution is\n * in progress.\n */\n output: string | null;\n\n /**\n * Execution status for the tool call.\n */\n status: 'in_progress' | 'completed';\n\n /**\n * Identifier of the parent thread.\n */\n thread_id: string;\n\n /**\n * Type discriminator that is always `chatkit.client_tool_call`.\n */\n type: 'chatkit.client_tool_call';\n }\n\n /**\n * Task emitted by the workflow to show progress and status updates.\n */\n export interface ChatKitTask {\n /**\n * Identifier of the thread item.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) for when the item was created.\n */\n created_at: number;\n\n /**\n * Optional heading for the task. Defaults to null when not provided.\n */\n heading: string | null;\n\n /**\n * Type discriminator that is always `chatkit.thread_item`.\n */\n object: 'chatkit.thread_item';\n\n /**\n * Optional summary that describes the task. Defaults to null when omitted.\n */\n summary: string | null;\n\n /**\n * Subtype for the task.\n */\n task_type: 'custom' | 'thought';\n\n /**\n * Identifier of the parent thread.\n */\n thread_id: string;\n\n /**\n * Type discriminator that is always `chatkit.task`.\n */\n type: 'chatkit.task';\n }\n\n /**\n * Collection of workflow tasks grouped together in the thread.\n */\n export interface ChatKitTaskGroup {\n /**\n * Identifier of the thread item.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) for when the item was created.\n */\n created_at: number;\n\n /**\n * Type discriminator that is always `chatkit.thread_item`.\n */\n object: 'chatkit.thread_item';\n\n /**\n * Tasks included in the group.\n */\n tasks: Array<ChatKitTaskGroup.Task>;\n\n /**\n * Identifier of the parent thread.\n */\n thread_id: string;\n\n /**\n * Type discriminator that is always `chatkit.task_group`.\n */\n type: 'chatkit.task_group';\n }\n\n export namespace ChatKitTaskGroup {\n /**\n * Task entry that appears within a TaskGroup.\n */\n export interface Task {\n /**\n * Optional heading for the grouped task. Defaults to null when not provided.\n */\n heading: string | null;\n\n /**\n * Optional summary that describes the grouped task. Defaults to null when omitted.\n */\n summary: string | null;\n\n /**\n * Subtype for the grouped task.\n */\n type: 'custom' | 'thought';\n }\n }\n}\n\n/**\n * User-authored messages within a thread.\n */\nexport interface ChatKitThreadUserMessageItem {\n /**\n * Identifier of the thread item.\n */\n id: string;\n\n /**\n * Attachments associated with the user message. Defaults to an empty list.\n */\n attachments: Array<ChatKitAttachment>;\n\n /**\n * Ordered content elements supplied by the user.\n */\n content: Array<ChatKitThreadUserMessageItem.InputText | ChatKitThreadUserMessageItem.QuotedText>;\n\n /**\n * Unix timestamp (in seconds) for when the item was created.\n */\n created_at: number;\n\n /**\n * Inference overrides applied to the message. Defaults to null when unset.\n */\n inference_options: ChatKitThreadUserMessageItem.InferenceOptions | null;\n\n /**\n * Type discriminator that is always `chatkit.thread_item`.\n */\n object: 'chatkit.thread_item';\n\n /**\n * Identifier of the parent thread.\n */\n thread_id: string;\n\n type: 'chatkit.user_message';\n}\n\nexport namespace ChatKitThreadUserMessageItem {\n /**\n * Text block that a user contributed to the thread.\n */\n export interface InputText {\n /**\n * Plain-text content supplied by the user.\n */\n text: string;\n\n /**\n * Type discriminator that is always `input_text`.\n */\n type: 'input_text';\n }\n\n /**\n * Quoted snippet that the user referenced in their message.\n */\n export interface QuotedText {\n /**\n * Quoted text content.\n */\n text: string;\n\n /**\n * Type discriminator that is always `quoted_text`.\n */\n type: 'quoted_text';\n }\n\n /**\n * Inference overrides applied to the message. Defaults to null when unset.\n */\n export interface InferenceOptions {\n /**\n * Model name that generated the response. Defaults to null when using the session\n * default.\n */\n model: string | null;\n\n /**\n * Preferred tool to invoke. Defaults to null when ChatKit should auto-select.\n */\n tool_choice: InferenceOptions.ToolChoice | null;\n }\n\n export namespace InferenceOptions {\n /**\n * Preferred tool to invoke. Defaults to null when ChatKit should auto-select.\n */\n export interface ToolChoice {\n /**\n * Identifier of the requested tool.\n */\n id: string;\n }\n }\n}\n\n/**\n * Thread item that renders a widget payload.\n */\nexport interface ChatKitWidgetItem {\n /**\n * Identifier of the thread item.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) for when the item was created.\n */\n created_at: number;\n\n /**\n * Type discriminator that is always `chatkit.thread_item`.\n */\n object: 'chatkit.thread_item';\n\n /**\n * Identifier of the parent thread.\n */\n thread_id: string;\n\n /**\n * Type discriminator that is always `chatkit.widget`.\n */\n type: 'chatkit.widget';\n\n /**\n * Serialized widget payload rendered in the UI.\n */\n widget: string;\n}\n\n/**\n * Confirmation payload returned after deleting a thread.\n */\nexport interface ThreadDeleteResponse {\n /**\n * Identifier of the deleted thread.\n */\n id: string;\n\n /**\n * Indicates that the thread has been deleted.\n */\n deleted: boolean;\n\n /**\n * Type discriminator that is always `chatkit.thread.deleted`.\n */\n object: 'chatkit.thread.deleted';\n}\n\nexport interface ThreadListParams extends ConversationCursorPageParams {\n /**\n * List items created before this thread item ID. Defaults to null for the newest\n * results.\n */\n before?: string;\n\n /**\n * Sort order for results by creation time. Defaults to `desc`.\n */\n order?: 'asc' | 'desc';\n\n /**\n * Filter threads that belong to this user identifier. Defaults to null to return\n * all users.\n */\n user?: string;\n}\n\nexport interface ThreadListItemsParams extends ConversationCursorPageParams {\n /**\n * List items created before this thread item ID. Defaults to null for the newest\n * results.\n */\n before?: string;\n\n /**\n * Sort order for results by creation time. Defaults to `desc`.\n */\n order?: 'asc' | 'desc';\n}\n\nexport declare namespace Threads {\n export {\n type ChatSession as ChatSession,\n type ChatSessionAutomaticThreadTitling as ChatSessionAutomaticThreadTitling,\n type ChatSessionChatKitConfiguration as ChatSessionChatKitConfiguration,\n type ChatSessionChatKitConfigurationParam as ChatSessionChatKitConfigurationParam,\n type ChatSessionExpiresAfterParam as ChatSessionExpiresAfterParam,\n type ChatSessionFileUpload as ChatSessionFileUpload,\n type ChatSessionHistory as ChatSessionHistory,\n type ChatSessionRateLimits as ChatSessionRateLimits,\n type ChatSessionRateLimitsParam as ChatSessionRateLimitsParam,\n type ChatSessionStatus as ChatSessionStatus,\n type ChatSessionWorkflowParam as ChatSessionWorkflowParam,\n type ChatKitAttachment as ChatKitAttachment,\n type ChatKitResponseOutputText as ChatKitResponseOutputText,\n type ChatKitThread as ChatKitThread,\n type ChatKitThreadAssistantMessageItem as ChatKitThreadAssistantMessageItem,\n type ChatKitThreadItemList as ChatKitThreadItemList,\n type ChatKitThreadUserMessageItem as ChatKitThreadUserMessageItem,\n type ChatKitWidgetItem as ChatKitWidgetItem,\n type ThreadDeleteResponse as ThreadDeleteResponse,\n type ChatKitThreadsPage as ChatKitThreadsPage,\n type ChatKitThreadItemListDataPage as ChatKitThreadItemListDataPage,\n type ThreadListParams as ThreadListParams,\n type ThreadListItemsParams as ThreadListItemsParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as SessionsAPI from './sessions';\nimport { SessionCreateParams, Sessions } from './sessions';\nimport * as ThreadsAPI from './threads';\nimport {\n ChatKitAttachment,\n ChatKitResponseOutputText,\n ChatKitThread,\n ChatKitThreadAssistantMessageItem,\n ChatKitThreadItemList,\n ChatKitThreadItemListDataPage,\n ChatKitThreadUserMessageItem,\n ChatKitThreadsPage,\n ChatKitWidgetItem,\n ChatSession,\n ChatSessionAutomaticThreadTitling,\n ChatSessionChatKitConfiguration,\n ChatSessionChatKitConfigurationParam,\n ChatSessionExpiresAfterParam,\n ChatSessionFileUpload,\n ChatSessionHistory,\n ChatSessionRateLimits,\n ChatSessionRateLimitsParam,\n ChatSessionStatus,\n ChatSessionWorkflowParam,\n ThreadDeleteResponse,\n ThreadListItemsParams,\n ThreadListParams,\n Threads,\n} from './threads';\n\nexport class ChatKit extends APIResource {\n sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);\n threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);\n}\n\n/**\n * Workflow metadata and state returned for the session.\n */\nexport interface ChatKitWorkflow {\n /**\n * Identifier of the workflow backing the session.\n */\n id: string;\n\n /**\n * State variable key-value pairs applied when invoking the workflow. Defaults to\n * null when no overrides were provided.\n */\n state_variables: { [key: string]: string | boolean | number } | null;\n\n /**\n * Tracing settings applied to the workflow.\n */\n tracing: ChatKitWorkflow.Tracing;\n\n /**\n * Specific workflow version used for the session. Defaults to null when using the\n * latest deployment.\n */\n version: string | null;\n}\n\nexport namespace ChatKitWorkflow {\n /**\n * Tracing settings applied to the workflow.\n */\n export interface Tracing {\n /**\n * Indicates whether tracing is enabled.\n */\n enabled: boolean;\n }\n}\n\nChatKit.Sessions = Sessions;\nChatKit.Threads = Threads;\n\nexport declare namespace ChatKit {\n export { type ChatKitWorkflow as ChatKitWorkflow };\n\n export { Sessions as Sessions, type SessionCreateParams as SessionCreateParams };\n\n export {\n Threads as Threads,\n type ChatSession as ChatSession,\n type ChatSessionAutomaticThreadTitling as ChatSessionAutomaticThreadTitling,\n type ChatSessionChatKitConfiguration as ChatSessionChatKitConfiguration,\n type ChatSessionChatKitConfigurationParam as ChatSessionChatKitConfigurationParam,\n type ChatSessionExpiresAfterParam as ChatSessionExpiresAfterParam,\n type ChatSessionFileUpload as ChatSessionFileUpload,\n type ChatSessionHistory as ChatSessionHistory,\n type ChatSessionRateLimits as ChatSessionRateLimits,\n type ChatSessionRateLimitsParam as ChatSessionRateLimitsParam,\n type ChatSessionStatus as ChatSessionStatus,\n type ChatSessionWorkflowParam as ChatSessionWorkflowParam,\n type ChatKitAttachment as ChatKitAttachment,\n type ChatKitResponseOutputText as ChatKitResponseOutputText,\n type ChatKitThread as ChatKitThread,\n type ChatKitThreadAssistantMessageItem as ChatKitThreadAssistantMessageItem,\n type ChatKitThreadItemList as ChatKitThreadItemList,\n type ChatKitThreadUserMessageItem as ChatKitThreadUserMessageItem,\n type ChatKitWidgetItem as ChatKitWidgetItem,\n type ThreadDeleteResponse as ThreadDeleteResponse,\n type ChatKitThreadsPage as ChatKitThreadsPage,\n type ChatKitThreadItemListDataPage as ChatKitThreadItemListDataPage,\n type ThreadListParams as ThreadListParams,\n type ThreadListItemsParams as ThreadListItemsParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as Shared from '../../shared';\nimport * as AssistantsAPI from '../assistants';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Messages extends APIResource {\n /**\n * Create a message.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n create(threadID: string, body: MessageCreateParams, options?: RequestOptions): APIPromise<Message> {\n return this._client.post(path`/threads/${threadID}/messages`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Retrieve a message.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n retrieve(messageID: string, params: MessageRetrieveParams, options?: RequestOptions): APIPromise<Message> {\n const { thread_id } = params;\n return this._client.get(path`/threads/${thread_id}/messages/${messageID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Modifies a message.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n update(messageID: string, params: MessageUpdateParams, options?: RequestOptions): APIPromise<Message> {\n const { thread_id, ...body } = params;\n return this._client.post(path`/threads/${thread_id}/messages/${messageID}`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Returns a list of messages for a given thread.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n list(\n threadID: string,\n query: MessageListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<MessagesPage, Message> {\n return this._client.getAPIList(path`/threads/${threadID}/messages`, CursorPage<Message>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Deletes a message.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n delete(\n messageID: string,\n params: MessageDeleteParams,\n options?: RequestOptions,\n ): APIPromise<MessageDeleted> {\n const { thread_id } = params;\n return this._client.delete(path`/threads/${thread_id}/messages/${messageID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n}\n\nexport type MessagesPage = CursorPage<Message>;\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport type Annotation = FileCitationAnnotation | FilePathAnnotation;\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport type AnnotationDelta = FileCitationDeltaAnnotation | FilePathDeltaAnnotation;\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport interface FileCitationAnnotation {\n end_index: number;\n\n file_citation: FileCitationAnnotation.FileCitation;\n\n start_index: number;\n\n /**\n * The text in the message content that needs to be replaced.\n */\n text: string;\n\n /**\n * Always `file_citation`.\n */\n type: 'file_citation';\n}\n\nexport namespace FileCitationAnnotation {\n export interface FileCitation {\n /**\n * The ID of the specific File the citation is from.\n */\n file_id: string;\n }\n}\n\n/**\n * A citation within the message that points to a specific quote from a specific\n * File associated with the assistant or the message. Generated when the assistant\n * uses the \"file_search\" tool to search files.\n */\nexport interface FileCitationDeltaAnnotation {\n /**\n * The index of the annotation in the text content part.\n */\n index: number;\n\n /**\n * Always `file_citation`.\n */\n type: 'file_citation';\n\n end_index?: number;\n\n file_citation?: FileCitationDeltaAnnotation.FileCitation;\n\n start_index?: number;\n\n /**\n * The text in the message content that needs to be replaced.\n */\n text?: string;\n}\n\nexport namespace FileCitationDeltaAnnotation {\n export interface FileCitation {\n /**\n * The ID of the specific File the citation is from.\n */\n file_id?: string;\n\n /**\n * The specific quote in the file.\n */\n quote?: string;\n }\n}\n\n/**\n * A URL for the file that's generated when the assistant used the\n * `code_interpreter` tool to generate a file.\n */\nexport interface FilePathAnnotation {\n end_index: number;\n\n file_path: FilePathAnnotation.FilePath;\n\n start_index: number;\n\n /**\n * The text in the message content that needs to be replaced.\n */\n text: string;\n\n /**\n * Always `file_path`.\n */\n type: 'file_path';\n}\n\nexport namespace FilePathAnnotation {\n export interface FilePath {\n /**\n * The ID of the file that was generated.\n */\n file_id: string;\n }\n}\n\n/**\n * A URL for the file that's generated when the assistant used the\n * `code_interpreter` tool to generate a file.\n */\nexport interface FilePathDeltaAnnotation {\n /**\n * The index of the annotation in the text content part.\n */\n index: number;\n\n /**\n * Always `file_path`.\n */\n type: 'file_path';\n\n end_index?: number;\n\n file_path?: FilePathDeltaAnnotation.FilePath;\n\n start_index?: number;\n\n /**\n * The text in the message content that needs to be replaced.\n */\n text?: string;\n}\n\nexport namespace FilePathDeltaAnnotation {\n export interface FilePath {\n /**\n * The ID of the file that was generated.\n */\n file_id?: string;\n }\n}\n\nexport interface ImageFile {\n /**\n * The [File](https://platform.openai.com/docs/api-reference/files) ID of the image\n * in the message content. Set `purpose=\"vision\"` when uploading the File if you\n * need to later display the file content.\n */\n file_id: string;\n\n /**\n * Specifies the detail level of the image if specified by the user. `low` uses\n * fewer tokens, you can opt in to high resolution using `high`.\n */\n detail?: 'auto' | 'low' | 'high';\n}\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport interface ImageFileContentBlock {\n image_file: ImageFile;\n\n /**\n * Always `image_file`.\n */\n type: 'image_file';\n}\n\nexport interface ImageFileDelta {\n /**\n * Specifies the detail level of the image if specified by the user. `low` uses\n * fewer tokens, you can opt in to high resolution using `high`.\n */\n detail?: 'auto' | 'low' | 'high';\n\n /**\n * The [File](https://platform.openai.com/docs/api-reference/files) ID of the image\n * in the message content. Set `purpose=\"vision\"` when uploading the File if you\n * need to later display the file content.\n */\n file_id?: string;\n}\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport interface ImageFileDeltaBlock {\n /**\n * The index of the content part in the message.\n */\n index: number;\n\n /**\n * Always `image_file`.\n */\n type: 'image_file';\n\n image_file?: ImageFileDelta;\n}\n\nexport interface ImageURL {\n /**\n * The external URL of the image, must be a supported image types: jpeg, jpg, png,\n * gif, webp.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. `low` uses fewer tokens, you can opt in\n * to high resolution using `high`. Default value is `auto`\n */\n detail?: 'auto' | 'low' | 'high';\n}\n\n/**\n * References an image URL in the content of a message.\n */\nexport interface ImageURLContentBlock {\n image_url: ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport interface ImageURLDelta {\n /**\n * Specifies the detail level of the image. `low` uses fewer tokens, you can opt in\n * to high resolution using `high`.\n */\n detail?: 'auto' | 'low' | 'high';\n\n /**\n * The URL of the image, must be a supported image types: jpeg, jpg, png, gif,\n * webp.\n */\n url?: string;\n}\n\n/**\n * References an image URL in the content of a message.\n */\nexport interface ImageURLDeltaBlock {\n /**\n * The index of the content part in the message.\n */\n index: number;\n\n /**\n * Always `image_url`.\n */\n type: 'image_url';\n\n image_url?: ImageURLDelta;\n}\n\n/**\n * Represents a message within a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\nexport interface Message {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * If applicable, the ID of the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) that\n * authored this message.\n */\n assistant_id: string | null;\n\n /**\n * A list of files attached to the message, and the tools they were added to.\n */\n attachments: Array<Message.Attachment> | null;\n\n /**\n * The Unix timestamp (in seconds) for when the message was completed.\n */\n completed_at: number | null;\n\n /**\n * The content of the message in array of text and/or images.\n */\n content: Array<MessageContent>;\n\n /**\n * The Unix timestamp (in seconds) for when the message was created.\n */\n created_at: number;\n\n /**\n * The Unix timestamp (in seconds) for when the message was marked as incomplete.\n */\n incomplete_at: number | null;\n\n /**\n * On an incomplete message, details about why the message is incomplete.\n */\n incomplete_details: Message.IncompleteDetails | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The object type, which is always `thread.message`.\n */\n object: 'thread.message';\n\n /**\n * The entity that produced the message. One of `user` or `assistant`.\n */\n role: 'user' | 'assistant';\n\n /**\n * The ID of the [run](https://platform.openai.com/docs/api-reference/runs)\n * associated with the creation of this message. Value is `null` when messages are\n * created manually using the create message or create thread endpoints.\n */\n run_id: string | null;\n\n /**\n * The status of the message, which can be either `in_progress`, `incomplete`, or\n * `completed`.\n */\n status: 'in_progress' | 'incomplete' | 'completed';\n\n /**\n * The [thread](https://platform.openai.com/docs/api-reference/threads) ID that\n * this message belongs to.\n */\n thread_id: string;\n}\n\nexport namespace Message {\n export interface Attachment {\n /**\n * The ID of the file to attach to the message.\n */\n file_id?: string;\n\n /**\n * The tools to add this file to.\n */\n tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.AssistantToolsFileSearchTypeOnly>;\n }\n\n export namespace Attachment {\n export interface AssistantToolsFileSearchTypeOnly {\n /**\n * The type of tool being defined: `file_search`\n */\n type: 'file_search';\n }\n }\n\n /**\n * On an incomplete message, details about why the message is incomplete.\n */\n export interface IncompleteDetails {\n /**\n * The reason the message is incomplete.\n */\n reason: 'content_filter' | 'max_tokens' | 'run_cancelled' | 'run_expired' | 'run_failed';\n }\n}\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport type MessageContent =\n | ImageFileContentBlock\n | ImageURLContentBlock\n | TextContentBlock\n | RefusalContentBlock;\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport type MessageContentDelta =\n | ImageFileDeltaBlock\n | TextDeltaBlock\n | RefusalDeltaBlock\n | ImageURLDeltaBlock;\n\n/**\n * References an image [File](https://platform.openai.com/docs/api-reference/files)\n * in the content of a message.\n */\nexport type MessageContentPartParam = ImageFileContentBlock | ImageURLContentBlock | TextContentBlockParam;\n\nexport interface MessageDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'thread.message.deleted';\n}\n\n/**\n * The delta containing the fields that have changed on the Message.\n */\nexport interface MessageDelta {\n /**\n * The content of the message in array of text and/or images.\n */\n content?: Array<MessageContentDelta>;\n\n /**\n * The entity that produced the message. One of `user` or `assistant`.\n */\n role?: 'user' | 'assistant';\n}\n\n/**\n * Represents a message delta i.e. any changed fields on a message during\n * streaming.\n */\nexport interface MessageDeltaEvent {\n /**\n * The identifier of the message, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The delta containing the fields that have changed on the Message.\n */\n delta: MessageDelta;\n\n /**\n * The object type, which is always `thread.message.delta`.\n */\n object: 'thread.message.delta';\n}\n\n/**\n * The refusal content generated by the assistant.\n */\nexport interface RefusalContentBlock {\n refusal: string;\n\n /**\n * Always `refusal`.\n */\n type: 'refusal';\n}\n\n/**\n * The refusal content that is part of a message.\n */\nexport interface RefusalDeltaBlock {\n /**\n * The index of the refusal part in the message.\n */\n index: number;\n\n /**\n * Always `refusal`.\n */\n type: 'refusal';\n\n refusal?: string;\n}\n\nexport interface Text {\n annotations: Array<Annotation>;\n\n /**\n * The data that makes up the text.\n */\n value: string;\n}\n\n/**\n * The text content that is part of a message.\n */\nexport interface TextContentBlock {\n text: Text;\n\n /**\n * Always `text`.\n */\n type: 'text';\n}\n\n/**\n * The text content that is part of a message.\n */\nexport interface TextContentBlockParam {\n /**\n * Text content to be sent to the model\n */\n text: string;\n\n /**\n * Always `text`.\n */\n type: 'text';\n}\n\nexport interface TextDelta {\n annotations?: Array<AnnotationDelta>;\n\n /**\n * The data that makes up the text.\n */\n value?: string;\n}\n\n/**\n * The text content that is part of a message.\n */\nexport interface TextDeltaBlock {\n /**\n * The index of the content part in the message.\n */\n index: number;\n\n /**\n * Always `text`.\n */\n type: 'text';\n\n text?: TextDelta;\n}\n\nexport interface MessageCreateParams {\n /**\n * The text contents of the message.\n */\n content: string | Array<MessageContentPartParam>;\n\n /**\n * The role of the entity that is creating the message. Allowed values include:\n *\n * - `user`: Indicates the message is sent by an actual user and should be used in\n * most cases to represent user-generated messages.\n * - `assistant`: Indicates the message is generated by the assistant. Use this\n * value to insert messages from the assistant into the conversation.\n */\n role: 'user' | 'assistant';\n\n /**\n * A list of files attached to the message, and the tools they should be added to.\n */\n attachments?: Array<MessageCreateParams.Attachment> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n}\n\nexport namespace MessageCreateParams {\n export interface Attachment {\n /**\n * The ID of the file to attach to the message.\n */\n file_id?: string;\n\n /**\n * The tools to add this file to.\n */\n tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n }\n\n export namespace Attachment {\n export interface FileSearch {\n /**\n * The type of tool being defined: `file_search`\n */\n type: 'file_search';\n }\n }\n}\n\nexport interface MessageRetrieveParams {\n /**\n * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n * to which this message belongs.\n */\n thread_id: string;\n}\n\nexport interface MessageUpdateParams {\n /**\n * Path param: The ID of the thread to which this message belongs.\n */\n thread_id: string;\n\n /**\n * Body param: Set of 16 key-value pairs that can be attached to an object. This\n * can be useful for storing additional information about the object in a\n * structured format, and querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n}\n\nexport interface MessageListParams extends CursorPageParams {\n /**\n * A cursor for use in pagination. `before` is an object ID that defines your place\n * in the list. For instance, if you make a list request and receive 100 objects,\n * starting with obj_foo, your subsequent call can include before=obj_foo in order\n * to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n\n /**\n * Filter messages by the run ID that generated them.\n */\n run_id?: string;\n}\n\nexport interface MessageDeleteParams {\n /**\n * The ID of the thread to which this message belongs.\n */\n thread_id: string;\n}\n\nexport declare namespace Messages {\n export {\n type Annotation as Annotation,\n type AnnotationDelta as AnnotationDelta,\n type FileCitationAnnotation as FileCitationAnnotation,\n type FileCitationDeltaAnnotation as FileCitationDeltaAnnotation,\n type FilePathAnnotation as FilePathAnnotation,\n type FilePathDeltaAnnotation as FilePathDeltaAnnotation,\n type ImageFile as ImageFile,\n type ImageFileContentBlock as ImageFileContentBlock,\n type ImageFileDelta as ImageFileDelta,\n type ImageFileDeltaBlock as ImageFileDeltaBlock,\n type ImageURL as ImageURL,\n type ImageURLContentBlock as ImageURLContentBlock,\n type ImageURLDelta as ImageURLDelta,\n type ImageURLDeltaBlock as ImageURLDeltaBlock,\n type Message as Message,\n type MessageContent as MessageContent,\n type MessageContentDelta as MessageContentDelta,\n type MessageContentPartParam as MessageContentPartParam,\n type MessageDeleted as MessageDeleted,\n type MessageDelta as MessageDelta,\n type MessageDeltaEvent as MessageDeltaEvent,\n type RefusalContentBlock as RefusalContentBlock,\n type RefusalDeltaBlock as RefusalDeltaBlock,\n type Text as Text,\n type TextContentBlock as TextContentBlock,\n type TextContentBlockParam as TextContentBlockParam,\n type TextDelta as TextDelta,\n type TextDeltaBlock as TextDeltaBlock,\n type MessagesPage as MessagesPage,\n type MessageCreateParams as MessageCreateParams,\n type MessageRetrieveParams as MessageRetrieveParams,\n type MessageUpdateParams as MessageUpdateParams,\n type MessageListParams as MessageListParams,\n type MessageDeleteParams as MessageDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../../core/resource';\nimport * as StepsAPI from './steps';\nimport * as Shared from '../../../shared';\nimport { APIPromise } from '../../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../../core/pagination';\nimport { buildHeaders } from '../../../../internal/headers';\nimport { RequestOptions } from '../../../../internal/request-options';\nimport { path } from '../../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Steps extends APIResource {\n /**\n * Retrieves a run step.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n retrieve(stepID: string, params: StepRetrieveParams, options?: RequestOptions): APIPromise<RunStep> {\n const { thread_id, run_id, ...query } = params;\n return this._client.get(path`/threads/${thread_id}/runs/${run_id}/steps/${stepID}`, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Returns a list of run steps belonging to a run.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n list(runID: string, params: StepListParams, options?: RequestOptions): PagePromise<RunStepsPage, RunStep> {\n const { thread_id, ...query } = params;\n return this._client.getAPIList(path`/threads/${thread_id}/runs/${runID}/steps`, CursorPage<RunStep>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n}\n\nexport type RunStepsPage = CursorPage<RunStep>;\n\n/**\n * Text output from the Code Interpreter tool call as part of a run step.\n */\nexport interface CodeInterpreterLogs {\n /**\n * The index of the output in the outputs array.\n */\n index: number;\n\n /**\n * Always `logs`.\n */\n type: 'logs';\n\n /**\n * The text output from the Code Interpreter tool call.\n */\n logs?: string;\n}\n\nexport interface CodeInterpreterOutputImage {\n /**\n * The index of the output in the outputs array.\n */\n index: number;\n\n /**\n * Always `image`.\n */\n type: 'image';\n\n image?: CodeInterpreterOutputImage.Image;\n}\n\nexport namespace CodeInterpreterOutputImage {\n export interface Image {\n /**\n * The [file](https://platform.openai.com/docs/api-reference/files) ID of the\n * image.\n */\n file_id?: string;\n }\n}\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport interface CodeInterpreterToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The Code Interpreter tool call definition.\n */\n code_interpreter: CodeInterpreterToolCall.CodeInterpreter;\n\n /**\n * The type of tool call. This is always going to be `code_interpreter` for this\n * type of tool call.\n */\n type: 'code_interpreter';\n}\n\nexport namespace CodeInterpreterToolCall {\n /**\n * The Code Interpreter tool call definition.\n */\n export interface CodeInterpreter {\n /**\n * The input to the Code Interpreter tool call.\n */\n input: string;\n\n /**\n * The outputs from the Code Interpreter tool call. Code Interpreter can output one\n * or more items, including text (`logs`) or images (`image`). Each of these are\n * represented by a different object type.\n */\n outputs: Array<CodeInterpreter.Logs | CodeInterpreter.Image>;\n }\n\n export namespace CodeInterpreter {\n /**\n * Text output from the Code Interpreter tool call as part of a run step.\n */\n export interface Logs {\n /**\n * The text output from the Code Interpreter tool call.\n */\n logs: string;\n\n /**\n * Always `logs`.\n */\n type: 'logs';\n }\n\n export interface Image {\n image: Image.Image;\n\n /**\n * Always `image`.\n */\n type: 'image';\n }\n\n export namespace Image {\n export interface Image {\n /**\n * The [file](https://platform.openai.com/docs/api-reference/files) ID of the\n * image.\n */\n file_id: string;\n }\n }\n }\n}\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport interface CodeInterpreterToolCallDelta {\n /**\n * The index of the tool call in the tool calls array.\n */\n index: number;\n\n /**\n * The type of tool call. This is always going to be `code_interpreter` for this\n * type of tool call.\n */\n type: 'code_interpreter';\n\n /**\n * The ID of the tool call.\n */\n id?: string;\n\n /**\n * The Code Interpreter tool call definition.\n */\n code_interpreter?: CodeInterpreterToolCallDelta.CodeInterpreter;\n}\n\nexport namespace CodeInterpreterToolCallDelta {\n /**\n * The Code Interpreter tool call definition.\n */\n export interface CodeInterpreter {\n /**\n * The input to the Code Interpreter tool call.\n */\n input?: string;\n\n /**\n * The outputs from the Code Interpreter tool call. Code Interpreter can output one\n * or more items, including text (`logs`) or images (`image`). Each of these are\n * represented by a different object type.\n */\n outputs?: Array<StepsAPI.CodeInterpreterLogs | StepsAPI.CodeInterpreterOutputImage>;\n }\n}\n\nexport interface FileSearchToolCall {\n /**\n * The ID of the tool call object.\n */\n id: string;\n\n /**\n * For now, this is always going to be an empty object.\n */\n file_search: FileSearchToolCall.FileSearch;\n\n /**\n * The type of tool call. This is always going to be `file_search` for this type of\n * tool call.\n */\n type: 'file_search';\n}\n\nexport namespace FileSearchToolCall {\n /**\n * For now, this is always going to be an empty object.\n */\n export interface FileSearch {\n /**\n * The ranking options for the file search.\n */\n ranking_options?: FileSearch.RankingOptions;\n\n /**\n * The results of the file search.\n */\n results?: Array<FileSearch.Result>;\n }\n\n export namespace FileSearch {\n /**\n * The ranking options for the file search.\n */\n export interface RankingOptions {\n /**\n * The ranker to use for the file search. If not specified will use the `auto`\n * ranker.\n */\n ranker: 'auto' | 'default_2024_08_21';\n\n /**\n * The score threshold for the file search. All values must be a floating point\n * number between 0 and 1.\n */\n score_threshold: number;\n }\n\n /**\n * A result instance of the file search.\n */\n export interface Result {\n /**\n * The ID of the file that result was found in.\n */\n file_id: string;\n\n /**\n * The name of the file that result was found in.\n */\n file_name: string;\n\n /**\n * The score of the result. All values must be a floating point number between 0\n * and 1.\n */\n score: number;\n\n /**\n * The content of the result that was found. The content is only included if\n * requested via the include query parameter.\n */\n content?: Array<Result.Content>;\n }\n\n export namespace Result {\n export interface Content {\n /**\n * The text content of the file.\n */\n text?: string;\n\n /**\n * The type of the content.\n */\n type?: 'text';\n }\n }\n }\n}\n\nexport interface FileSearchToolCallDelta {\n /**\n * For now, this is always going to be an empty object.\n */\n file_search: unknown;\n\n /**\n * The index of the tool call in the tool calls array.\n */\n index: number;\n\n /**\n * The type of tool call. This is always going to be `file_search` for this type of\n * tool call.\n */\n type: 'file_search';\n\n /**\n * The ID of the tool call object.\n */\n id?: string;\n}\n\nexport interface FunctionToolCall {\n /**\n * The ID of the tool call object.\n */\n id: string;\n\n /**\n * The definition of the function that was called.\n */\n function: FunctionToolCall.Function;\n\n /**\n * The type of tool call. This is always going to be `function` for this type of\n * tool call.\n */\n type: 'function';\n}\n\nexport namespace FunctionToolCall {\n /**\n * The definition of the function that was called.\n */\n export interface Function {\n /**\n * The arguments passed to the function.\n */\n arguments: string;\n\n /**\n * The name of the function.\n */\n name: string;\n\n /**\n * The output of the function. This will be `null` if the outputs have not been\n * [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)\n * yet.\n */\n output: string | null;\n }\n}\n\nexport interface FunctionToolCallDelta {\n /**\n * The index of the tool call in the tool calls array.\n */\n index: number;\n\n /**\n * The type of tool call. This is always going to be `function` for this type of\n * tool call.\n */\n type: 'function';\n\n /**\n * The ID of the tool call object.\n */\n id?: string;\n\n /**\n * The definition of the function that was called.\n */\n function?: FunctionToolCallDelta.Function;\n}\n\nexport namespace FunctionToolCallDelta {\n /**\n * The definition of the function that was called.\n */\n export interface Function {\n /**\n * The arguments passed to the function.\n */\n arguments?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * The output of the function. This will be `null` if the outputs have not been\n * [submitted](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)\n * yet.\n */\n output?: string | null;\n }\n}\n\n/**\n * Details of the message creation by the run step.\n */\nexport interface MessageCreationStepDetails {\n message_creation: MessageCreationStepDetails.MessageCreation;\n\n /**\n * Always `message_creation`.\n */\n type: 'message_creation';\n}\n\nexport namespace MessageCreationStepDetails {\n export interface MessageCreation {\n /**\n * The ID of the message that was created by this run step.\n */\n message_id: string;\n }\n}\n\n/**\n * Represents a step in execution of a run.\n */\nexport interface RunStep {\n /**\n * The identifier of the run step, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The ID of the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants)\n * associated with the run step.\n */\n assistant_id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the run step was cancelled.\n */\n cancelled_at: number | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run step completed.\n */\n completed_at: number | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run step was created.\n */\n created_at: number;\n\n /**\n * The Unix timestamp (in seconds) for when the run step expired. A step is\n * considered expired if the parent run is expired.\n */\n expired_at: number | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run step failed.\n */\n failed_at: number | null;\n\n /**\n * The last error associated with this run step. Will be `null` if there are no\n * errors.\n */\n last_error: RunStep.LastError | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The object type, which is always `thread.run.step`.\n */\n object: 'thread.run.step';\n\n /**\n * The ID of the [run](https://platform.openai.com/docs/api-reference/runs) that\n * this run step is a part of.\n */\n run_id: string;\n\n /**\n * The status of the run step, which can be either `in_progress`, `cancelled`,\n * `failed`, `completed`, or `expired`.\n */\n status: 'in_progress' | 'cancelled' | 'failed' | 'completed' | 'expired';\n\n /**\n * The details of the run step.\n */\n step_details: MessageCreationStepDetails | ToolCallsStepDetails;\n\n /**\n * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n * that was run.\n */\n thread_id: string;\n\n /**\n * The type of run step, which can be either `message_creation` or `tool_calls`.\n */\n type: 'message_creation' | 'tool_calls';\n\n /**\n * Usage statistics related to the run step. This value will be `null` while the\n * run step's status is `in_progress`.\n */\n usage: RunStep.Usage | null;\n}\n\nexport namespace RunStep {\n /**\n * The last error associated with this run step. Will be `null` if there are no\n * errors.\n */\n export interface LastError {\n /**\n * One of `server_error` or `rate_limit_exceeded`.\n */\n code: 'server_error' | 'rate_limit_exceeded';\n\n /**\n * A human-readable description of the error.\n */\n message: string;\n }\n\n /**\n * Usage statistics related to the run step. This value will be `null` while the\n * run step's status is `in_progress`.\n */\n export interface Usage {\n /**\n * Number of completion tokens used over the course of the run step.\n */\n completion_tokens: number;\n\n /**\n * Number of prompt tokens used over the course of the run step.\n */\n prompt_tokens: number;\n\n /**\n * Total number of tokens used (prompt + completion).\n */\n total_tokens: number;\n }\n}\n\n/**\n * The delta containing the fields that have changed on the run step.\n */\nexport interface RunStepDelta {\n /**\n * The details of the run step.\n */\n step_details?: RunStepDeltaMessageDelta | ToolCallDeltaObject;\n}\n\n/**\n * Represents a run step delta i.e. any changed fields on a run step during\n * streaming.\n */\nexport interface RunStepDeltaEvent {\n /**\n * The identifier of the run step, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The delta containing the fields that have changed on the run step.\n */\n delta: RunStepDelta;\n\n /**\n * The object type, which is always `thread.run.step.delta`.\n */\n object: 'thread.run.step.delta';\n}\n\n/**\n * Details of the message creation by the run step.\n */\nexport interface RunStepDeltaMessageDelta {\n /**\n * Always `message_creation`.\n */\n type: 'message_creation';\n\n message_creation?: RunStepDeltaMessageDelta.MessageCreation;\n}\n\nexport namespace RunStepDeltaMessageDelta {\n export interface MessageCreation {\n /**\n * The ID of the message that was created by this run step.\n */\n message_id?: string;\n }\n}\n\nexport type RunStepInclude = 'step_details.tool_calls[*].file_search.results[*].content';\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport type ToolCall = CodeInterpreterToolCall | FileSearchToolCall | FunctionToolCall;\n\n/**\n * Details of the Code Interpreter tool call the run step was involved in.\n */\nexport type ToolCallDelta = CodeInterpreterToolCallDelta | FileSearchToolCallDelta | FunctionToolCallDelta;\n\n/**\n * Details of the tool call.\n */\nexport interface ToolCallDeltaObject {\n /**\n * Always `tool_calls`.\n */\n type: 'tool_calls';\n\n /**\n * An array of tool calls the run step was involved in. These can be associated\n * with one of three types of tools: `code_interpreter`, `file_search`, or\n * `function`.\n */\n tool_calls?: Array<ToolCallDelta>;\n}\n\n/**\n * Details of the tool call.\n */\nexport interface ToolCallsStepDetails {\n /**\n * An array of tool calls the run step was involved in. These can be associated\n * with one of three types of tools: `code_interpreter`, `file_search`, or\n * `function`.\n */\n tool_calls: Array<ToolCall>;\n\n /**\n * Always `tool_calls`.\n */\n type: 'tool_calls';\n}\n\nexport interface StepRetrieveParams {\n /**\n * Path param: The ID of the thread to which the run and run step belongs.\n */\n thread_id: string;\n\n /**\n * Path param: The ID of the run to which the run step belongs.\n */\n run_id: string;\n\n /**\n * Query param: A list of additional fields to include in the response. Currently\n * the only supported value is\n * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file\n * search result content.\n *\n * See the\n * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n * for more information.\n */\n include?: Array<RunStepInclude>;\n}\n\nexport interface StepListParams extends CursorPageParams {\n /**\n * Path param: The ID of the thread the run and run steps belong to.\n */\n thread_id: string;\n\n /**\n * Query param: A cursor for use in pagination. `before` is an object ID that\n * defines your place in the list. For instance, if you make a list request and\n * receive 100 objects, starting with obj_foo, your subsequent call can include\n * before=obj_foo in order to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Query param: A list of additional fields to include in the response. Currently\n * the only supported value is\n * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file\n * search result content.\n *\n * See the\n * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n * for more information.\n */\n include?: Array<RunStepInclude>;\n\n /**\n * Query param: Sort order by the `created_at` timestamp of the objects. `asc` for\n * ascending order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport declare namespace Steps {\n export {\n type CodeInterpreterLogs as CodeInterpreterLogs,\n type CodeInterpreterOutputImage as CodeInterpreterOutputImage,\n type CodeInterpreterToolCall as CodeInterpreterToolCall,\n type CodeInterpreterToolCallDelta as CodeInterpreterToolCallDelta,\n type FileSearchToolCall as FileSearchToolCall,\n type FileSearchToolCallDelta as FileSearchToolCallDelta,\n type FunctionToolCall as FunctionToolCall,\n type FunctionToolCallDelta as FunctionToolCallDelta,\n type MessageCreationStepDetails as MessageCreationStepDetails,\n type RunStep as RunStep,\n type RunStepDelta as RunStepDelta,\n type RunStepDeltaEvent as RunStepDeltaEvent,\n type RunStepDeltaMessageDelta as RunStepDeltaMessageDelta,\n type RunStepInclude as RunStepInclude,\n type ToolCall as ToolCall,\n type ToolCallDelta as ToolCallDelta,\n type ToolCallDeltaObject as ToolCallDeltaObject,\n type ToolCallsStepDetails as ToolCallsStepDetails,\n type RunStepsPage as RunStepsPage,\n type StepRetrieveParams as StepRetrieveParams,\n type StepListParams as StepListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { OpenAIError } from '../../core/error';\nimport { encodeUTF8 } from './bytes';\n\nexport const toBase64 = (data: string | Uint8Array | null | undefined): string => {\n if (!data) return '';\n\n if (typeof (globalThis as any).Buffer !== 'undefined') {\n return (globalThis as any).Buffer.from(data).toString('base64');\n }\n\n if (typeof data === 'string') {\n data = encodeUTF8(data);\n }\n\n if (typeof btoa !== 'undefined') {\n return btoa(String.fromCharCode.apply(null, data as any));\n }\n\n throw new OpenAIError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');\n};\n\nexport const fromBase64 = (str: string): Uint8Array => {\n if (typeof (globalThis as any).Buffer !== 'undefined') {\n const buf = (globalThis as any).Buffer.from(str, 'base64');\n return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n }\n\n if (typeof atob !== 'undefined') {\n const bstr = atob(str);\n const buf = new Uint8Array(bstr.length);\n for (let i = 0; i < bstr.length; i++) {\n buf[i] = bstr.charCodeAt(i);\n }\n return buf;\n }\n\n throw new OpenAIError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');\n};\n\n/**\n * Converts a Base64 encoded string to a Float32Array.\n * @param base64Str - The Base64 encoded string.\n * @returns An Array of numbers interpreted as Float32 values.\n */\nexport const toFloat32Array = (base64Str: string): Array<number> => {\n if (typeof Buffer !== 'undefined') {\n // for Node.js environment\n const buf = Buffer.from(base64Str, 'base64');\n return Array.from(\n new Float32Array(buf.buffer, buf.byteOffset, buf.length / Float32Array.BYTES_PER_ELEMENT),\n );\n } else {\n // for legacy web platform APIs\n const binaryStr = atob(base64Str);\n const len = binaryStr.length;\n const bytes = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n bytes[i] = binaryStr.charCodeAt(i);\n }\n return Array.from(new Float32Array(bytes.buffer));\n }\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\n/**\n * Read an environment variable.\n *\n * Trims beginning and trailing whitespace.\n *\n * Will return undefined if the environment variable doesn't exist or cannot be accessed.\n */\nexport const readEnv = (env: string): string | undefined => {\n if (typeof (globalThis as any).process !== 'undefined') {\n return (globalThis as any).process.env?.[env]?.trim() ?? undefined;\n }\n if (typeof (globalThis as any).Deno !== 'undefined') {\n return (globalThis as any).Deno.env?.get?.(env)?.trim();\n }\n return undefined;\n};\n","import {\n TextContentBlock,\n ImageFileContentBlock,\n Message,\n MessageContentDelta,\n Text,\n ImageFile,\n TextDelta,\n MessageDelta,\n MessageContent,\n} from '../resources/beta/threads/messages';\nimport { RequestOptions } from '../internal/request-options';\nimport {\n Run,\n RunCreateParamsBase,\n RunCreateParamsStreaming,\n Runs,\n RunSubmitToolOutputsParamsBase,\n RunSubmitToolOutputsParamsStreaming,\n} from '../resources/beta/threads/runs/runs';\nimport { type ReadableStream } from '../internal/shim-types';\nimport { Stream } from '../streaming';\nimport { APIUserAbortError, OpenAIError } from '../error';\nimport {\n AssistantStreamEvent,\n MessageStreamEvent,\n RunStepStreamEvent,\n RunStreamEvent,\n} from '../resources/beta/assistants';\nimport { RunStep, RunStepDelta, ToolCall, ToolCallDelta } from '../resources/beta/threads/runs/steps';\nimport { ThreadCreateAndRunParamsBase, Threads } from '../resources/beta/threads/threads';\nimport { BaseEvents, EventStream } from './EventStream';\nimport { isObj } from '../internal/utils';\n\nexport interface AssistantStreamEvents extends BaseEvents {\n run: (run: Run) => void;\n\n //New event structure\n messageCreated: (message: Message) => void;\n messageDelta: (message: MessageDelta, snapshot: Message) => void;\n messageDone: (message: Message) => void;\n\n runStepCreated: (runStep: RunStep) => void;\n runStepDelta: (delta: RunStepDelta, snapshot: Runs.RunStep) => void;\n runStepDone: (runStep: Runs.RunStep, snapshot: Runs.RunStep) => void;\n\n toolCallCreated: (toolCall: ToolCall) => void;\n toolCallDelta: (delta: ToolCallDelta, snapshot: ToolCall) => void;\n toolCallDone: (toolCall: ToolCall) => void;\n\n textCreated: (content: Text) => void;\n textDelta: (delta: TextDelta, snapshot: Text) => void;\n textDone: (content: Text, snapshot: Message) => void;\n\n //No created or delta as this is not streamed\n imageFileDone: (content: ImageFile, snapshot: Message) => void;\n\n event: (event: AssistantStreamEvent) => void;\n}\n\nexport type ThreadCreateAndRunParamsBaseStream = Omit<ThreadCreateAndRunParamsBase, 'stream'> & {\n stream?: true;\n};\n\nexport type RunCreateParamsBaseStream = Omit<RunCreateParamsBase, 'stream'> & {\n stream?: true;\n};\n\nexport type RunSubmitToolOutputsParamsStream = Omit<RunSubmitToolOutputsParamsBase, 'stream'> & {\n stream?: true;\n};\n\nexport class AssistantStream\n extends EventStream<AssistantStreamEvents>\n implements AsyncIterable<AssistantStreamEvent>\n{\n //Track all events in a single list for reference\n #events: AssistantStreamEvent[] = [];\n\n //Used to accumulate deltas\n //We are accumulating many types so the value here is not strict\n #runStepSnapshots: { [id: string]: Runs.RunStep } = {};\n #messageSnapshots: { [id: string]: Message } = {};\n #messageSnapshot: Message | undefined;\n #finalRun: Run | undefined;\n #currentContentIndex: number | undefined;\n #currentContent: MessageContent | undefined;\n #currentToolCallIndex: number | undefined;\n #currentToolCall: ToolCall | undefined;\n\n //For current snapshot methods\n #currentEvent: AssistantStreamEvent | undefined;\n #currentRunSnapshot: Run | undefined;\n #currentRunStepSnapshot: Runs.RunStep | undefined;\n\n [Symbol.asyncIterator](): AsyncIterator<AssistantStreamEvent> {\n const pushQueue: AssistantStreamEvent[] = [];\n const readQueue: {\n resolve: (chunk: AssistantStreamEvent | undefined) => void;\n reject: (err: unknown) => void;\n }[] = [];\n let done = false;\n\n //Catch all for passing along all events\n this.on('event', (event) => {\n const reader = readQueue.shift();\n if (reader) {\n reader.resolve(event);\n } else {\n pushQueue.push(event);\n }\n });\n\n this.on('end', () => {\n done = true;\n for (const reader of readQueue) {\n reader.resolve(undefined);\n }\n readQueue.length = 0;\n });\n\n this.on('abort', (err) => {\n done = true;\n for (const reader of readQueue) {\n reader.reject(err);\n }\n readQueue.length = 0;\n });\n\n this.on('error', (err) => {\n done = true;\n for (const reader of readQueue) {\n reader.reject(err);\n }\n readQueue.length = 0;\n });\n\n return {\n next: async (): Promise<IteratorResult<AssistantStreamEvent>> => {\n if (!pushQueue.length) {\n if (done) {\n return { value: undefined, done: true };\n }\n return new Promise<AssistantStreamEvent | undefined>((resolve, reject) =>\n readQueue.push({ resolve, reject }),\n ).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));\n }\n const chunk = pushQueue.shift()!;\n return { value: chunk, done: false };\n },\n return: async () => {\n this.abort();\n return { value: undefined, done: true };\n },\n };\n }\n\n static fromReadableStream(stream: ReadableStream): AssistantStream {\n const runner = new AssistantStream();\n runner._run(() => runner._fromReadableStream(stream));\n return runner;\n }\n\n protected async _fromReadableStream(\n readableStream: ReadableStream,\n options?: RequestOptions,\n ): Promise<Run> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n this._connected();\n const stream = Stream.fromReadableStream<AssistantStreamEvent>(readableStream, this.controller);\n for await (const event of stream) {\n this.#addEvent(event);\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n return this._addRun(this.#endRequest());\n }\n\n toReadableStream(): ReadableStream {\n const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);\n return stream.toReadableStream();\n }\n\n static createToolAssistantStream(\n runId: string,\n runs: Runs,\n params: RunSubmitToolOutputsParamsStream,\n options: RequestOptions | undefined,\n ): AssistantStream {\n const runner = new AssistantStream();\n runner._run(() =>\n runner._runToolAssistantStream(runId, runs, params, {\n ...options,\n headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n }),\n );\n return runner;\n }\n\n protected async _createToolAssistantStream(\n run: Runs,\n runId: string,\n params: RunSubmitToolOutputsParamsStream,\n options?: RequestOptions,\n ): Promise<Run> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n\n const body: RunSubmitToolOutputsParamsStreaming = { ...params, stream: true };\n const stream = await run.submitToolOutputs(runId, body, {\n ...options,\n signal: this.controller.signal,\n });\n\n this._connected();\n\n for await (const event of stream) {\n this.#addEvent(event);\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n\n return this._addRun(this.#endRequest());\n }\n\n static createThreadAssistantStream(\n params: ThreadCreateAndRunParamsBaseStream,\n thread: Threads,\n options?: RequestOptions,\n ): AssistantStream {\n const runner = new AssistantStream();\n runner._run(() =>\n runner._threadAssistantStream(params, thread, {\n ...options,\n headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n }),\n );\n return runner;\n }\n\n static createAssistantStream(\n threadId: string,\n runs: Runs,\n params: RunCreateParamsBaseStream,\n options?: RequestOptions,\n ): AssistantStream {\n const runner = new AssistantStream();\n runner._run(() =>\n runner._runAssistantStream(threadId, runs, params, {\n ...options,\n headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n }),\n );\n return runner;\n }\n\n currentEvent(): AssistantStreamEvent | undefined {\n return this.#currentEvent;\n }\n\n currentRun(): Run | undefined {\n return this.#currentRunSnapshot;\n }\n\n currentMessageSnapshot(): Message | undefined {\n return this.#messageSnapshot;\n }\n\n currentRunStepSnapshot(): Runs.RunStep | undefined {\n return this.#currentRunStepSnapshot;\n }\n\n async finalRunSteps(): Promise<Runs.RunStep[]> {\n await this.done();\n\n return Object.values(this.#runStepSnapshots);\n }\n\n async finalMessages(): Promise<Message[]> {\n await this.done();\n\n return Object.values(this.#messageSnapshots);\n }\n\n async finalRun(): Promise<Run> {\n await this.done();\n if (!this.#finalRun) throw Error('Final run was not received.');\n\n return this.#finalRun;\n }\n\n protected async _createThreadAssistantStream(\n thread: Threads,\n params: ThreadCreateAndRunParamsBase,\n options?: RequestOptions,\n ): Promise<Run> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n\n const body: RunCreateParamsStreaming = { ...params, stream: true };\n const stream = await thread.createAndRun(body, { ...options, signal: this.controller.signal });\n\n this._connected();\n\n for await (const event of stream) {\n this.#addEvent(event);\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n\n return this._addRun(this.#endRequest());\n }\n\n protected async _createAssistantStream(\n run: Runs,\n threadId: string,\n params: RunCreateParamsBase,\n options?: RequestOptions,\n ): Promise<Run> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n\n const body: RunCreateParamsStreaming = { ...params, stream: true };\n const stream = await run.create(threadId, body, { ...options, signal: this.controller.signal });\n\n this._connected();\n\n for await (const event of stream) {\n this.#addEvent(event);\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n\n return this._addRun(this.#endRequest());\n }\n\n #addEvent(event: AssistantStreamEvent) {\n if (this.ended) return;\n\n this.#currentEvent = event;\n\n this.#handleEvent(event);\n\n switch (event.event) {\n case 'thread.created':\n //No action on this event.\n break;\n\n case 'thread.run.created':\n case 'thread.run.queued':\n case 'thread.run.in_progress':\n case 'thread.run.requires_action':\n case 'thread.run.completed':\n case 'thread.run.incomplete':\n case 'thread.run.failed':\n case 'thread.run.cancelling':\n case 'thread.run.cancelled':\n case 'thread.run.expired':\n this.#handleRun(event);\n break;\n\n case 'thread.run.step.created':\n case 'thread.run.step.in_progress':\n case 'thread.run.step.delta':\n case 'thread.run.step.completed':\n case 'thread.run.step.failed':\n case 'thread.run.step.cancelled':\n case 'thread.run.step.expired':\n this.#handleRunStep(event);\n break;\n\n case 'thread.message.created':\n case 'thread.message.in_progress':\n case 'thread.message.delta':\n case 'thread.message.completed':\n case 'thread.message.incomplete':\n this.#handleMessage(event);\n break;\n\n case 'error':\n //This is included for completeness, but errors are processed in the SSE event processing so this should not occur\n throw new Error(\n 'Encountered an error event in event processing - errors should be processed earlier',\n );\n default:\n assertNever(event);\n }\n }\n\n #endRequest(): Run {\n if (this.ended) {\n throw new OpenAIError(`stream has ended, this shouldn't happen`);\n }\n\n if (!this.#finalRun) throw Error('Final run has not been received');\n\n return this.#finalRun;\n }\n\n #handleMessage(this: AssistantStream, event: MessageStreamEvent) {\n const [accumulatedMessage, newContent] = this.#accumulateMessage(event, this.#messageSnapshot);\n this.#messageSnapshot = accumulatedMessage;\n this.#messageSnapshots[accumulatedMessage.id] = accumulatedMessage;\n\n for (const content of newContent) {\n const snapshotContent = accumulatedMessage.content[content.index];\n if (snapshotContent?.type == 'text') {\n this._emit('textCreated', snapshotContent.text);\n }\n }\n\n switch (event.event) {\n case 'thread.message.created':\n this._emit('messageCreated', event.data);\n break;\n\n case 'thread.message.in_progress':\n break;\n\n case 'thread.message.delta':\n this._emit('messageDelta', event.data.delta, accumulatedMessage);\n\n if (event.data.delta.content) {\n for (const content of event.data.delta.content) {\n //If it is text delta, emit a text delta event\n if (content.type == 'text' && content.text) {\n let textDelta = content.text;\n let snapshot = accumulatedMessage.content[content.index];\n if (snapshot && snapshot.type == 'text') {\n this._emit('textDelta', textDelta, snapshot.text);\n } else {\n throw Error('The snapshot associated with this text delta is not text or missing');\n }\n }\n\n if (content.index != this.#currentContentIndex) {\n //See if we have in progress content\n if (this.#currentContent) {\n switch (this.#currentContent.type) {\n case 'text':\n this._emit('textDone', this.#currentContent.text, this.#messageSnapshot);\n break;\n case 'image_file':\n this._emit('imageFileDone', this.#currentContent.image_file, this.#messageSnapshot);\n break;\n }\n }\n\n this.#currentContentIndex = content.index;\n }\n\n this.#currentContent = accumulatedMessage.content[content.index];\n }\n }\n\n break;\n\n case 'thread.message.completed':\n case 'thread.message.incomplete':\n //We emit the latest content we were working on on completion (including incomplete)\n if (this.#currentContentIndex !== undefined) {\n const currentContent = event.data.content[this.#currentContentIndex];\n if (currentContent) {\n switch (currentContent.type) {\n case 'image_file':\n this._emit('imageFileDone', currentContent.image_file, this.#messageSnapshot);\n break;\n case 'text':\n this._emit('textDone', currentContent.text, this.#messageSnapshot);\n break;\n }\n }\n }\n\n if (this.#messageSnapshot) {\n this._emit('messageDone', event.data);\n }\n\n this.#messageSnapshot = undefined;\n }\n }\n\n #handleRunStep(this: AssistantStream, event: RunStepStreamEvent) {\n const accumulatedRunStep = this.#accumulateRunStep(event);\n this.#currentRunStepSnapshot = accumulatedRunStep;\n\n switch (event.event) {\n case 'thread.run.step.created':\n this._emit('runStepCreated', event.data);\n break;\n case 'thread.run.step.delta':\n const delta = event.data.delta;\n if (\n delta.step_details &&\n delta.step_details.type == 'tool_calls' &&\n delta.step_details.tool_calls &&\n accumulatedRunStep.step_details.type == 'tool_calls'\n ) {\n for (const toolCall of delta.step_details.tool_calls) {\n if (toolCall.index == this.#currentToolCallIndex) {\n this._emit(\n 'toolCallDelta',\n toolCall,\n accumulatedRunStep.step_details.tool_calls[toolCall.index] as ToolCall,\n );\n } else {\n if (this.#currentToolCall) {\n this._emit('toolCallDone', this.#currentToolCall);\n }\n\n this.#currentToolCallIndex = toolCall.index;\n this.#currentToolCall = accumulatedRunStep.step_details.tool_calls[toolCall.index];\n if (this.#currentToolCall) this._emit('toolCallCreated', this.#currentToolCall);\n }\n }\n }\n\n this._emit('runStepDelta', event.data.delta, accumulatedRunStep);\n break;\n case 'thread.run.step.completed':\n case 'thread.run.step.failed':\n case 'thread.run.step.cancelled':\n case 'thread.run.step.expired':\n this.#currentRunStepSnapshot = undefined;\n const details = event.data.step_details;\n if (details.type == 'tool_calls') {\n if (this.#currentToolCall) {\n this._emit('toolCallDone', this.#currentToolCall as ToolCall);\n this.#currentToolCall = undefined;\n }\n }\n this._emit('runStepDone', event.data, accumulatedRunStep);\n break;\n case 'thread.run.step.in_progress':\n break;\n }\n }\n\n #handleEvent(this: AssistantStream, event: AssistantStreamEvent) {\n this.#events.push(event);\n this._emit('event', event);\n }\n\n #accumulateRunStep(event: RunStepStreamEvent): Runs.RunStep {\n switch (event.event) {\n case 'thread.run.step.created':\n this.#runStepSnapshots[event.data.id] = event.data;\n return event.data;\n\n case 'thread.run.step.delta':\n let snapshot = this.#runStepSnapshots[event.data.id] as Runs.RunStep;\n if (!snapshot) {\n throw Error('Received a RunStepDelta before creation of a snapshot');\n }\n\n let data = event.data;\n\n if (data.delta) {\n const accumulated = AssistantStream.accumulateDelta(snapshot, data.delta) as Runs.RunStep;\n this.#runStepSnapshots[event.data.id] = accumulated;\n }\n\n return this.#runStepSnapshots[event.data.id] as Runs.RunStep;\n\n case 'thread.run.step.completed':\n case 'thread.run.step.failed':\n case 'thread.run.step.cancelled':\n case 'thread.run.step.expired':\n case 'thread.run.step.in_progress':\n this.#runStepSnapshots[event.data.id] = event.data;\n break;\n }\n\n if (this.#runStepSnapshots[event.data.id]) return this.#runStepSnapshots[event.data.id] as Runs.RunStep;\n throw new Error('No snapshot available');\n }\n\n #accumulateMessage(\n event: AssistantStreamEvent,\n snapshot: Message | undefined,\n ): [Message, MessageContentDelta[]] {\n let newContent: MessageContentDelta[] = [];\n\n switch (event.event) {\n case 'thread.message.created':\n //On creation the snapshot is just the initial message\n return [event.data, newContent];\n\n case 'thread.message.delta':\n if (!snapshot) {\n throw Error(\n 'Received a delta with no existing snapshot (there should be one from message creation)',\n );\n }\n\n let data = event.data;\n\n //If this delta does not have content, nothing to process\n if (data.delta.content) {\n for (const contentElement of data.delta.content) {\n if (contentElement.index in snapshot.content) {\n let currentContent = snapshot.content[contentElement.index];\n snapshot.content[contentElement.index] = this.#accumulateContent(\n contentElement,\n currentContent,\n );\n } else {\n snapshot.content[contentElement.index] = contentElement as MessageContent;\n // This is a new element\n newContent.push(contentElement);\n }\n }\n }\n\n return [snapshot, newContent];\n\n case 'thread.message.in_progress':\n case 'thread.message.completed':\n case 'thread.message.incomplete':\n //No changes on other thread events\n if (snapshot) {\n return [snapshot, newContent];\n } else {\n throw Error('Received thread message event with no existing snapshot');\n }\n }\n throw Error('Tried to accumulate a non-message event');\n }\n\n #accumulateContent(\n contentElement: MessageContentDelta,\n currentContent: MessageContent | undefined,\n ): TextContentBlock | ImageFileContentBlock {\n return AssistantStream.accumulateDelta(currentContent as unknown as Record<any, any>, contentElement) as\n | TextContentBlock\n | ImageFileContentBlock;\n }\n\n static accumulateDelta(acc: Record<string, any>, delta: Record<string, any>): Record<string, any> {\n for (const [key, deltaValue] of Object.entries(delta)) {\n if (!acc.hasOwnProperty(key)) {\n acc[key] = deltaValue;\n continue;\n }\n\n let accValue = acc[key];\n if (accValue === null || accValue === undefined) {\n acc[key] = deltaValue;\n continue;\n }\n\n // We don't accumulate these special properties\n if (key === 'index' || key === 'type') {\n acc[key] = deltaValue;\n continue;\n }\n\n // Type-specific accumulation logic\n if (typeof accValue === 'string' && typeof deltaValue === 'string') {\n accValue += deltaValue;\n } else if (typeof accValue === 'number' && typeof deltaValue === 'number') {\n accValue += deltaValue;\n } else if (isObj(accValue) && isObj(deltaValue)) {\n accValue = this.accumulateDelta(accValue as Record<string, any>, deltaValue as Record<string, any>);\n } else if (Array.isArray(accValue) && Array.isArray(deltaValue)) {\n if (accValue.every((x) => typeof x === 'string' || typeof x === 'number')) {\n accValue.push(...deltaValue); // Use spread syntax for efficient addition\n continue;\n }\n\n for (const deltaEntry of deltaValue) {\n if (!isObj(deltaEntry)) {\n throw new Error(`Expected array delta entry to be an object but got: ${deltaEntry}`);\n }\n\n const index = deltaEntry['index'];\n if (index == null) {\n console.error(deltaEntry);\n throw new Error('Expected array delta entry to have an `index` property');\n }\n\n if (typeof index !== 'number') {\n throw new Error(`Expected array delta entry \\`index\\` property to be a number but got ${index}`);\n }\n\n const accEntry = accValue[index];\n if (accEntry == null) {\n accValue.push(deltaEntry);\n } else {\n accValue[index] = this.accumulateDelta(accEntry, deltaEntry);\n }\n }\n continue;\n } else {\n throw Error(`Unhandled record type: ${key}, deltaValue: ${deltaValue}, accValue: ${accValue}`);\n }\n acc[key] = accValue;\n }\n\n return acc;\n }\n\n #handleRun(this: AssistantStream, event: RunStreamEvent) {\n this.#currentRunSnapshot = event.data;\n\n switch (event.event) {\n case 'thread.run.created':\n break;\n case 'thread.run.queued':\n break;\n case 'thread.run.in_progress':\n break;\n case 'thread.run.requires_action':\n case 'thread.run.cancelled':\n case 'thread.run.failed':\n case 'thread.run.completed':\n case 'thread.run.expired':\n case 'thread.run.incomplete':\n this.#finalRun = event.data;\n if (this.#currentToolCall) {\n this._emit('toolCallDone', this.#currentToolCall);\n this.#currentToolCall = undefined;\n }\n break;\n case 'thread.run.cancelling':\n break;\n }\n }\n\n protected _addRun(run: Run): Run {\n return run;\n }\n\n protected async _threadAssistantStream(\n params: ThreadCreateAndRunParamsBase,\n thread: Threads,\n options?: RequestOptions,\n ): Promise<Run> {\n return await this._createThreadAssistantStream(thread, params, options);\n }\n\n protected async _runAssistantStream(\n threadId: string,\n runs: Runs,\n params: RunCreateParamsBase,\n options?: RequestOptions,\n ): Promise<Run> {\n return await this._createAssistantStream(runs, threadId, params, options);\n }\n\n protected async _runToolAssistantStream(\n runId: string,\n runs: Runs,\n params: RunSubmitToolOutputsParamsStream,\n options?: RequestOptions,\n ): Promise<Run> {\n return await this._createToolAssistantStream(runs, runId, params, options);\n }\n}\n\nfunction assertNever(_x: never) {}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../../core/resource';\nimport * as RunsAPI from './runs';\nimport * as Shared from '../../../shared';\nimport * as AssistantsAPI from '../../assistants';\nimport * as MessagesAPI from '../messages';\nimport * as ThreadsAPI from '../threads';\nimport * as StepsAPI from './steps';\nimport {\n CodeInterpreterLogs,\n CodeInterpreterOutputImage,\n CodeInterpreterToolCall,\n CodeInterpreterToolCallDelta,\n FileSearchToolCall,\n FileSearchToolCallDelta,\n FunctionToolCall,\n FunctionToolCallDelta,\n MessageCreationStepDetails,\n RunStep,\n RunStepDelta,\n RunStepDeltaEvent,\n RunStepDeltaMessageDelta,\n RunStepInclude,\n RunStepsPage,\n StepListParams,\n StepRetrieveParams,\n Steps,\n ToolCall,\n ToolCallDelta,\n ToolCallDeltaObject,\n ToolCallsStepDetails,\n} from './steps';\nimport { APIPromise } from '../../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../../core/pagination';\nimport { Stream } from '../../../../core/streaming';\nimport { buildHeaders } from '../../../../internal/headers';\nimport { RequestOptions } from '../../../../internal/request-options';\nimport { AssistantStream, RunCreateParamsBaseStream } from '../../../../lib/AssistantStream';\nimport { sleep } from '../../../../internal/utils/sleep';\nimport { RunSubmitToolOutputsParamsStream } from '../../../../lib/AssistantStream';\nimport { path } from '../../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Runs extends APIResource {\n steps: StepsAPI.Steps = new StepsAPI.Steps(this._client);\n\n /**\n * Create a run.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n create(threadID: string, params: RunCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Run>;\n create(\n threadID: string,\n params: RunCreateParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n create(\n threadID: string,\n params: RunCreateParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | Run>;\n create(\n threadID: string,\n params: RunCreateParams,\n options?: RequestOptions,\n ): APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>> {\n const { include, ...body } = params;\n return this._client.post(path`/threads/${threadID}/runs`, {\n query: { include },\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n stream: params.stream ?? false,\n __synthesizeEventData: true,\n }) as APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n }\n\n /**\n * Retrieves a run.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n retrieve(runID: string, params: RunRetrieveParams, options?: RequestOptions): APIPromise<Run> {\n const { thread_id } = params;\n return this._client.get(path`/threads/${thread_id}/runs/${runID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Modifies a run.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n update(runID: string, params: RunUpdateParams, options?: RequestOptions): APIPromise<Run> {\n const { thread_id, ...body } = params;\n return this._client.post(path`/threads/${thread_id}/runs/${runID}`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Returns a list of runs belonging to a thread.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n list(\n threadID: string,\n query: RunListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<RunsPage, Run> {\n return this._client.getAPIList(path`/threads/${threadID}/runs`, CursorPage<Run>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Cancels a run that is `in_progress`.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n cancel(runID: string, params: RunCancelParams, options?: RequestOptions): APIPromise<Run> {\n const { thread_id } = params;\n return this._client.post(path`/threads/${thread_id}/runs/${runID}/cancel`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * A helper to create a run an poll for a terminal state. More information on Run\n * lifecycles can be found here:\n * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n */\n async createAndPoll(\n threadId: string,\n body: RunCreateParamsNonStreaming,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<Run> {\n const run = await this.create(threadId, body, options);\n return await this.poll(run.id, { thread_id: threadId }, options);\n }\n\n /**\n * Create a Run stream\n *\n * @deprecated use `stream` instead\n */\n createAndStream(\n threadId: string,\n body: RunCreateParamsBaseStream,\n options?: RequestOptions,\n ): AssistantStream {\n return AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options);\n }\n\n /**\n * A helper to poll a run status until it reaches a terminal state. More\n * information on Run lifecycles can be found here:\n * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n */\n async poll(\n runId: string,\n params: RunRetrieveParams,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<Run> {\n const headers = buildHeaders([\n options?.headers,\n {\n 'X-Stainless-Poll-Helper': 'true',\n 'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined,\n },\n ]);\n\n while (true) {\n const { data: run, response } = await this.retrieve(runId, params, {\n ...options,\n headers: { ...options?.headers, ...headers },\n }).withResponse();\n\n switch (run.status) {\n //If we are in any sort of intermediate state we poll\n case 'queued':\n case 'in_progress':\n case 'cancelling':\n let sleepInterval = 5000;\n\n if (options?.pollIntervalMs) {\n sleepInterval = options.pollIntervalMs;\n } else {\n const headerInterval = response.headers.get('openai-poll-after-ms');\n if (headerInterval) {\n const headerIntervalMs = parseInt(headerInterval);\n if (!isNaN(headerIntervalMs)) {\n sleepInterval = headerIntervalMs;\n }\n }\n }\n await sleep(sleepInterval);\n break;\n //We return the run in any terminal state.\n case 'requires_action':\n case 'incomplete':\n case 'cancelled':\n case 'completed':\n case 'failed':\n case 'expired':\n return run;\n }\n }\n }\n\n /**\n * Create a Run stream\n */\n stream(threadId: string, body: RunCreateParamsBaseStream, options?: RequestOptions): AssistantStream {\n return AssistantStream.createAssistantStream(threadId, this._client.beta.threads.runs, body, options);\n }\n\n /**\n * When a run has the `status: \"requires_action\"` and `required_action.type` is\n * `submit_tool_outputs`, this endpoint can be used to submit the outputs from the\n * tool calls once they're all completed. All outputs must be submitted in a single\n * request.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n submitToolOutputs(\n runID: string,\n params: RunSubmitToolOutputsParamsNonStreaming,\n options?: RequestOptions,\n ): APIPromise<Run>;\n submitToolOutputs(\n runID: string,\n params: RunSubmitToolOutputsParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n submitToolOutputs(\n runID: string,\n params: RunSubmitToolOutputsParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | Run>;\n submitToolOutputs(\n runID: string,\n params: RunSubmitToolOutputsParams,\n options?: RequestOptions,\n ): APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>> {\n const { thread_id, ...body } = params;\n return this._client.post(path`/threads/${thread_id}/runs/${runID}/submit_tool_outputs`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n stream: params.stream ?? false,\n __synthesizeEventData: true,\n }) as APIPromise<Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n }\n\n /**\n * A helper to submit a tool output to a run and poll for a terminal run state.\n * More information on Run lifecycles can be found here:\n * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n */\n async submitToolOutputsAndPoll(\n runId: string,\n params: RunSubmitToolOutputsParamsNonStreaming,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<Run> {\n const run = await this.submitToolOutputs(runId, params, options);\n return await this.poll(run.id, params, options);\n }\n\n /**\n * Submit the tool outputs from a previous run and stream the run to a terminal\n * state. More information on Run lifecycles can be found here:\n * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n */\n submitToolOutputsStream(\n runId: string,\n params: RunSubmitToolOutputsParamsStream,\n options?: RequestOptions,\n ): AssistantStream {\n return AssistantStream.createToolAssistantStream(runId, this._client.beta.threads.runs, params, options);\n }\n}\n\nexport type RunsPage = CursorPage<Run>;\n\n/**\n * Tool call objects\n */\nexport interface RequiredActionFunctionToolCall {\n /**\n * The ID of the tool call. This ID must be referenced when you submit the tool\n * outputs in using the\n * [Submit tool outputs to run](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)\n * endpoint.\n */\n id: string;\n\n /**\n * The function definition.\n */\n function: RequiredActionFunctionToolCall.Function;\n\n /**\n * The type of tool call the output is required for. For now, this is always\n * `function`.\n */\n type: 'function';\n}\n\nexport namespace RequiredActionFunctionToolCall {\n /**\n * The function definition.\n */\n export interface Function {\n /**\n * The arguments that the model expects you to pass to the function.\n */\n arguments: string;\n\n /**\n * The name of the function.\n */\n name: string;\n }\n}\n\n/**\n * Represents an execution run on a\n * [thread](https://platform.openai.com/docs/api-reference/threads).\n */\nexport interface Run {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The ID of the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n * execution of this run.\n */\n assistant_id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the run was cancelled.\n */\n cancelled_at: number | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run was completed.\n */\n completed_at: number | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run was created.\n */\n created_at: number;\n\n /**\n * The Unix timestamp (in seconds) for when the run will expire.\n */\n expires_at: number | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run failed.\n */\n failed_at: number | null;\n\n /**\n * Details on why the run is incomplete. Will be `null` if the run is not\n * incomplete.\n */\n incomplete_details: Run.IncompleteDetails | null;\n\n /**\n * The instructions that the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n * this run.\n */\n instructions: string;\n\n /**\n * The last error associated with this run. Will be `null` if there are no errors.\n */\n last_error: Run.LastError | null;\n\n /**\n * The maximum number of completion tokens specified to have been used over the\n * course of the run.\n */\n max_completion_tokens: number | null;\n\n /**\n * The maximum number of prompt tokens specified to have been used over the course\n * of the run.\n */\n max_prompt_tokens: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The model that the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n * this run.\n */\n model: string;\n\n /**\n * The object type, which is always `thread.run`.\n */\n object: 'thread.run';\n\n /**\n * Whether to enable\n * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n * during tool use.\n */\n parallel_tool_calls: boolean;\n\n /**\n * Details on the action required to continue the run. Will be `null` if no action\n * is required.\n */\n required_action: Run.RequiredAction | null;\n\n /**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format: ThreadsAPI.AssistantResponseFormatOption | null;\n\n /**\n * The Unix timestamp (in seconds) for when the run was started.\n */\n started_at: number | null;\n\n /**\n * The status of the run, which can be either `queued`, `in_progress`,\n * `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,\n * `incomplete`, or `expired`.\n */\n status: RunStatus;\n\n /**\n * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n * that was executed on as a part of this run.\n */\n thread_id: string;\n\n /**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tools and instead generates a message. `auto` is the default value\n * and means the model can pick between generating a message or calling one or more\n * tools. `required` means the model must call one or more tools before responding\n * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n */\n tool_choice: ThreadsAPI.AssistantToolChoiceOption | null;\n\n /**\n * The list of tools that the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for\n * this run.\n */\n tools: Array<AssistantsAPI.AssistantTool>;\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the initial context window of the run.\n */\n truncation_strategy: Run.TruncationStrategy | null;\n\n /**\n * Usage statistics related to the run. This value will be `null` if the run is not\n * in a terminal state (i.e. `in_progress`, `queued`, etc.).\n */\n usage: Run.Usage | null;\n\n /**\n * The sampling temperature used for this run. If not set, defaults to 1.\n */\n temperature?: number | null;\n\n /**\n * The nucleus sampling value used for this run. If not set, defaults to 1.\n */\n top_p?: number | null;\n}\n\nexport namespace Run {\n /**\n * Details on why the run is incomplete. Will be `null` if the run is not\n * incomplete.\n */\n export interface IncompleteDetails {\n /**\n * The reason why the run is incomplete. This will point to which specific token\n * limit was reached over the course of the run.\n */\n reason?: 'max_completion_tokens' | 'max_prompt_tokens';\n }\n\n /**\n * The last error associated with this run. Will be `null` if there are no errors.\n */\n export interface LastError {\n /**\n * One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`.\n */\n code: 'server_error' | 'rate_limit_exceeded' | 'invalid_prompt';\n\n /**\n * A human-readable description of the error.\n */\n message: string;\n }\n\n /**\n * Details on the action required to continue the run. Will be `null` if no action\n * is required.\n */\n export interface RequiredAction {\n /**\n * Details on the tool outputs needed for this run to continue.\n */\n submit_tool_outputs: RequiredAction.SubmitToolOutputs;\n\n /**\n * For now, this is always `submit_tool_outputs`.\n */\n type: 'submit_tool_outputs';\n }\n\n export namespace RequiredAction {\n /**\n * Details on the tool outputs needed for this run to continue.\n */\n export interface SubmitToolOutputs {\n /**\n * A list of the relevant tool calls.\n */\n tool_calls: Array<RunsAPI.RequiredActionFunctionToolCall>;\n }\n }\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the initial context window of the run.\n */\n export interface TruncationStrategy {\n /**\n * The truncation strategy to use for the thread. The default is `auto`. If set to\n * `last_messages`, the thread will be truncated to the n most recent messages in\n * the thread. When set to `auto`, messages in the middle of the thread will be\n * dropped to fit the context length of the model, `max_prompt_tokens`.\n */\n type: 'auto' | 'last_messages';\n\n /**\n * The number of most recent messages from the thread when constructing the context\n * for the run.\n */\n last_messages?: number | null;\n }\n\n /**\n * Usage statistics related to the run. This value will be `null` if the run is not\n * in a terminal state (i.e. `in_progress`, `queued`, etc.).\n */\n export interface Usage {\n /**\n * Number of completion tokens used over the course of the run.\n */\n completion_tokens: number;\n\n /**\n * Number of prompt tokens used over the course of the run.\n */\n prompt_tokens: number;\n\n /**\n * Total number of tokens used (prompt + completion).\n */\n total_tokens: number;\n }\n}\n\n/**\n * The status of the run, which can be either `queued`, `in_progress`,\n * `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,\n * `incomplete`, or `expired`.\n */\nexport type RunStatus =\n | 'queued'\n | 'in_progress'\n | 'requires_action'\n | 'cancelling'\n | 'cancelled'\n | 'failed'\n | 'completed'\n | 'incomplete'\n | 'expired';\n\nexport type RunCreateParams = RunCreateParamsNonStreaming | RunCreateParamsStreaming;\n\nexport interface RunCreateParamsBase {\n /**\n * Body param: The ID of the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to\n * execute this run.\n */\n assistant_id: string;\n\n /**\n * Query param: A list of additional fields to include in the response. Currently\n * the only supported value is\n * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file\n * search result content.\n *\n * See the\n * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)\n * for more information.\n */\n include?: Array<StepsAPI.RunStepInclude>;\n\n /**\n * Body param: Appends additional instructions at the end of the instructions for\n * the run. This is useful for modifying the behavior on a per-run basis without\n * overriding other instructions.\n */\n additional_instructions?: string | null;\n\n /**\n * Body param: Adds additional messages to the thread before creating the run.\n */\n additional_messages?: Array<RunCreateParams.AdditionalMessage> | null;\n\n /**\n * Body param: Overrides the\n * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)\n * of the assistant. This is useful for modifying the behavior on a per-run basis.\n */\n instructions?: string | null;\n\n /**\n * Body param: The maximum number of completion tokens that may be used over the\n * course of the run. The run will make a best effort to use only the number of\n * completion tokens specified, across multiple turns of the run. If the run\n * exceeds the number of completion tokens specified, the run will end with status\n * `incomplete`. See `incomplete_details` for more info.\n */\n max_completion_tokens?: number | null;\n\n /**\n * Body param: The maximum number of prompt tokens that may be used over the course\n * of the run. The run will make a best effort to use only the number of prompt\n * tokens specified, across multiple turns of the run. If the run exceeds the\n * number of prompt tokens specified, the run will end with status `incomplete`.\n * See `incomplete_details` for more info.\n */\n max_prompt_tokens?: number | null;\n\n /**\n * Body param: Set of 16 key-value pairs that can be attached to an object. This\n * can be useful for storing additional information about the object in a\n * structured format, and querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * Body param: The ID of the\n * [Model](https://platform.openai.com/docs/api-reference/models) to be used to\n * execute this run. If a value is provided here, it will override the model\n * associated with the assistant. If not, the model associated with the assistant\n * will be used.\n */\n model?: (string & {}) | Shared.ChatModel | null;\n\n /**\n * Body param: Whether to enable\n * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n * during tool use.\n */\n parallel_tool_calls?: boolean;\n\n /**\n * Body param: Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Body param: Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format?: ThreadsAPI.AssistantResponseFormatOption | null;\n\n /**\n * Body param: If `true`, returns a stream of events that happen during the Run as\n * server-sent events, terminating when the Run enters a terminal state with a\n * `data: [DONE]` message.\n */\n stream?: boolean | null;\n\n /**\n * Body param: What sampling temperature to use, between 0 and 2. Higher values\n * like 0.8 will make the output more random, while lower values like 0.2 will make\n * it more focused and deterministic.\n */\n temperature?: number | null;\n\n /**\n * Body param: Controls which (if any) tool is called by the model. `none` means\n * the model will not call any tools and instead generates a message. `auto` is the\n * default value and means the model can pick between generating a message or\n * calling one or more tools. `required` means the model must call one or more\n * tools before responding to the user. Specifying a particular tool like\n * `{\"type\": \"file_search\"}` or\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n */\n tool_choice?: ThreadsAPI.AssistantToolChoiceOption | null;\n\n /**\n * Body param: Override the tools the assistant can use for this run. This is\n * useful for modifying the behavior on a per-run basis.\n */\n tools?: Array<AssistantsAPI.AssistantTool> | null;\n\n /**\n * Body param: An alternative to sampling with temperature, called nucleus\n * sampling, where the model considers the results of the tokens with top_p\n * probability mass. So 0.1 means only the tokens comprising the top 10%\n * probability mass are considered.\n *\n * We generally recommend altering this or temperature but not both.\n */\n top_p?: number | null;\n\n /**\n * Body param: Controls for how a thread will be truncated prior to the run. Use\n * this to control the initial context window of the run.\n */\n truncation_strategy?: RunCreateParams.TruncationStrategy | null;\n}\n\nexport namespace RunCreateParams {\n export interface AdditionalMessage {\n /**\n * The text contents of the message.\n */\n content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n /**\n * The role of the entity that is creating the message. Allowed values include:\n *\n * - `user`: Indicates the message is sent by an actual user and should be used in\n * most cases to represent user-generated messages.\n * - `assistant`: Indicates the message is generated by the assistant. Use this\n * value to insert messages from the assistant into the conversation.\n */\n role: 'user' | 'assistant';\n\n /**\n * A list of files attached to the message, and the tools they should be added to.\n */\n attachments?: Array<AdditionalMessage.Attachment> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n export namespace AdditionalMessage {\n export interface Attachment {\n /**\n * The ID of the file to attach to the message.\n */\n file_id?: string;\n\n /**\n * The tools to add this file to.\n */\n tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n }\n\n export namespace Attachment {\n export interface FileSearch {\n /**\n * The type of tool being defined: `file_search`\n */\n type: 'file_search';\n }\n }\n }\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the initial context window of the run.\n */\n export interface TruncationStrategy {\n /**\n * The truncation strategy to use for the thread. The default is `auto`. If set to\n * `last_messages`, the thread will be truncated to the n most recent messages in\n * the thread. When set to `auto`, messages in the middle of the thread will be\n * dropped to fit the context length of the model, `max_prompt_tokens`.\n */\n type: 'auto' | 'last_messages';\n\n /**\n * The number of most recent messages from the thread when constructing the context\n * for the run.\n */\n last_messages?: number | null;\n }\n\n export type RunCreateParamsNonStreaming = RunsAPI.RunCreateParamsNonStreaming;\n export type RunCreateParamsStreaming = RunsAPI.RunCreateParamsStreaming;\n}\n\nexport interface RunCreateParamsNonStreaming extends RunCreateParamsBase {\n /**\n * Body param: If `true`, returns a stream of events that happen during the Run as\n * server-sent events, terminating when the Run enters a terminal state with a\n * `data: [DONE]` message.\n */\n stream?: false | null;\n}\n\nexport interface RunCreateParamsStreaming extends RunCreateParamsBase {\n /**\n * Body param: If `true`, returns a stream of events that happen during the Run as\n * server-sent events, terminating when the Run enters a terminal state with a\n * `data: [DONE]` message.\n */\n stream: true;\n}\n\nexport interface RunRetrieveParams {\n /**\n * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)\n * that was run.\n */\n thread_id: string;\n}\n\nexport interface RunUpdateParams {\n /**\n * Path param: The ID of the\n * [thread](https://platform.openai.com/docs/api-reference/threads) that was run.\n */\n thread_id: string;\n\n /**\n * Body param: Set of 16 key-value pairs that can be attached to an object. This\n * can be useful for storing additional information about the object in a\n * structured format, and querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n}\n\nexport interface RunListParams extends CursorPageParams {\n /**\n * A cursor for use in pagination. `before` is an object ID that defines your place\n * in the list. For instance, if you make a list request and receive 100 objects,\n * starting with obj_foo, your subsequent call can include before=obj_foo in order\n * to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface RunCancelParams {\n /**\n * The ID of the thread to which this run belongs.\n */\n thread_id: string;\n}\n\nexport type RunCreateAndPollParams = ThreadsAPI.ThreadCreateAndRunParamsNonStreaming;\n\nexport type RunCreateAndStreamParams = RunCreateParamsBaseStream;\n\nexport type RunStreamParams = RunCreateParamsBaseStream;\n\nexport type RunSubmitToolOutputsParams =\n | RunSubmitToolOutputsParamsNonStreaming\n | RunSubmitToolOutputsParamsStreaming;\n\nexport interface RunSubmitToolOutputsParamsBase {\n /**\n * Path param: The ID of the\n * [thread](https://platform.openai.com/docs/api-reference/threads) to which this\n * run belongs.\n */\n thread_id: string;\n\n /**\n * Body param: A list of tools for which the outputs are being submitted.\n */\n tool_outputs: Array<RunSubmitToolOutputsParams.ToolOutput>;\n\n /**\n * Body param: If `true`, returns a stream of events that happen during the Run as\n * server-sent events, terminating when the Run enters a terminal state with a\n * `data: [DONE]` message.\n */\n stream?: boolean | null;\n}\n\nexport namespace RunSubmitToolOutputsParams {\n export interface ToolOutput {\n /**\n * The output of the tool call to be submitted to continue the run.\n */\n output?: string;\n\n /**\n * The ID of the tool call in the `required_action` object within the run object\n * the output is being submitted for.\n */\n tool_call_id?: string;\n }\n\n export type RunSubmitToolOutputsParamsNonStreaming = RunsAPI.RunSubmitToolOutputsParamsNonStreaming;\n export type RunSubmitToolOutputsParamsStreaming = RunsAPI.RunSubmitToolOutputsParamsStreaming;\n}\n\nexport interface RunSubmitToolOutputsParamsNonStreaming extends RunSubmitToolOutputsParamsBase {\n /**\n * Body param: If `true`, returns a stream of events that happen during the Run as\n * server-sent events, terminating when the Run enters a terminal state with a\n * `data: [DONE]` message.\n */\n stream?: false | null;\n}\n\nexport interface RunSubmitToolOutputsParamsStreaming extends RunSubmitToolOutputsParamsBase {\n /**\n * Body param: If `true`, returns a stream of events that happen during the Run as\n * server-sent events, terminating when the Run enters a terminal state with a\n * `data: [DONE]` message.\n */\n stream: true;\n}\n\nexport type RunSubmitToolOutputsAndPollParams = RunSubmitToolOutputsParamsNonStreaming;\nexport type RunSubmitToolOutputsStreamParams = RunSubmitToolOutputsParamsStream;\n\nRuns.Steps = Steps;\n\nexport declare namespace Runs {\n export {\n type RequiredActionFunctionToolCall as RequiredActionFunctionToolCall,\n type Run as Run,\n type RunStatus as RunStatus,\n type RunsPage as RunsPage,\n type RunCreateParams as RunCreateParams,\n type RunCreateParamsNonStreaming as RunCreateParamsNonStreaming,\n type RunCreateParamsStreaming as RunCreateParamsStreaming,\n type RunRetrieveParams as RunRetrieveParams,\n type RunUpdateParams as RunUpdateParams,\n type RunListParams as RunListParams,\n type RunCreateAndPollParams,\n type RunCreateAndStreamParams,\n type RunStreamParams,\n type RunSubmitToolOutputsParams as RunSubmitToolOutputsParams,\n type RunSubmitToolOutputsParamsNonStreaming as RunSubmitToolOutputsParamsNonStreaming,\n type RunSubmitToolOutputsParamsStreaming as RunSubmitToolOutputsParamsStreaming,\n type RunSubmitToolOutputsAndPollParams,\n type RunSubmitToolOutputsStreamParams,\n };\n\n export {\n Steps as Steps,\n type CodeInterpreterLogs as CodeInterpreterLogs,\n type CodeInterpreterOutputImage as CodeInterpreterOutputImage,\n type CodeInterpreterToolCall as CodeInterpreterToolCall,\n type CodeInterpreterToolCallDelta as CodeInterpreterToolCallDelta,\n type FileSearchToolCall as FileSearchToolCall,\n type FileSearchToolCallDelta as FileSearchToolCallDelta,\n type FunctionToolCall as FunctionToolCall,\n type FunctionToolCallDelta as FunctionToolCallDelta,\n type MessageCreationStepDetails as MessageCreationStepDetails,\n type RunStep as RunStep,\n type RunStepDelta as RunStepDelta,\n type RunStepDeltaEvent as RunStepDeltaEvent,\n type RunStepDeltaMessageDelta as RunStepDeltaMessageDelta,\n type RunStepInclude as RunStepInclude,\n type ToolCall as ToolCall,\n type ToolCallDelta as ToolCallDelta,\n type ToolCallDeltaObject as ToolCallDeltaObject,\n type ToolCallsStepDetails as ToolCallsStepDetails,\n type RunStepsPage as RunStepsPage,\n type StepRetrieveParams as StepRetrieveParams,\n type StepListParams as StepListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ThreadsAPI from './threads';\nimport * as Shared from '../../shared';\nimport * as AssistantsAPI from '../assistants';\nimport * as MessagesAPI from './messages';\nimport {\n Annotation,\n AnnotationDelta,\n FileCitationAnnotation,\n FileCitationDeltaAnnotation,\n FilePathAnnotation,\n FilePathDeltaAnnotation,\n ImageFile,\n ImageFileContentBlock,\n ImageFileDelta,\n ImageFileDeltaBlock,\n ImageURL,\n ImageURLContentBlock,\n ImageURLDelta,\n ImageURLDeltaBlock,\n Message as MessagesAPIMessage,\n MessageContent,\n MessageContentDelta,\n MessageContentPartParam,\n MessageCreateParams,\n MessageDeleteParams,\n MessageDeleted,\n MessageDelta,\n MessageDeltaEvent,\n MessageListParams,\n MessageRetrieveParams,\n MessageUpdateParams,\n Messages,\n MessagesPage,\n RefusalContentBlock,\n RefusalDeltaBlock,\n Text,\n TextContentBlock,\n TextContentBlockParam,\n TextDelta,\n TextDeltaBlock,\n} from './messages';\nimport * as RunsAPI from './runs/runs';\nimport {\n RequiredActionFunctionToolCall,\n Run,\n RunCreateAndPollParams,\n RunCreateAndStreamParams,\n RunCancelParams,\n RunCreateParams,\n RunCreateParamsNonStreaming,\n RunCreateParamsStreaming,\n RunListParams,\n RunRetrieveParams,\n RunStatus,\n RunStreamParams,\n RunSubmitToolOutputsAndPollParams,\n RunSubmitToolOutputsParams,\n RunSubmitToolOutputsParamsNonStreaming,\n RunSubmitToolOutputsParamsStreaming,\n RunSubmitToolOutputsStreamParams,\n RunUpdateParams,\n Runs,\n RunsPage,\n} from './runs/runs';\nimport { APIPromise } from '../../../core/api-promise';\nimport { Stream } from '../../../core/streaming';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { AssistantStream, ThreadCreateAndRunParamsBaseStream } from '../../../lib/AssistantStream';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Build Assistants that can call models and use tools.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\nexport class Threads extends APIResource {\n runs: RunsAPI.Runs = new RunsAPI.Runs(this._client);\n messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);\n\n /**\n * Create a thread.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n create(body: ThreadCreateParams | null | undefined = {}, options?: RequestOptions): APIPromise<Thread> {\n return this._client.post('/threads', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Retrieves a thread.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n retrieve(threadID: string, options?: RequestOptions): APIPromise<Thread> {\n return this._client.get(path`/threads/${threadID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Modifies a thread.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n update(threadID: string, body: ThreadUpdateParams, options?: RequestOptions): APIPromise<Thread> {\n return this._client.post(path`/threads/${threadID}`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Delete a thread.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n delete(threadID: string, options?: RequestOptions): APIPromise<ThreadDeleted> {\n return this._client.delete(path`/threads/${threadID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Create a thread and run it in one request.\n *\n * @deprecated The Assistants API is deprecated in favor of the Responses API\n */\n createAndRun(body: ThreadCreateAndRunParamsNonStreaming, options?: RequestOptions): APIPromise<RunsAPI.Run>;\n createAndRun(\n body: ThreadCreateAndRunParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n createAndRun(\n body: ThreadCreateAndRunParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | RunsAPI.Run>;\n createAndRun(\n body: ThreadCreateAndRunParams,\n options?: RequestOptions,\n ): APIPromise<RunsAPI.Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>> {\n return this._client.post('/threads/runs', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n stream: body.stream ?? false,\n __synthesizeEventData: true,\n }) as APIPromise<RunsAPI.Run> | APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;\n }\n\n /**\n * A helper to create a thread, start a run and then poll for a terminal state.\n * More information on Run lifecycles can be found here:\n * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps\n */\n async createAndRunPoll(\n body: ThreadCreateAndRunParamsNonStreaming,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<Threads.Run> {\n const run = await this.createAndRun(body, options);\n return await this.runs.poll(run.id, { thread_id: run.thread_id }, options);\n }\n\n /**\n * Create a thread and stream the run back\n */\n createAndRunStream(body: ThreadCreateAndRunParamsBaseStream, options?: RequestOptions): AssistantStream {\n return AssistantStream.createThreadAssistantStream(body, this._client.beta.threads, options);\n }\n}\n\n/**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\nexport type AssistantResponseFormatOption =\n | 'auto'\n | Shared.ResponseFormatText\n | Shared.ResponseFormatJSONObject\n | Shared.ResponseFormatJSONSchema;\n\n/**\n * Specifies a tool the model should use. Use to force the model to call a specific\n * tool.\n */\nexport interface AssistantToolChoice {\n /**\n * The type of the tool. If type is `function`, the function name must be set\n */\n type: 'function' | 'code_interpreter' | 'file_search';\n\n function?: AssistantToolChoiceFunction;\n}\n\nexport interface AssistantToolChoiceFunction {\n /**\n * The name of the function to call.\n */\n name: string;\n}\n\n/**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tools and instead generates a message. `auto` is the default value\n * and means the model can pick between generating a message or calling one or more\n * tools. `required` means the model must call one or more tools before responding\n * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n */\nexport type AssistantToolChoiceOption = 'none' | 'auto' | 'required' | AssistantToolChoice;\n\n/**\n * Represents a thread that contains\n * [messages](https://platform.openai.com/docs/api-reference/messages).\n */\nexport interface Thread {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the thread was created.\n */\n created_at: number;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The object type, which is always `thread`.\n */\n object: 'thread';\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n tool_resources: Thread.ToolResources | null;\n}\n\nexport namespace Thread {\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this thread. There can be a maximum of 1 vector store attached to\n * the thread.\n */\n vector_store_ids?: Array<string>;\n }\n }\n}\n\nexport interface ThreadDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'thread.deleted';\n}\n\nexport interface ThreadCreateParams {\n /**\n * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to\n * start the thread with.\n */\n messages?: Array<ThreadCreateParams.Message>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n tool_resources?: ThreadCreateParams.ToolResources | null;\n}\n\nexport namespace ThreadCreateParams {\n export interface Message {\n /**\n * The text contents of the message.\n */\n content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n /**\n * The role of the entity that is creating the message. Allowed values include:\n *\n * - `user`: Indicates the message is sent by an actual user and should be used in\n * most cases to represent user-generated messages.\n * - `assistant`: Indicates the message is generated by the assistant. Use this\n * value to insert messages from the assistant into the conversation.\n */\n role: 'user' | 'assistant';\n\n /**\n * A list of files attached to the message, and the tools they should be added to.\n */\n attachments?: Array<Message.Attachment> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n export namespace Message {\n export interface Attachment {\n /**\n * The ID of the file to attach to the message.\n */\n file_id?: string;\n\n /**\n * The tools to add this file to.\n */\n tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n }\n\n export namespace Attachment {\n export interface FileSearch {\n /**\n * The type of tool being defined: `file_search`\n */\n type: 'file_search';\n }\n }\n }\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this thread. There can be a maximum of 1 vector store attached to\n * the thread.\n */\n vector_store_ids?: Array<string>;\n\n /**\n * A helper to create a\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * with file_ids and attach it to this thread. There can be a maximum of 1 vector\n * store attached to the thread.\n */\n vector_stores?: Array<FileSearch.VectorStore>;\n }\n\n export namespace FileSearch {\n export interface VectorStore {\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy.\n */\n chunking_strategy?: VectorStore.Auto | VectorStore.Static;\n\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n * add to the vector store. For vector stores created before Nov 2025, there can be\n * a maximum of 10,000 files in a vector store. For vector stores created starting\n * in Nov 2025, the limit is 100,000,000 files.\n */\n file_ids?: Array<string>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n export namespace VectorStore {\n /**\n * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n * `800` and `chunk_overlap_tokens` of `400`.\n */\n export interface Auto {\n /**\n * Always `auto`.\n */\n type: 'auto';\n }\n\n export interface Static {\n static: Static.Static;\n\n /**\n * Always `static`.\n */\n type: 'static';\n }\n\n export namespace Static {\n export interface Static {\n /**\n * The number of tokens that overlap between chunks. The default value is `400`.\n *\n * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n */\n chunk_overlap_tokens: number;\n\n /**\n * The maximum number of tokens in each chunk. The default value is `800`. The\n * minimum value is `100` and the maximum value is `4096`.\n */\n max_chunk_size_tokens: number;\n }\n }\n }\n }\n }\n}\n\nexport interface ThreadUpdateParams {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n tool_resources?: ThreadUpdateParams.ToolResources | null;\n}\n\nexport namespace ThreadUpdateParams {\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this thread. There can be a maximum of 1 vector store attached to\n * the thread.\n */\n vector_store_ids?: Array<string>;\n }\n }\n}\n\nexport type ThreadCreateAndRunParams =\n | ThreadCreateAndRunParamsNonStreaming\n | ThreadCreateAndRunParamsStreaming;\n\nexport interface ThreadCreateAndRunParamsBase {\n /**\n * The ID of the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to\n * execute this run.\n */\n assistant_id: string;\n\n /**\n * Override the default system message of the assistant. This is useful for\n * modifying the behavior on a per-run basis.\n */\n instructions?: string | null;\n\n /**\n * The maximum number of completion tokens that may be used over the course of the\n * run. The run will make a best effort to use only the number of completion tokens\n * specified, across multiple turns of the run. If the run exceeds the number of\n * completion tokens specified, the run will end with status `incomplete`. See\n * `incomplete_details` for more info.\n */\n max_completion_tokens?: number | null;\n\n /**\n * The maximum number of prompt tokens that may be used over the course of the run.\n * The run will make a best effort to use only the number of prompt tokens\n * specified, across multiple turns of the run. If the run exceeds the number of\n * prompt tokens specified, the run will end with status `incomplete`. See\n * `incomplete_details` for more info.\n */\n max_prompt_tokens?: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to\n * be used to execute this run. If a value is provided here, it will override the\n * model associated with the assistant. If not, the model associated with the\n * assistant will be used.\n */\n model?: (string & {}) | Shared.ChatModel | null;\n\n /**\n * Whether to enable\n * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)\n * during tool use.\n */\n parallel_tool_calls?: boolean;\n\n /**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format?: AssistantResponseFormatOption | null;\n\n /**\n * If `true`, returns a stream of events that happen during the Run as server-sent\n * events, terminating when the Run enters a terminal state with a `data: [DONE]`\n * message.\n */\n stream?: boolean | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic.\n */\n temperature?: number | null;\n\n /**\n * Options to create a new thread. If no thread is provided when running a request,\n * an empty thread will be created.\n */\n thread?: ThreadCreateAndRunParams.Thread;\n\n /**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tools and instead generates a message. `auto` is the default value\n * and means the model can pick between generating a message or calling one or more\n * tools. `required` means the model must call one or more tools before responding\n * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n */\n tool_choice?: AssistantToolChoiceOption | null;\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n tool_resources?: ThreadCreateAndRunParams.ToolResources | null;\n\n /**\n * Override the tools the assistant can use for this run. This is useful for\n * modifying the behavior on a per-run basis.\n */\n tools?: Array<AssistantsAPI.AssistantTool> | null;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or temperature but not both.\n */\n top_p?: number | null;\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the initial context window of the run.\n */\n truncation_strategy?: ThreadCreateAndRunParams.TruncationStrategy | null;\n}\n\nexport namespace ThreadCreateAndRunParams {\n /**\n * Options to create a new thread. If no thread is provided when running a request,\n * an empty thread will be created.\n */\n export interface Thread {\n /**\n * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to\n * start the thread with.\n */\n messages?: Array<Thread.Message>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n tool_resources?: Thread.ToolResources | null;\n }\n\n export namespace Thread {\n export interface Message {\n /**\n * The text contents of the message.\n */\n content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n /**\n * The role of the entity that is creating the message. Allowed values include:\n *\n * - `user`: Indicates the message is sent by an actual user and should be used in\n * most cases to represent user-generated messages.\n * - `assistant`: Indicates the message is generated by the assistant. Use this\n * value to insert messages from the assistant into the conversation.\n */\n role: 'user' | 'assistant';\n\n /**\n * A list of files attached to the message, and the tools they should be added to.\n */\n attachments?: Array<Message.Attachment> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n export namespace Message {\n export interface Attachment {\n /**\n * The ID of the file to attach to the message.\n */\n file_id?: string;\n\n /**\n * The tools to add this file to.\n */\n tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;\n }\n\n export namespace Attachment {\n export interface FileSearch {\n /**\n * The type of tool being defined: `file_search`\n */\n type: 'file_search';\n }\n }\n }\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this thread. There can be a maximum of 1 vector store attached to\n * the thread.\n */\n vector_store_ids?: Array<string>;\n\n /**\n * A helper to create a\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * with file_ids and attach it to this thread. There can be a maximum of 1 vector\n * store attached to the thread.\n */\n vector_stores?: Array<FileSearch.VectorStore>;\n }\n\n export namespace FileSearch {\n export interface VectorStore {\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy.\n */\n chunking_strategy?: VectorStore.Auto | VectorStore.Static;\n\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n * add to the vector store. For vector stores created before Nov 2025, there can be\n * a maximum of 10,000 files in a vector store. For vector stores created starting\n * in Nov 2025, the limit is 100,000,000 files.\n */\n file_ids?: Array<string>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n export namespace VectorStore {\n /**\n * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n * `800` and `chunk_overlap_tokens` of `400`.\n */\n export interface Auto {\n /**\n * Always `auto`.\n */\n type: 'auto';\n }\n\n export interface Static {\n static: Static.Static;\n\n /**\n * Always `static`.\n */\n type: 'static';\n }\n\n export namespace Static {\n export interface Static {\n /**\n * The number of tokens that overlap between chunks. The default value is `400`.\n *\n * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n */\n chunk_overlap_tokens: number;\n\n /**\n * The maximum number of tokens in each chunk. The default value is `800`. The\n * minimum value is `100` and the maximum value is `4096`.\n */\n max_chunk_size_tokens: number;\n }\n }\n }\n }\n }\n }\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The ID of the\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this assistant. There can be a maximum of 1 vector store attached to\n * the assistant.\n */\n vector_store_ids?: Array<string>;\n }\n }\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the initial context window of the run.\n */\n export interface TruncationStrategy {\n /**\n * The truncation strategy to use for the thread. The default is `auto`. If set to\n * `last_messages`, the thread will be truncated to the n most recent messages in\n * the thread. When set to `auto`, messages in the middle of the thread will be\n * dropped to fit the context length of the model, `max_prompt_tokens`.\n */\n type: 'auto' | 'last_messages';\n\n /**\n * The number of most recent messages from the thread when constructing the context\n * for the run.\n */\n last_messages?: number | null;\n }\n\n export type ThreadCreateAndRunParamsNonStreaming = ThreadsAPI.ThreadCreateAndRunParamsNonStreaming;\n export type ThreadCreateAndRunParamsStreaming = ThreadsAPI.ThreadCreateAndRunParamsStreaming;\n}\n\nexport interface ThreadCreateAndRunParamsNonStreaming extends ThreadCreateAndRunParamsBase {\n /**\n * If `true`, returns a stream of events that happen during the Run as server-sent\n * events, terminating when the Run enters a terminal state with a `data: [DONE]`\n * message.\n */\n stream?: false | null;\n}\n\nexport interface ThreadCreateAndRunParamsStreaming extends ThreadCreateAndRunParamsBase {\n /**\n * If `true`, returns a stream of events that happen during the Run as server-sent\n * events, terminating when the Run enters a terminal state with a `data: [DONE]`\n * message.\n */\n stream: true;\n}\n\nexport interface ThreadCreateAndRunPollParams {\n /**\n * The ID of the\n * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to\n * execute this run.\n */\n assistant_id: string;\n\n /**\n * Override the default system message of the assistant. This is useful for\n * modifying the behavior on a per-run basis.\n */\n instructions?: string | null;\n\n /**\n * The maximum number of completion tokens that may be used over the course of the\n * run. The run will make a best effort to use only the number of completion tokens\n * specified, across multiple turns of the run. If the run exceeds the number of\n * completion tokens specified, the run will end with status `incomplete`. See\n * `incomplete_details` for more info.\n */\n max_completion_tokens?: number | null;\n\n /**\n * The maximum number of prompt tokens that may be used over the course of the run.\n * The run will make a best effort to use only the number of prompt tokens\n * specified, across multiple turns of the run. If the run exceeds the number of\n * prompt tokens specified, the run will end with status `incomplete`. See\n * `incomplete_details` for more info.\n */\n max_prompt_tokens?: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format. Keys\n * can be a maximum of 64 characters long and values can be a maxium of 512\n * characters long.\n */\n metadata?: unknown | null;\n\n /**\n * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to\n * be used to execute this run. If a value is provided here, it will override the\n * model associated with the assistant. If not, the model associated with the\n * assistant will be used.\n */\n model?:\n | (string & {})\n | 'gpt-4o'\n | 'gpt-4o-2024-05-13'\n | 'gpt-4-turbo'\n | 'gpt-4-turbo-2024-04-09'\n | 'gpt-4-0125-preview'\n | 'gpt-4-turbo-preview'\n | 'gpt-4-1106-preview'\n | 'gpt-4-vision-preview'\n | 'gpt-4'\n | 'gpt-4-0314'\n | 'gpt-4-0613'\n | 'gpt-4-32k'\n | 'gpt-4-32k-0314'\n | 'gpt-4-32k-0613'\n | 'gpt-3.5-turbo'\n | 'gpt-3.5-turbo-16k'\n | 'gpt-3.5-turbo-0613'\n | 'gpt-3.5-turbo-1106'\n | 'gpt-3.5-turbo-0125'\n | 'gpt-3.5-turbo-16k-0613'\n | null;\n\n /**\n * Specifies the format that the model must output. Compatible with\n * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),\n * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),\n * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.\n *\n * Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the\n * message the model generates is valid JSON.\n *\n * **Important:** when using JSON mode, you **must** also instruct the model to\n * produce JSON yourself via a system or user message. Without this, the model may\n * generate an unending stream of whitespace until the generation reaches the token\n * limit, resulting in a long-running and seemingly \"stuck\" request. Also note that\n * the message content may be partially cut off if `finish_reason=\"length\"`, which\n * indicates the generation exceeded `max_tokens` or the conversation exceeded the\n * max context length.\n */\n response_format?: AssistantResponseFormatOption | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic.\n */\n temperature?: number | null;\n\n /**\n * If no thread is provided, an empty thread will be created.\n */\n thread?: ThreadCreateAndRunPollParams.Thread;\n\n /**\n * Controls which (if any) tool is called by the model. `none` means the model will\n * not call any tools and instead generates a message. `auto` is the default value\n * and means the model can pick between generating a message or calling one or more\n * tools. `required` means the model must call one or more tools before responding\n * to the user. Specifying a particular tool like `{\"type\": \"file_search\"}` or\n * `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to\n * call that tool.\n */\n tool_choice?: AssistantToolChoiceOption | null;\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n tool_resources?: ThreadCreateAndRunPollParams.ToolResources | null;\n\n /**\n * Override the tools the assistant can use for this run. This is useful for\n * modifying the behavior on a per-run basis.\n */\n tools?: Array<\n AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool | AssistantsAPI.FunctionTool\n > | null;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or temperature but not both.\n */\n top_p?: number | null;\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the intial context window of the run.\n */\n truncation_strategy?: ThreadCreateAndRunPollParams.TruncationStrategy | null;\n}\n\nexport namespace ThreadCreateAndRunPollParams {\n /**\n * If no thread is provided, an empty thread will be created.\n */\n export interface Thread {\n /**\n * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to\n * start the thread with.\n */\n messages?: Array<Thread.Message>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format. Keys\n * can be a maximum of 64 characters long and values can be a maxium of 512\n * characters long.\n */\n metadata?: unknown | null;\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n tool_resources?: Thread.ToolResources | null;\n }\n\n export namespace Thread {\n export interface Message {\n /**\n * The text contents of the message.\n */\n content: string | Array<MessagesAPI.MessageContentPartParam>;\n\n /**\n * The role of the entity that is creating the message. Allowed values include:\n *\n * - `user`: Indicates the message is sent by an actual user and should be used in\n * most cases to represent user-generated messages.\n * - `assistant`: Indicates the message is generated by the assistant. Use this\n * value to insert messages from the assistant into the conversation.\n */\n role: 'user' | 'assistant';\n\n /**\n * A list of files attached to the message, and the tools they should be added to.\n */\n attachments?: Array<Message.Attachment> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format. Keys\n * can be a maximum of 64 characters long and values can be a maxium of 512\n * characters long.\n */\n metadata?: unknown | null;\n }\n\n export namespace Message {\n export interface Attachment {\n /**\n * The ID of the file to attach to the message.\n */\n file_id?: string;\n\n /**\n * The tools to add this file to.\n */\n tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;\n }\n }\n\n /**\n * A set of resources that are made available to the assistant's tools in this\n * thread. The resources are specific to the type of tool. For example, the\n * `code_interpreter` tool requires a list of file IDs, while the `file_search`\n * tool requires a list of vector store IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this thread. There can be a maximum of 1 vector store attached to\n * the thread.\n */\n vector_store_ids?: Array<string>;\n\n /**\n * A helper to create a\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * with file_ids and attach it to this thread. There can be a maximum of 1 vector\n * store attached to the thread.\n */\n vector_stores?: Array<FileSearch.VectorStore>;\n }\n\n export namespace FileSearch {\n export interface VectorStore {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to\n * add to the vector store. There can be a maximum of 10000 files in a vector\n * store.\n */\n file_ids?: Array<string>;\n\n /**\n * Set of 16 key-value pairs that can be attached to a vector store. This can be\n * useful for storing additional information about the vector store in a structured\n * format. Keys can be a maximum of 64 characters long and values can be a maxium\n * of 512 characters long.\n */\n metadata?: unknown;\n }\n }\n }\n }\n\n /**\n * A set of resources that are used by the assistant's tools. The resources are\n * specific to the type of tool. For example, the `code_interpreter` tool requires\n * a list of file IDs, while the `file_search` tool requires a list of vector store\n * IDs.\n */\n export interface ToolResources {\n code_interpreter?: ToolResources.CodeInterpreter;\n\n file_search?: ToolResources.FileSearch;\n }\n\n export namespace ToolResources {\n export interface CodeInterpreter {\n /**\n * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made\n * available to the `code_interpreter` tool. There can be a maximum of 20 files\n * associated with the tool.\n */\n file_ids?: Array<string>;\n }\n\n export interface FileSearch {\n /**\n * The ID of the\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * attached to this assistant. There can be a maximum of 1 vector store attached to\n * the assistant.\n */\n vector_store_ids?: Array<string>;\n }\n }\n\n /**\n * Controls for how a thread will be truncated prior to the run. Use this to\n * control the intial context window of the run.\n */\n export interface TruncationStrategy {\n /**\n * The truncation strategy to use for the thread. The default is `auto`. If set to\n * `last_messages`, the thread will be truncated to the n most recent messages in\n * the thread. When set to `auto`, messages in the middle of the thread will be\n * dropped to fit the context length of the model, `max_prompt_tokens`.\n */\n type: 'auto' | 'last_messages';\n\n /**\n * The number of most recent messages from the thread when constructing the context\n * for the run.\n */\n last_messages?: number | null;\n }\n}\n\nexport type ThreadCreateAndRunStreamParams = ThreadCreateAndRunParamsBaseStream;\n\nThreads.Runs = Runs;\nThreads.Messages = Messages;\n\nexport declare namespace Threads {\n export {\n type AssistantResponseFormatOption as AssistantResponseFormatOption,\n type AssistantToolChoice as AssistantToolChoice,\n type AssistantToolChoiceFunction as AssistantToolChoiceFunction,\n type AssistantToolChoiceOption as AssistantToolChoiceOption,\n type Thread as Thread,\n type ThreadDeleted as ThreadDeleted,\n type ThreadCreateParams as ThreadCreateParams,\n type ThreadUpdateParams as ThreadUpdateParams,\n type ThreadCreateAndRunParams as ThreadCreateAndRunParams,\n type ThreadCreateAndRunParamsNonStreaming as ThreadCreateAndRunParamsNonStreaming,\n type ThreadCreateAndRunParamsStreaming as ThreadCreateAndRunParamsStreaming,\n type ThreadCreateAndRunPollParams,\n type ThreadCreateAndRunStreamParams,\n };\n\n export {\n Runs as Runs,\n type RequiredActionFunctionToolCall as RequiredActionFunctionToolCall,\n type Run as Run,\n type RunStatus as RunStatus,\n type RunsPage as RunsPage,\n type RunCreateParams as RunCreateParams,\n type RunCreateParamsNonStreaming as RunCreateParamsNonStreaming,\n type RunCreateParamsStreaming as RunCreateParamsStreaming,\n type RunRetrieveParams as RunRetrieveParams,\n type RunUpdateParams as RunUpdateParams,\n type RunListParams as RunListParams,\n type RunCancelParams as RunCancelParams,\n type RunCreateAndPollParams,\n type RunCreateAndStreamParams,\n type RunStreamParams,\n type RunSubmitToolOutputsParams as RunSubmitToolOutputsParams,\n type RunSubmitToolOutputsParamsNonStreaming as RunSubmitToolOutputsParamsNonStreaming,\n type RunSubmitToolOutputsParamsStreaming as RunSubmitToolOutputsParamsStreaming,\n type RunSubmitToolOutputsAndPollParams,\n type RunSubmitToolOutputsStreamParams,\n };\n\n export {\n Messages as Messages,\n type Annotation as Annotation,\n type AnnotationDelta as AnnotationDelta,\n type FileCitationAnnotation as FileCitationAnnotation,\n type FileCitationDeltaAnnotation as FileCitationDeltaAnnotation,\n type FilePathAnnotation as FilePathAnnotation,\n type FilePathDeltaAnnotation as FilePathDeltaAnnotation,\n type ImageFile as ImageFile,\n type ImageFileContentBlock as ImageFileContentBlock,\n type ImageFileDelta as ImageFileDelta,\n type ImageFileDeltaBlock as ImageFileDeltaBlock,\n type ImageURL as ImageURL,\n type ImageURLContentBlock as ImageURLContentBlock,\n type ImageURLDelta as ImageURLDelta,\n type ImageURLDeltaBlock as ImageURLDeltaBlock,\n type MessagesAPIMessage as Message,\n type MessageContent as MessageContent,\n type MessageContentDelta as MessageContentDelta,\n type MessageContentPartParam as MessageContentPartParam,\n type MessageDeleted as MessageDeleted,\n type MessageDelta as MessageDelta,\n type MessageDeltaEvent as MessageDeltaEvent,\n type RefusalContentBlock as RefusalContentBlock,\n type RefusalDeltaBlock as RefusalDeltaBlock,\n type Text as Text,\n type TextContentBlock as TextContentBlock,\n type TextContentBlockParam as TextContentBlockParam,\n type TextDelta as TextDelta,\n type TextDeltaBlock as TextDeltaBlock,\n type MessagesPage as MessagesPage,\n type MessageCreateParams as MessageCreateParams,\n type MessageRetrieveParams as MessageRetrieveParams,\n type MessageUpdateParams as MessageUpdateParams,\n type MessageListParams as MessageListParams,\n type MessageDeleteParams as MessageDeleteParams,\n };\n\n export { AssistantStream };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as AssistantsAPI from './assistants';\nimport {\n Assistant,\n AssistantCreateParams,\n AssistantDeleted,\n AssistantListParams,\n AssistantStreamEvent,\n AssistantTool,\n AssistantUpdateParams,\n Assistants,\n AssistantsPage,\n CodeInterpreterTool,\n FileSearchTool,\n FunctionTool,\n MessageStreamEvent,\n RunStepStreamEvent,\n RunStreamEvent,\n ThreadStreamEvent,\n} from './assistants';\nimport * as RealtimeAPI from './realtime/realtime';\nimport {\n ConversationCreatedEvent,\n ConversationItem,\n ConversationItemContent,\n ConversationItemCreateEvent,\n ConversationItemCreatedEvent,\n ConversationItemDeleteEvent,\n ConversationItemDeletedEvent,\n ConversationItemInputAudioTranscriptionCompletedEvent,\n ConversationItemInputAudioTranscriptionDeltaEvent,\n ConversationItemInputAudioTranscriptionFailedEvent,\n ConversationItemRetrieveEvent,\n ConversationItemTruncateEvent,\n ConversationItemTruncatedEvent,\n ConversationItemWithReference,\n ErrorEvent,\n InputAudioBufferAppendEvent,\n InputAudioBufferClearEvent,\n InputAudioBufferClearedEvent,\n InputAudioBufferCommitEvent,\n InputAudioBufferCommittedEvent,\n InputAudioBufferSpeechStartedEvent,\n InputAudioBufferSpeechStoppedEvent,\n RateLimitsUpdatedEvent,\n Realtime,\n RealtimeClientEvent,\n RealtimeResponse,\n RealtimeResponseStatus,\n RealtimeResponseUsage,\n RealtimeServerEvent,\n ResponseAudioDeltaEvent,\n ResponseAudioDoneEvent,\n ResponseAudioTranscriptDeltaEvent,\n ResponseAudioTranscriptDoneEvent,\n ResponseCancelEvent,\n ResponseContentPartAddedEvent,\n ResponseContentPartDoneEvent,\n ResponseCreateEvent,\n ResponseCreatedEvent,\n ResponseDoneEvent,\n ResponseFunctionCallArgumentsDeltaEvent,\n ResponseFunctionCallArgumentsDoneEvent,\n ResponseOutputItemAddedEvent,\n ResponseOutputItemDoneEvent,\n ResponseTextDeltaEvent,\n ResponseTextDoneEvent,\n SessionCreatedEvent,\n SessionUpdateEvent,\n SessionUpdatedEvent,\n TranscriptionSessionUpdate,\n TranscriptionSessionUpdatedEvent,\n} from './realtime/realtime';\nimport * as ChatKitAPI from './chatkit/chatkit';\nimport { ChatKit, ChatKitWorkflow } from './chatkit/chatkit';\nimport * as ThreadsAPI from './threads/threads';\nimport {\n AssistantResponseFormatOption,\n AssistantToolChoice,\n AssistantToolChoiceFunction,\n AssistantToolChoiceOption,\n Thread,\n ThreadCreateAndRunParams,\n ThreadCreateAndRunParamsNonStreaming,\n ThreadCreateAndRunParamsStreaming,\n ThreadCreateAndRunPollParams,\n ThreadCreateAndRunStreamParams,\n ThreadCreateParams,\n ThreadDeleted,\n ThreadUpdateParams,\n Threads,\n} from './threads/threads';\n\nexport class Beta extends APIResource {\n realtime: RealtimeAPI.Realtime = new RealtimeAPI.Realtime(this._client);\n chatkit: ChatKitAPI.ChatKit = new ChatKitAPI.ChatKit(this._client);\n assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this._client);\n threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);\n}\n\nBeta.Realtime = Realtime;\nBeta.ChatKit = ChatKit;\nBeta.Assistants = Assistants;\nBeta.Threads = Threads;\n\nexport declare namespace Beta {\n export {\n Realtime as Realtime,\n type ConversationCreatedEvent as ConversationCreatedEvent,\n type ConversationItem as ConversationItem,\n type ConversationItemContent as ConversationItemContent,\n type ConversationItemCreateEvent as ConversationItemCreateEvent,\n type ConversationItemCreatedEvent as ConversationItemCreatedEvent,\n type ConversationItemDeleteEvent as ConversationItemDeleteEvent,\n type ConversationItemDeletedEvent as ConversationItemDeletedEvent,\n type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent,\n type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent,\n type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent,\n type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent,\n type ConversationItemTruncateEvent as ConversationItemTruncateEvent,\n type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent,\n type ConversationItemWithReference as ConversationItemWithReference,\n type ErrorEvent as ErrorEvent,\n type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent,\n type InputAudioBufferClearEvent as InputAudioBufferClearEvent,\n type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent,\n type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent,\n type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent,\n type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent,\n type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent,\n type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent,\n type RealtimeClientEvent as RealtimeClientEvent,\n type RealtimeResponse as RealtimeResponse,\n type RealtimeResponseStatus as RealtimeResponseStatus,\n type RealtimeResponseUsage as RealtimeResponseUsage,\n type RealtimeServerEvent as RealtimeServerEvent,\n type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n type ResponseCancelEvent as ResponseCancelEvent,\n type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n type ResponseCreateEvent as ResponseCreateEvent,\n type ResponseCreatedEvent as ResponseCreatedEvent,\n type ResponseDoneEvent as ResponseDoneEvent,\n type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n type ResponseTextDoneEvent as ResponseTextDoneEvent,\n type SessionCreatedEvent as SessionCreatedEvent,\n type SessionUpdateEvent as SessionUpdateEvent,\n type SessionUpdatedEvent as SessionUpdatedEvent,\n type TranscriptionSessionUpdate as TranscriptionSessionUpdate,\n type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent,\n ChatKit as ChatKit,\n type ChatKitWorkflow as ChatKitWorkflow,\n };\n\n export {\n Assistants as Assistants,\n type Assistant as Assistant,\n type AssistantDeleted as AssistantDeleted,\n type AssistantStreamEvent as AssistantStreamEvent,\n type AssistantTool as AssistantTool,\n type CodeInterpreterTool as CodeInterpreterTool,\n type FileSearchTool as FileSearchTool,\n type FunctionTool as FunctionTool,\n type MessageStreamEvent as MessageStreamEvent,\n type RunStepStreamEvent as RunStepStreamEvent,\n type RunStreamEvent as RunStreamEvent,\n type ThreadStreamEvent as ThreadStreamEvent,\n type AssistantsPage as AssistantsPage,\n type AssistantCreateParams as AssistantCreateParams,\n type AssistantUpdateParams as AssistantUpdateParams,\n type AssistantListParams as AssistantListParams,\n };\n\n export {\n Threads as Threads,\n type AssistantResponseFormatOption as AssistantResponseFormatOption,\n type AssistantToolChoice as AssistantToolChoice,\n type AssistantToolChoiceFunction as AssistantToolChoiceFunction,\n type AssistantToolChoiceOption as AssistantToolChoiceOption,\n type Thread as Thread,\n type ThreadDeleted as ThreadDeleted,\n type ThreadCreateParams as ThreadCreateParams,\n type ThreadUpdateParams as ThreadUpdateParams,\n type ThreadCreateAndRunParams as ThreadCreateAndRunParams,\n type ThreadCreateAndRunParamsNonStreaming as ThreadCreateAndRunParamsNonStreaming,\n type ThreadCreateAndRunParamsStreaming as ThreadCreateAndRunParamsStreaming,\n type ThreadCreateAndRunPollParams,\n type ThreadCreateAndRunStreamParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport * as CompletionsAPI from './completions';\nimport * as ChatCompletionsAPI from './chat/completions/completions';\nimport { APIPromise } from '../core/api-promise';\nimport { Stream } from '../core/streaming';\nimport { RequestOptions } from '../internal/request-options';\n\n/**\n * Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.\n */\nexport class Completions extends APIResource {\n /**\n * Creates a completion for the provided prompt and parameters.\n *\n * Returns a completion object, or a sequence of completion objects if the request\n * is streamed.\n *\n * @example\n * ```ts\n * const completion = await client.completions.create({\n * model: 'string',\n * prompt: 'This is a test.',\n * });\n * ```\n */\n create(body: CompletionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Completion>;\n create(body: CompletionCreateParamsStreaming, options?: RequestOptions): APIPromise<Stream<Completion>>;\n create(\n body: CompletionCreateParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<Completion> | Completion>;\n create(\n body: CompletionCreateParams,\n options?: RequestOptions,\n ): APIPromise<Completion> | APIPromise<Stream<Completion>> {\n return this._client.post('/completions', { body, ...options, stream: body.stream ?? false }) as\n | APIPromise<Completion>\n | APIPromise<Stream<Completion>>;\n }\n}\n\n/**\n * Represents a completion response from the API. Note: both the streamed and\n * non-streamed response objects share the same shape (unlike the chat endpoint).\n */\nexport interface Completion {\n /**\n * A unique identifier for the completion.\n */\n id: string;\n\n /**\n * The list of completion choices the model generated for the input prompt.\n */\n choices: Array<CompletionChoice>;\n\n /**\n * The Unix timestamp (in seconds) of when the completion was created.\n */\n created: number;\n\n /**\n * The model used for completion.\n */\n model: string;\n\n /**\n * The object type, which is always \"text_completion\"\n */\n object: 'text_completion';\n\n /**\n * This fingerprint represents the backend configuration that the model runs with.\n *\n * Can be used in conjunction with the `seed` request parameter to understand when\n * backend changes have been made that might impact determinism.\n */\n system_fingerprint?: string;\n\n /**\n * Usage statistics for the completion request.\n */\n usage?: CompletionUsage;\n}\n\nexport interface CompletionChoice {\n /**\n * The reason the model stopped generating tokens. This will be `stop` if the model\n * hit a natural stop point or a provided stop sequence, `length` if the maximum\n * number of tokens specified in the request was reached, or `content_filter` if\n * content was omitted due to a flag from our content filters.\n */\n finish_reason: 'stop' | 'length' | 'content_filter';\n\n index: number;\n\n logprobs: CompletionChoice.Logprobs | null;\n\n text: string;\n}\n\nexport namespace CompletionChoice {\n export interface Logprobs {\n text_offset?: Array<number>;\n\n token_logprobs?: Array<number>;\n\n tokens?: Array<string>;\n\n top_logprobs?: Array<{ [key: string]: number }>;\n }\n}\n\n/**\n * Usage statistics for the completion request.\n */\nexport interface CompletionUsage {\n /**\n * Number of tokens in the generated completion.\n */\n completion_tokens: number;\n\n /**\n * Number of tokens in the prompt.\n */\n prompt_tokens: number;\n\n /**\n * Total number of tokens used in the request (prompt + completion).\n */\n total_tokens: number;\n\n /**\n * Breakdown of tokens used in a completion.\n */\n completion_tokens_details?: CompletionUsage.CompletionTokensDetails;\n\n /**\n * Breakdown of tokens used in the prompt.\n */\n prompt_tokens_details?: CompletionUsage.PromptTokensDetails;\n}\n\nexport namespace CompletionUsage {\n /**\n * Breakdown of tokens used in a completion.\n */\n export interface CompletionTokensDetails {\n /**\n * When using Predicted Outputs, the number of tokens in the prediction that\n * appeared in the completion.\n */\n accepted_prediction_tokens?: number;\n\n /**\n * Audio input tokens generated by the model.\n */\n audio_tokens?: number;\n\n /**\n * Tokens generated by the model for reasoning.\n */\n reasoning_tokens?: number;\n\n /**\n * When using Predicted Outputs, the number of tokens in the prediction that did\n * not appear in the completion. However, like reasoning tokens, these tokens are\n * still counted in the total completion tokens for purposes of billing, output,\n * and context window limits.\n */\n rejected_prediction_tokens?: number;\n }\n\n /**\n * Breakdown of tokens used in the prompt.\n */\n export interface PromptTokensDetails {\n /**\n * Audio input tokens present in the prompt.\n */\n audio_tokens?: number;\n\n /**\n * Cached tokens present in the prompt.\n */\n cached_tokens?: number;\n }\n}\n\nexport type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;\n\nexport interface CompletionCreateParamsBase {\n /**\n * ID of the model to use. You can use the\n * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n * see all of your available models, or see our\n * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n * them.\n */\n model: (string & {}) | 'gpt-3.5-turbo-instruct' | 'davinci-002' | 'babbage-002';\n\n /**\n * The prompt(s) to generate completions for, encoded as a string, array of\n * strings, array of tokens, or array of token arrays.\n *\n * Note that <|endoftext|> is the document separator that the model sees during\n * training, so if a prompt is not specified the model will generate as if from the\n * beginning of a new document.\n */\n prompt: string | Array<string> | Array<number> | Array<Array<number>> | null;\n\n /**\n * Generates `best_of` completions server-side and returns the \"best\" (the one with\n * the highest log probability per token). Results cannot be streamed.\n *\n * When used with `n`, `best_of` controls the number of candidate completions and\n * `n` specifies how many to return – `best_of` must be greater than `n`.\n *\n * **Note:** Because this parameter generates many completions, it can quickly\n * consume your token quota. Use carefully and ensure that you have reasonable\n * settings for `max_tokens` and `stop`.\n */\n best_of?: number | null;\n\n /**\n * Echo back the prompt in addition to the completion\n */\n echo?: boolean | null;\n\n /**\n * Number between -2.0 and 2.0. Positive values penalize new tokens based on their\n * existing frequency in the text so far, decreasing the model's likelihood to\n * repeat the same line verbatim.\n *\n * [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)\n */\n frequency_penalty?: number | null;\n\n /**\n * Modify the likelihood of specified tokens appearing in the completion.\n *\n * Accepts a JSON object that maps tokens (specified by their token ID in the GPT\n * tokenizer) to an associated bias value from -100 to 100. You can use this\n * [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs.\n * Mathematically, the bias is added to the logits generated by the model prior to\n * sampling. The exact effect will vary per model, but values between -1 and 1\n * should decrease or increase likelihood of selection; values like -100 or 100\n * should result in a ban or exclusive selection of the relevant token.\n *\n * As an example, you can pass `{\"50256\": -100}` to prevent the <|endoftext|> token\n * from being generated.\n */\n logit_bias?: { [key: string]: number } | null;\n\n /**\n * Include the log probabilities on the `logprobs` most likely output tokens, as\n * well the chosen tokens. For example, if `logprobs` is 5, the API will return a\n * list of the 5 most likely tokens. The API will always return the `logprob` of\n * the sampled token, so there may be up to `logprobs+1` elements in the response.\n *\n * The maximum value for `logprobs` is 5.\n */\n logprobs?: number | null;\n\n /**\n * The maximum number of [tokens](/tokenizer) that can be generated in the\n * completion.\n *\n * The token count of your prompt plus `max_tokens` cannot exceed the model's\n * context length.\n * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)\n * for counting tokens.\n */\n max_tokens?: number | null;\n\n /**\n * How many completions to generate for each prompt.\n *\n * **Note:** Because this parameter generates many completions, it can quickly\n * consume your token quota. Use carefully and ensure that you have reasonable\n * settings for `max_tokens` and `stop`.\n */\n n?: number | null;\n\n /**\n * Number between -2.0 and 2.0. Positive values penalize new tokens based on\n * whether they appear in the text so far, increasing the model's likelihood to\n * talk about new topics.\n *\n * [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/text-generation)\n */\n presence_penalty?: number | null;\n\n /**\n * If specified, our system will make a best effort to sample deterministically,\n * such that repeated requests with the same `seed` and parameters should return\n * the same result.\n *\n * Determinism is not guaranteed, and you should refer to the `system_fingerprint`\n * response parameter to monitor changes in the backend.\n */\n seed?: number | null;\n\n /**\n * Not supported with latest reasoning models `o3` and `o4-mini`.\n *\n * Up to 4 sequences where the API will stop generating further tokens. The\n * returned text will not contain the stop sequence.\n */\n stop?: string | null | Array<string>;\n\n /**\n * Whether to stream back partial progress. If set, tokens will be sent as\n * data-only\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)\n * as they become available, with the stream terminated by a `data: [DONE]`\n * message.\n * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).\n */\n stream?: boolean | null;\n\n /**\n * Options for streaming response. Only set this when you set `stream: true`.\n */\n stream_options?: ChatCompletionsAPI.ChatCompletionStreamOptions | null;\n\n /**\n * The suffix that comes after a completion of inserted text.\n *\n * This parameter is only supported for `gpt-3.5-turbo-instruct`.\n */\n suffix?: string | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic.\n *\n * We generally recommend altering this or `top_p` but not both.\n */\n temperature?: number | null;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or `temperature` but not both.\n */\n top_p?: number | null;\n\n /**\n * A unique identifier representing your end-user, which can help OpenAI to monitor\n * and detect abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n */\n user?: string;\n}\n\nexport namespace CompletionCreateParams {\n export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;\n export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;\n}\n\nexport interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {\n /**\n * Whether to stream back partial progress. If set, tokens will be sent as\n * data-only\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)\n * as they become available, with the stream terminated by a `data: [DONE]`\n * message.\n * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).\n */\n stream?: false | null;\n}\n\nexport interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {\n /**\n * Whether to stream back partial progress. If set, tokens will be sent as\n * data-only\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)\n * as they become available, with the stream terminated by a `data: [DONE]`\n * message.\n * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).\n */\n stream: true;\n}\n\nexport declare namespace Completions {\n export {\n type Completion as Completion,\n type CompletionChoice as CompletionChoice,\n type CompletionUsage as CompletionUsage,\n type CompletionCreateParams as CompletionCreateParams,\n type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,\n type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Content extends APIResource {\n /**\n * Retrieve Container File Content\n */\n retrieve(fileID: string, params: ContentRetrieveParams, options?: RequestOptions): APIPromise<Response> {\n const { container_id } = params;\n return this._client.get(path`/containers/${container_id}/files/${fileID}/content`, {\n ...options,\n headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n __binaryResponse: true,\n });\n }\n}\n\nexport interface ContentRetrieveParams {\n container_id: string;\n}\n\nexport declare namespace Content {\n export { type ContentRetrieveParams as ContentRetrieveParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ContentAPI from './content';\nimport { Content, ContentRetrieveParams } from './content';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { type Uploadable } from '../../../core/uploads';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../../../internal/uploads';\nimport { path } from '../../../internal/utils/path';\n\nexport class Files extends APIResource {\n content: ContentAPI.Content = new ContentAPI.Content(this._client);\n\n /**\n * Create a Container File\n *\n * You can send either a multipart/form-data request with the raw file content, or\n * a JSON request with a file ID.\n */\n create(\n containerID: string,\n body: FileCreateParams,\n options?: RequestOptions,\n ): APIPromise<FileCreateResponse> {\n return this._client.post(\n path`/containers/${containerID}/files`,\n maybeMultipartFormRequestOptions({ body, ...options }, this._client),\n );\n }\n\n /**\n * Retrieve Container File\n */\n retrieve(\n fileID: string,\n params: FileRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<FileRetrieveResponse> {\n const { container_id } = params;\n return this._client.get(path`/containers/${container_id}/files/${fileID}`, options);\n }\n\n /**\n * List Container files\n */\n list(\n containerID: string,\n query: FileListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<FileListResponsesPage, FileListResponse> {\n return this._client.getAPIList(path`/containers/${containerID}/files`, CursorPage<FileListResponse>, {\n query,\n ...options,\n });\n }\n\n /**\n * Delete Container File\n */\n delete(fileID: string, params: FileDeleteParams, options?: RequestOptions): APIPromise<void> {\n const { container_id } = params;\n return this._client.delete(path`/containers/${container_id}/files/${fileID}`, {\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n}\n\nexport type FileListResponsesPage = CursorPage<FileListResponse>;\n\nexport interface FileCreateResponse {\n /**\n * Unique identifier for the file.\n */\n id: string;\n\n /**\n * Size of the file in bytes.\n */\n bytes: number;\n\n /**\n * The container this file belongs to.\n */\n container_id: string;\n\n /**\n * Unix timestamp (in seconds) when the file was created.\n */\n created_at: number;\n\n /**\n * The type of this object (`container.file`).\n */\n object: 'container.file';\n\n /**\n * Path of the file in the container.\n */\n path: string;\n\n /**\n * Source of the file (e.g., `user`, `assistant`).\n */\n source: string;\n}\n\nexport interface FileRetrieveResponse {\n /**\n * Unique identifier for the file.\n */\n id: string;\n\n /**\n * Size of the file in bytes.\n */\n bytes: number;\n\n /**\n * The container this file belongs to.\n */\n container_id: string;\n\n /**\n * Unix timestamp (in seconds) when the file was created.\n */\n created_at: number;\n\n /**\n * The type of this object (`container.file`).\n */\n object: 'container.file';\n\n /**\n * Path of the file in the container.\n */\n path: string;\n\n /**\n * Source of the file (e.g., `user`, `assistant`).\n */\n source: string;\n}\n\nexport interface FileListResponse {\n /**\n * Unique identifier for the file.\n */\n id: string;\n\n /**\n * Size of the file in bytes.\n */\n bytes: number;\n\n /**\n * The container this file belongs to.\n */\n container_id: string;\n\n /**\n * Unix timestamp (in seconds) when the file was created.\n */\n created_at: number;\n\n /**\n * The type of this object (`container.file`).\n */\n object: 'container.file';\n\n /**\n * Path of the file in the container.\n */\n path: string;\n\n /**\n * Source of the file (e.g., `user`, `assistant`).\n */\n source: string;\n}\n\nexport interface FileCreateParams {\n /**\n * The File object (not file name) to be uploaded.\n */\n file?: Uploadable;\n\n /**\n * Name of the file to create.\n */\n file_id?: string;\n}\n\nexport interface FileRetrieveParams {\n container_id: string;\n}\n\nexport interface FileListParams extends CursorPageParams {\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface FileDeleteParams {\n container_id: string;\n}\n\nFiles.Content = Content;\n\nexport declare namespace Files {\n export {\n type FileCreateResponse as FileCreateResponse,\n type FileRetrieveResponse as FileRetrieveResponse,\n type FileListResponse as FileListResponse,\n type FileListResponsesPage as FileListResponsesPage,\n type FileCreateParams as FileCreateParams,\n type FileRetrieveParams as FileRetrieveParams,\n type FileListParams as FileListParams,\n type FileDeleteParams as FileDeleteParams,\n };\n\n export { Content as Content, type ContentRetrieveParams as ContentRetrieveParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ResponsesAPI from '../responses/responses';\nimport * as FilesAPI from './files/files';\nimport {\n FileCreateParams,\n FileCreateResponse,\n FileDeleteParams,\n FileListParams,\n FileListResponse,\n FileListResponsesPage,\n FileRetrieveParams,\n FileRetrieveResponse,\n Files,\n} from './files/files';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class Containers extends APIResource {\n files: FilesAPI.Files = new FilesAPI.Files(this._client);\n\n /**\n * Create Container\n */\n create(body: ContainerCreateParams, options?: RequestOptions): APIPromise<ContainerCreateResponse> {\n return this._client.post('/containers', { body, ...options });\n }\n\n /**\n * Retrieve Container\n */\n retrieve(containerID: string, options?: RequestOptions): APIPromise<ContainerRetrieveResponse> {\n return this._client.get(path`/containers/${containerID}`, options);\n }\n\n /**\n * List Containers\n */\n list(\n query: ContainerListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<ContainerListResponsesPage, ContainerListResponse> {\n return this._client.getAPIList('/containers', CursorPage<ContainerListResponse>, { query, ...options });\n }\n\n /**\n * Delete Container\n */\n delete(containerID: string, options?: RequestOptions): APIPromise<void> {\n return this._client.delete(path`/containers/${containerID}`, {\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n}\n\nexport type ContainerListResponsesPage = CursorPage<ContainerListResponse>;\n\nexport interface ContainerCreateResponse {\n /**\n * Unique identifier for the container.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the container was created.\n */\n created_at: number;\n\n /**\n * Name of the container.\n */\n name: string;\n\n /**\n * The type of this object.\n */\n object: string;\n\n /**\n * Status of the container (e.g., active, deleted).\n */\n status: string;\n\n /**\n * The container will expire after this time period. The anchor is the reference\n * point for the expiration. The minutes is the number of minutes after the anchor\n * before the container expires.\n */\n expires_after?: ContainerCreateResponse.ExpiresAfter;\n\n /**\n * Unix timestamp (in seconds) when the container was last active.\n */\n last_active_at?: number;\n\n /**\n * The memory limit configured for the container.\n */\n memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n /**\n * Network access policy for the container.\n */\n network_policy?: ContainerCreateResponse.NetworkPolicy;\n}\n\nexport namespace ContainerCreateResponse {\n /**\n * The container will expire after this time period. The anchor is the reference\n * point for the expiration. The minutes is the number of minutes after the anchor\n * before the container expires.\n */\n export interface ExpiresAfter {\n /**\n * The reference point for the expiration.\n */\n anchor?: 'last_active_at';\n\n /**\n * The number of minutes after the anchor before the container expires.\n */\n minutes?: number;\n }\n\n /**\n * Network access policy for the container.\n */\n export interface NetworkPolicy {\n /**\n * The network policy mode.\n */\n type: 'allowlist' | 'disabled';\n\n /**\n * Allowed outbound domains when `type` is `allowlist`.\n */\n allowed_domains?: Array<string>;\n }\n}\n\nexport interface ContainerRetrieveResponse {\n /**\n * Unique identifier for the container.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the container was created.\n */\n created_at: number;\n\n /**\n * Name of the container.\n */\n name: string;\n\n /**\n * The type of this object.\n */\n object: string;\n\n /**\n * Status of the container (e.g., active, deleted).\n */\n status: string;\n\n /**\n * The container will expire after this time period. The anchor is the reference\n * point for the expiration. The minutes is the number of minutes after the anchor\n * before the container expires.\n */\n expires_after?: ContainerRetrieveResponse.ExpiresAfter;\n\n /**\n * Unix timestamp (in seconds) when the container was last active.\n */\n last_active_at?: number;\n\n /**\n * The memory limit configured for the container.\n */\n memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n /**\n * Network access policy for the container.\n */\n network_policy?: ContainerRetrieveResponse.NetworkPolicy;\n}\n\nexport namespace ContainerRetrieveResponse {\n /**\n * The container will expire after this time period. The anchor is the reference\n * point for the expiration. The minutes is the number of minutes after the anchor\n * before the container expires.\n */\n export interface ExpiresAfter {\n /**\n * The reference point for the expiration.\n */\n anchor?: 'last_active_at';\n\n /**\n * The number of minutes after the anchor before the container expires.\n */\n minutes?: number;\n }\n\n /**\n * Network access policy for the container.\n */\n export interface NetworkPolicy {\n /**\n * The network policy mode.\n */\n type: 'allowlist' | 'disabled';\n\n /**\n * Allowed outbound domains when `type` is `allowlist`.\n */\n allowed_domains?: Array<string>;\n }\n}\n\nexport interface ContainerListResponse {\n /**\n * Unique identifier for the container.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the container was created.\n */\n created_at: number;\n\n /**\n * Name of the container.\n */\n name: string;\n\n /**\n * The type of this object.\n */\n object: string;\n\n /**\n * Status of the container (e.g., active, deleted).\n */\n status: string;\n\n /**\n * The container will expire after this time period. The anchor is the reference\n * point for the expiration. The minutes is the number of minutes after the anchor\n * before the container expires.\n */\n expires_after?: ContainerListResponse.ExpiresAfter;\n\n /**\n * Unix timestamp (in seconds) when the container was last active.\n */\n last_active_at?: number;\n\n /**\n * The memory limit configured for the container.\n */\n memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n /**\n * Network access policy for the container.\n */\n network_policy?: ContainerListResponse.NetworkPolicy;\n}\n\nexport namespace ContainerListResponse {\n /**\n * The container will expire after this time period. The anchor is the reference\n * point for the expiration. The minutes is the number of minutes after the anchor\n * before the container expires.\n */\n export interface ExpiresAfter {\n /**\n * The reference point for the expiration.\n */\n anchor?: 'last_active_at';\n\n /**\n * The number of minutes after the anchor before the container expires.\n */\n minutes?: number;\n }\n\n /**\n * Network access policy for the container.\n */\n export interface NetworkPolicy {\n /**\n * The network policy mode.\n */\n type: 'allowlist' | 'disabled';\n\n /**\n * Allowed outbound domains when `type` is `allowlist`.\n */\n allowed_domains?: Array<string>;\n }\n}\n\nexport interface ContainerCreateParams {\n /**\n * Name of the container to create.\n */\n name: string;\n\n /**\n * Container expiration time in seconds relative to the 'anchor' time.\n */\n expires_after?: ContainerCreateParams.ExpiresAfter;\n\n /**\n * IDs of files to copy to the container.\n */\n file_ids?: Array<string>;\n\n /**\n * Optional memory limit for the container. Defaults to \"1g\".\n */\n memory_limit?: '1g' | '4g' | '16g' | '64g';\n\n /**\n * Network access policy for the container.\n */\n network_policy?: ResponsesAPI.ContainerNetworkPolicyDisabled | ResponsesAPI.ContainerNetworkPolicyAllowlist;\n\n /**\n * An optional list of skills referenced by id or inline data.\n */\n skills?: Array<ResponsesAPI.SkillReference | ResponsesAPI.InlineSkill>;\n}\n\nexport namespace ContainerCreateParams {\n /**\n * Container expiration time in seconds relative to the 'anchor' time.\n */\n export interface ExpiresAfter {\n /**\n * Time anchor for the expiration time. Currently only 'last_active_at' is\n * supported.\n */\n anchor: 'last_active_at';\n\n minutes: number;\n }\n}\n\nexport interface ContainerListParams extends CursorPageParams {\n /**\n * Filter results by container name.\n */\n name?: string;\n\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nContainers.Files = Files;\n\nexport declare namespace Containers {\n export {\n type ContainerCreateResponse as ContainerCreateResponse,\n type ContainerRetrieveResponse as ContainerRetrieveResponse,\n type ContainerListResponse as ContainerListResponse,\n type ContainerListResponsesPage as ContainerListResponsesPage,\n type ContainerCreateParams as ContainerCreateParams,\n type ContainerListParams as ContainerListParams,\n };\n\n export {\n Files as Files,\n type FileCreateResponse as FileCreateResponse,\n type FileRetrieveResponse as FileRetrieveResponse,\n type FileListResponse as FileListResponse,\n type FileListResponsesPage as FileListResponsesPage,\n type FileCreateParams as FileCreateParams,\n type FileRetrieveParams as FileRetrieveParams,\n type FileListParams as FileListParams,\n type FileDeleteParams as FileDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ConversationsAPI from './conversations';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport {\n ConversationCursorPage,\n type ConversationCursorPageParams,\n PagePromise,\n} from '../../core/pagination';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Manage conversations and conversation items.\n */\nexport class Items extends APIResource {\n /**\n * Create items in a conversation with the given ID.\n */\n create(\n conversationID: string,\n params: ItemCreateParams,\n options?: RequestOptions,\n ): APIPromise<ConversationItemList> {\n const { include, ...body } = params;\n return this._client.post(path`/conversations/${conversationID}/items`, {\n query: { include },\n body,\n ...options,\n });\n }\n\n /**\n * Get a single item from a conversation with the given IDs.\n */\n retrieve(\n itemID: string,\n params: ItemRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<ConversationItem> {\n const { conversation_id, ...query } = params;\n return this._client.get(path`/conversations/${conversation_id}/items/${itemID}`, { query, ...options });\n }\n\n /**\n * List all items for a conversation with the given ID.\n */\n list(\n conversationID: string,\n query: ItemListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<ConversationItemsPage, ConversationItem> {\n return this._client.getAPIList(\n path`/conversations/${conversationID}/items`,\n ConversationCursorPage<ConversationItem>,\n { query, ...options },\n );\n }\n\n /**\n * Delete an item from a conversation with the given IDs.\n */\n delete(\n itemID: string,\n params: ItemDeleteParams,\n options?: RequestOptions,\n ): APIPromise<ConversationsAPI.Conversation> {\n const { conversation_id } = params;\n return this._client.delete(path`/conversations/${conversation_id}/items/${itemID}`, options);\n }\n}\n\nexport type ConversationItemsPage = ConversationCursorPage<ConversationItem>;\n\n/**\n * A single item within a conversation. The set of possible types are the same as\n * the `output` type of a\n * [Response object](https://platform.openai.com/docs/api-reference/responses/object#responses/object-output).\n */\nexport type ConversationItem =\n | ConversationsAPI.Message\n | ResponsesAPI.ResponseFunctionToolCallItem\n | ResponsesAPI.ResponseFunctionToolCallOutputItem\n | ResponsesAPI.ResponseFileSearchToolCall\n | ResponsesAPI.ResponseFunctionWebSearch\n | ConversationItem.ImageGenerationCall\n | ResponsesAPI.ResponseComputerToolCall\n | ResponsesAPI.ResponseComputerToolCallOutputItem\n | ResponsesAPI.ResponseToolSearchCall\n | ResponsesAPI.ResponseToolSearchOutputItem\n | ResponsesAPI.ResponseReasoningItem\n | ResponsesAPI.ResponseCodeInterpreterToolCall\n | ConversationItem.LocalShellCall\n | ConversationItem.LocalShellCallOutput\n | ResponsesAPI.ResponseFunctionShellToolCall\n | ResponsesAPI.ResponseFunctionShellToolCallOutput\n | ResponsesAPI.ResponseApplyPatchToolCall\n | ResponsesAPI.ResponseApplyPatchToolCallOutput\n | ConversationItem.McpListTools\n | ConversationItem.McpApprovalRequest\n | ConversationItem.McpApprovalResponse\n | ConversationItem.McpCall\n | ResponsesAPI.ResponseCustomToolCall\n | ResponsesAPI.ResponseCustomToolCallOutput;\n\nexport namespace ConversationItem {\n /**\n * An image generation request made by the model.\n */\n export interface ImageGenerationCall {\n /**\n * The unique ID of the image generation call.\n */\n id: string;\n\n /**\n * The generated image encoded in base64.\n */\n result: string | null;\n\n /**\n * The status of the image generation call.\n */\n status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n /**\n * The type of the image generation call. Always `image_generation_call`.\n */\n type: 'image_generation_call';\n }\n\n /**\n * A tool call to run a command on the local shell.\n */\n export interface LocalShellCall {\n /**\n * The unique ID of the local shell call.\n */\n id: string;\n\n /**\n * Execute a shell command on the server.\n */\n action: LocalShellCall.Action;\n\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The status of the local shell call.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the local shell call. Always `local_shell_call`.\n */\n type: 'local_shell_call';\n }\n\n export namespace LocalShellCall {\n /**\n * Execute a shell command on the server.\n */\n export interface Action {\n /**\n * The command to run.\n */\n command: Array<string>;\n\n /**\n * Environment variables to set for the command.\n */\n env: { [key: string]: string };\n\n /**\n * The type of the local shell action. Always `exec`.\n */\n type: 'exec';\n\n /**\n * Optional timeout in milliseconds for the command.\n */\n timeout_ms?: number | null;\n\n /**\n * Optional user to run the command as.\n */\n user?: string | null;\n\n /**\n * Optional working directory to run the command in.\n */\n working_directory?: string | null;\n }\n }\n\n /**\n * The output of a local shell tool call.\n */\n export interface LocalShellCallOutput {\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n id: string;\n\n /**\n * A JSON string of the output of the local shell tool call.\n */\n output: string;\n\n /**\n * The type of the local shell tool call output. Always `local_shell_call_output`.\n */\n type: 'local_shell_call_output';\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n /**\n * A list of tools available on an MCP server.\n */\n export interface McpListTools {\n /**\n * The unique ID of the list.\n */\n id: string;\n\n /**\n * The label of the MCP server.\n */\n server_label: string;\n\n /**\n * The tools available on the server.\n */\n tools: Array<McpListTools.Tool>;\n\n /**\n * The type of the item. Always `mcp_list_tools`.\n */\n type: 'mcp_list_tools';\n\n /**\n * Error message if the server could not list tools.\n */\n error?: string | null;\n }\n\n export namespace McpListTools {\n /**\n * A tool available on an MCP server.\n */\n export interface Tool {\n /**\n * The JSON schema describing the tool's input.\n */\n input_schema: unknown;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * Additional annotations about the tool.\n */\n annotations?: unknown | null;\n\n /**\n * The description of the tool.\n */\n description?: string | null;\n }\n }\n\n /**\n * A request for human approval of a tool invocation.\n */\n export interface McpApprovalRequest {\n /**\n * The unique ID of the approval request.\n */\n id: string;\n\n /**\n * A JSON string of arguments for the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool to run.\n */\n name: string;\n\n /**\n * The label of the MCP server making the request.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_approval_request`.\n */\n type: 'mcp_approval_request';\n }\n\n /**\n * A response to an MCP approval request.\n */\n export interface McpApprovalResponse {\n /**\n * The unique ID of the approval response\n */\n id: string;\n\n /**\n * The ID of the approval request being answered.\n */\n approval_request_id: string;\n\n /**\n * Whether the request was approved.\n */\n approve: boolean;\n\n /**\n * The type of the item. Always `mcp_approval_response`.\n */\n type: 'mcp_approval_response';\n\n /**\n * Optional reason for the decision.\n */\n reason?: string | null;\n }\n\n /**\n * An invocation of a tool on an MCP server.\n */\n export interface McpCall {\n /**\n * The unique ID of the tool call.\n */\n id: string;\n\n /**\n * A JSON string of the arguments passed to the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool that was run.\n */\n name: string;\n\n /**\n * The label of the MCP server running the tool.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_call`.\n */\n type: 'mcp_call';\n\n /**\n * Unique identifier for the MCP tool call approval request. Include this value in\n * a subsequent `mcp_approval_response` input to approve or reject the\n * corresponding tool call.\n */\n approval_request_id?: string | null;\n\n /**\n * The error from the tool call, if any.\n */\n error?: string | null;\n\n /**\n * The output from the tool call.\n */\n output?: string | null;\n\n /**\n * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n * `calling`, or `failed`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n }\n}\n\n/**\n * A list of Conversation items.\n */\nexport interface ConversationItemList {\n /**\n * A list of conversation items.\n */\n data: Array<ConversationItem>;\n\n /**\n * The ID of the first item in the list.\n */\n first_id: string;\n\n /**\n * Whether there are more items available.\n */\n has_more: boolean;\n\n /**\n * The ID of the last item in the list.\n */\n last_id: string;\n\n /**\n * The type of object returned, must be `list`.\n */\n object: 'list';\n}\n\nexport interface ItemCreateParams {\n /**\n * Body param: The items to add to the conversation. You may add up to 20 items at\n * a time.\n */\n items: Array<ResponsesAPI.ResponseInputItem>;\n\n /**\n * Query param: Additional fields to include in the response. See the `include`\n * parameter for\n * [listing Conversation items above](https://platform.openai.com/docs/api-reference/conversations/list-items#conversations_list_items-include)\n * for more information.\n */\n include?: Array<ResponsesAPI.ResponseIncludable>;\n}\n\nexport interface ItemRetrieveParams {\n /**\n * Path param: The ID of the conversation that contains the item.\n */\n conversation_id: string;\n\n /**\n * Query param: Additional fields to include in the response. See the `include`\n * parameter for\n * [listing Conversation items above](https://platform.openai.com/docs/api-reference/conversations/list-items#conversations_list_items-include)\n * for more information.\n */\n include?: Array<ResponsesAPI.ResponseIncludable>;\n}\n\nexport interface ItemListParams extends ConversationCursorPageParams {\n /**\n * Specify additional output data to include in the model response. Currently\n * supported values are:\n *\n * - `web_search_call.action.sources`: Include the sources of the web search tool\n * call.\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n * in code interpreter tool call items.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n * call output.\n * - `file_search_call.results`: Include the search results of the file search tool\n * call.\n * - `message.input_image.image_url`: Include image urls from the input message.\n * - `message.output_text.logprobs`: Include logprobs with assistant messages.\n * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n * tokens in reasoning item outputs. This enables reasoning items to be used in\n * multi-turn conversations when using the Responses API statelessly (like when\n * the `store` parameter is set to `false`, or when an organization is enrolled\n * in the zero data retention program).\n */\n include?: Array<ResponsesAPI.ResponseIncludable>;\n\n /**\n * The order to return the input items in. Default is `desc`.\n *\n * - `asc`: Return the input items in ascending order.\n * - `desc`: Return the input items in descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface ItemDeleteParams {\n /**\n * The ID of the conversation that contains the item.\n */\n conversation_id: string;\n}\n\nexport declare namespace Items {\n export {\n type ConversationItem as ConversationItem,\n type ConversationItemList as ConversationItemList,\n type ConversationItemsPage as ConversationItemsPage,\n type ItemCreateParams as ItemCreateParams,\n type ItemRetrieveParams as ItemRetrieveParams,\n type ItemListParams as ItemListParams,\n type ItemDeleteParams as ItemDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as ItemsAPI from './items';\nimport {\n ConversationItem,\n ConversationItemList,\n ConversationItemsPage,\n ItemCreateParams,\n ItemDeleteParams,\n ItemListParams,\n ItemRetrieveParams,\n Items,\n} from './items';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Manage conversations and conversation items.\n */\nexport class Conversations extends APIResource {\n items: ItemsAPI.Items = new ItemsAPI.Items(this._client);\n\n /**\n * Create a conversation.\n */\n create(\n body: ConversationCreateParams | null | undefined = {},\n options?: RequestOptions,\n ): APIPromise<Conversation> {\n return this._client.post('/conversations', { body, ...options });\n }\n\n /**\n * Get a conversation\n */\n retrieve(conversationID: string, options?: RequestOptions): APIPromise<Conversation> {\n return this._client.get(path`/conversations/${conversationID}`, options);\n }\n\n /**\n * Update a conversation\n */\n update(\n conversationID: string,\n body: ConversationUpdateParams,\n options?: RequestOptions,\n ): APIPromise<Conversation> {\n return this._client.post(path`/conversations/${conversationID}`, { body, ...options });\n }\n\n /**\n * Delete a conversation. Items in the conversation will not be deleted.\n */\n delete(conversationID: string, options?: RequestOptions): APIPromise<ConversationDeletedResource> {\n return this._client.delete(path`/conversations/${conversationID}`, options);\n }\n}\n\n/**\n * A screenshot of a computer.\n */\nexport interface ComputerScreenshotContent {\n /**\n * The detail level of the screenshot image to be sent to the model. One of `high`,\n * `low`, `auto`, or `original`. Defaults to `auto`.\n */\n detail: 'low' | 'high' | 'auto' | 'original';\n\n /**\n * The identifier of an uploaded file that contains the screenshot.\n */\n file_id: string | null;\n\n /**\n * The URL of the screenshot image.\n */\n image_url: string | null;\n\n /**\n * Specifies the event type. For a computer screenshot, this property is always set\n * to `computer_screenshot`.\n */\n type: 'computer_screenshot';\n}\n\nexport interface Conversation {\n /**\n * The unique ID of the conversation.\n */\n id: string;\n\n /**\n * The time at which the conversation was created, measured in seconds since the\n * Unix epoch.\n */\n created_at: number;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters.\n */\n metadata: unknown;\n\n /**\n * The object type, which is always `conversation`.\n */\n object: 'conversation';\n}\n\nexport interface ConversationDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'conversation.deleted';\n}\n\nexport interface ConversationDeletedResource {\n id: string;\n\n deleted: boolean;\n\n object: 'conversation.deleted';\n}\n\n/**\n * A message to or from the model.\n */\nexport interface Message {\n /**\n * The unique ID of the message.\n */\n id: string;\n\n /**\n * The content of the message\n */\n content: Array<\n | ResponsesAPI.ResponseInputText\n | ResponsesAPI.ResponseOutputText\n | TextContent\n | SummaryTextContent\n | Message.ReasoningText\n | ResponsesAPI.ResponseOutputRefusal\n | ResponsesAPI.ResponseInputImage\n | ComputerScreenshotContent\n | ResponsesAPI.ResponseInputFile\n >;\n\n /**\n * The role of the message. One of `unknown`, `user`, `assistant`, `system`,\n * `critic`, `discriminator`, `developer`, or `tool`.\n */\n role: 'unknown' | 'user' | 'assistant' | 'system' | 'critic' | 'discriminator' | 'developer' | 'tool';\n\n /**\n * The status of item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the message. Always set to `message`.\n */\n type: 'message';\n}\n\nexport namespace Message {\n /**\n * Reasoning text from the model.\n */\n export interface ReasoningText {\n /**\n * The reasoning text from the model.\n */\n text: string;\n\n /**\n * The type of the reasoning text. Always `reasoning_text`.\n */\n type: 'reasoning_text';\n }\n}\n\n/**\n * A summary text from the model.\n */\nexport interface SummaryTextContent {\n /**\n * A summary of the reasoning output from the model so far.\n */\n text: string;\n\n /**\n * The type of the object. Always `summary_text`.\n */\n type: 'summary_text';\n}\n\n/**\n * A text content.\n */\nexport interface TextContent {\n text: string;\n\n type: 'text';\n}\n\nexport type InputTextContent = ResponsesAPI.ResponseInputText;\n\nexport type OutputTextContent = ResponsesAPI.ResponseOutputText;\n\nexport type RefusalContent = ResponsesAPI.ResponseOutputRefusal;\n\nexport type InputImageContent = ResponsesAPI.ResponseInputImage;\n\nexport type InputFileContent = ResponsesAPI.ResponseInputFile;\n\nexport interface ConversationCreateParams {\n /**\n * Initial items to include in the conversation context. You may add up to 20 items\n * at a time.\n */\n items?: Array<ResponsesAPI.ResponseInputItem> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n}\n\nexport interface ConversationUpdateParams {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n}\n\nConversations.Items = Items;\n\nexport declare namespace Conversations {\n export {\n type ComputerScreenshotContent as ComputerScreenshotContent,\n type Conversation as Conversation,\n type ConversationDeleted as ConversationDeleted,\n type ConversationDeletedResource as ConversationDeletedResource,\n type Message as Message,\n type SummaryTextContent as SummaryTextContent,\n type TextContent as TextContent,\n type InputTextContent as InputTextContent,\n type OutputTextContent as OutputTextContent,\n type RefusalContent as RefusalContent,\n type InputImageContent as InputImageContent,\n type InputFileContent as InputFileContent,\n type ConversationCreateParams as ConversationCreateParams,\n type ConversationUpdateParams as ConversationUpdateParams,\n };\n\n export {\n Items as Items,\n type ConversationItem as ConversationItem,\n type ConversationItemList as ConversationItemList,\n type ConversationItemsPage as ConversationItemsPage,\n type ItemCreateParams as ItemCreateParams,\n type ItemRetrieveParams as ItemRetrieveParams,\n type ItemListParams as ItemListParams,\n type ItemDeleteParams as ItemDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { RequestOptions } from '../internal/request-options';\nimport { loggerFor, toFloat32Array } from '../internal/utils';\n\n/**\n * Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.\n */\nexport class Embeddings extends APIResource {\n /**\n * Creates an embedding vector representing the input text.\n *\n * @example\n * ```ts\n * const createEmbeddingResponse =\n * await client.embeddings.create({\n * input: 'The quick brown fox jumped over the lazy dog',\n * model: 'text-embedding-3-small',\n * });\n * ```\n */\n create(body: EmbeddingCreateParams, options?: RequestOptions): APIPromise<CreateEmbeddingResponse> {\n const hasUserProvidedEncodingFormat = !!body.encoding_format;\n // No encoding_format specified, defaulting to base64 for performance reasons\n // See https://github.com/openai/openai-node/pull/1312\n let encoding_format: EmbeddingCreateParams['encoding_format'] =\n hasUserProvidedEncodingFormat ? body.encoding_format : 'base64';\n\n if (hasUserProvidedEncodingFormat) {\n loggerFor(this._client).debug('embeddings/user defined encoding_format:', body.encoding_format);\n }\n\n const response: APIPromise<CreateEmbeddingResponse> = this._client.post('/embeddings', {\n body: {\n ...body,\n encoding_format: encoding_format as EmbeddingCreateParams['encoding_format'],\n },\n ...options,\n });\n\n // if the user specified an encoding_format, return the response as-is\n if (hasUserProvidedEncodingFormat) {\n return response;\n }\n\n // in this stage, we are sure the user did not specify an encoding_format\n // and we defaulted to base64 for performance reasons\n // we are sure then that the response is base64 encoded, let's decode it\n // the returned result will be a float32 array since this is OpenAI API's default encoding\n loggerFor(this._client).debug('embeddings/decoding base64 embeddings from base64');\n\n return (response as APIPromise<CreateEmbeddingResponse>)._thenUnwrap((response) => {\n if (response && response.data) {\n response.data.forEach((embeddingBase64Obj) => {\n const embeddingBase64Str = embeddingBase64Obj.embedding as unknown as string;\n embeddingBase64Obj.embedding = toFloat32Array(embeddingBase64Str);\n });\n }\n\n return response;\n });\n }\n}\n\nexport interface CreateEmbeddingResponse {\n /**\n * The list of embeddings generated by the model.\n */\n data: Array<Embedding>;\n\n /**\n * The name of the model used to generate the embedding.\n */\n model: string;\n\n /**\n * The object type, which is always \"list\".\n */\n object: 'list';\n\n /**\n * The usage information for the request.\n */\n usage: CreateEmbeddingResponse.Usage;\n}\n\nexport namespace CreateEmbeddingResponse {\n /**\n * The usage information for the request.\n */\n export interface Usage {\n /**\n * The number of tokens used by the prompt.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used by the request.\n */\n total_tokens: number;\n }\n}\n\n/**\n * Represents an embedding vector returned by embedding endpoint.\n */\nexport interface Embedding {\n /**\n * The embedding vector, which is a list of floats. The length of vector depends on\n * the model as listed in the\n * [embedding guide](https://platform.openai.com/docs/guides/embeddings).\n */\n embedding: Array<number>;\n\n /**\n * The index of the embedding in the list of embeddings.\n */\n index: number;\n\n /**\n * The object type, which is always \"embedding\".\n */\n object: 'embedding';\n}\n\nexport type EmbeddingModel = 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large';\n\nexport interface EmbeddingCreateParams {\n /**\n * Input text to embed, encoded as a string or array of tokens. To embed multiple\n * inputs in a single request, pass an array of strings or array of token arrays.\n * The input must not exceed the max input tokens for the model (8192 tokens for\n * all embedding models), cannot be an empty string, and any array must be 2048\n * dimensions or less.\n * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)\n * for counting tokens. In addition to the per-input token limit, all embedding\n * models enforce a maximum of 300,000 tokens summed across all inputs in a single\n * request.\n */\n input: string | Array<string> | Array<number> | Array<Array<number>>;\n\n /**\n * ID of the model to use. You can use the\n * [List models](https://platform.openai.com/docs/api-reference/models/list) API to\n * see all of your available models, or see our\n * [Model overview](https://platform.openai.com/docs/models) for descriptions of\n * them.\n */\n model: (string & {}) | EmbeddingModel;\n\n /**\n * The number of dimensions the resulting output embeddings should have. Only\n * supported in `text-embedding-3` and later models.\n */\n dimensions?: number;\n\n /**\n * The format to return the embeddings in. Can be either `float` or\n * [`base64`](https://pypi.org/project/pybase64/).\n */\n encoding_format?: 'float' | 'base64';\n\n /**\n * A unique identifier representing your end-user, which can help OpenAI to monitor\n * and detect abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n */\n user?: string;\n}\n\nexport declare namespace Embeddings {\n export {\n type CreateEmbeddingResponse as CreateEmbeddingResponse,\n type Embedding as Embedding,\n type EmbeddingModel as EmbeddingModel,\n type EmbeddingCreateParams as EmbeddingCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as RunsAPI from './runs';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage and run evals in the OpenAI platform.\n */\nexport class OutputItems extends APIResource {\n /**\n * Get an evaluation run output item by ID.\n */\n retrieve(\n outputItemID: string,\n params: OutputItemRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<OutputItemRetrieveResponse> {\n const { eval_id, run_id } = params;\n return this._client.get(path`/evals/${eval_id}/runs/${run_id}/output_items/${outputItemID}`, options);\n }\n\n /**\n * Get a list of output items for an evaluation run.\n */\n list(\n runID: string,\n params: OutputItemListParams,\n options?: RequestOptions,\n ): PagePromise<OutputItemListResponsesPage, OutputItemListResponse> {\n const { eval_id, ...query } = params;\n return this._client.getAPIList(\n path`/evals/${eval_id}/runs/${runID}/output_items`,\n CursorPage<OutputItemListResponse>,\n { query, ...options },\n );\n }\n}\n\nexport type OutputItemListResponsesPage = CursorPage<OutputItemListResponse>;\n\n/**\n * A schema representing an evaluation run output item.\n */\nexport interface OutputItemRetrieveResponse {\n /**\n * Unique identifier for the evaluation run output item.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the evaluation run was created.\n */\n created_at: number;\n\n /**\n * Details of the input data source item.\n */\n datasource_item: { [key: string]: unknown };\n\n /**\n * The identifier for the data source item.\n */\n datasource_item_id: number;\n\n /**\n * The identifier of the evaluation group.\n */\n eval_id: string;\n\n /**\n * The type of the object. Always \"eval.run.output_item\".\n */\n object: 'eval.run.output_item';\n\n /**\n * A list of grader results for this output item.\n */\n results: Array<OutputItemRetrieveResponse.Result>;\n\n /**\n * The identifier of the evaluation run associated with this output item.\n */\n run_id: string;\n\n /**\n * A sample containing the input and output of the evaluation run.\n */\n sample: OutputItemRetrieveResponse.Sample;\n\n /**\n * The status of the evaluation run.\n */\n status: string;\n}\n\nexport namespace OutputItemRetrieveResponse {\n /**\n * A single grader result for an evaluation run output item.\n */\n export interface Result {\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * Whether the grader considered the output a pass.\n */\n passed: boolean;\n\n /**\n * The numeric score produced by the grader.\n */\n score: number;\n\n /**\n * Optional sample or intermediate data produced by the grader.\n */\n sample?: { [key: string]: unknown } | null;\n\n /**\n * The grader type (for example, \"string-check-grader\").\n */\n type?: string;\n\n [k: string]: unknown;\n }\n\n /**\n * A sample containing the input and output of the evaluation run.\n */\n export interface Sample {\n /**\n * An object representing an error response from the Eval API.\n */\n error: RunsAPI.EvalAPIError;\n\n /**\n * The reason why the sample generation was finished.\n */\n finish_reason: string;\n\n /**\n * An array of input messages.\n */\n input: Array<Sample.Input>;\n\n /**\n * The maximum number of tokens allowed for completion.\n */\n max_completion_tokens: number;\n\n /**\n * The model used for generating the sample.\n */\n model: string;\n\n /**\n * An array of output messages.\n */\n output: Array<Sample.Output>;\n\n /**\n * The seed used for generating the sample.\n */\n seed: number;\n\n /**\n * The sampling temperature used.\n */\n temperature: number;\n\n /**\n * The top_p value used for sampling.\n */\n top_p: number;\n\n /**\n * Token usage details for the sample.\n */\n usage: Sample.Usage;\n }\n\n export namespace Sample {\n /**\n * An input message.\n */\n export interface Input {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message sender (e.g., system, user, developer).\n */\n role: string;\n }\n\n export interface Output {\n /**\n * The content of the message.\n */\n content?: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role?: string;\n }\n\n /**\n * Token usage details for the sample.\n */\n export interface Usage {\n /**\n * The number of tokens retrieved from cache.\n */\n cached_tokens: number;\n\n /**\n * The number of completion tokens generated.\n */\n completion_tokens: number;\n\n /**\n * The number of prompt tokens used.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n }\n }\n}\n\n/**\n * A schema representing an evaluation run output item.\n */\nexport interface OutputItemListResponse {\n /**\n * Unique identifier for the evaluation run output item.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the evaluation run was created.\n */\n created_at: number;\n\n /**\n * Details of the input data source item.\n */\n datasource_item: { [key: string]: unknown };\n\n /**\n * The identifier for the data source item.\n */\n datasource_item_id: number;\n\n /**\n * The identifier of the evaluation group.\n */\n eval_id: string;\n\n /**\n * The type of the object. Always \"eval.run.output_item\".\n */\n object: 'eval.run.output_item';\n\n /**\n * A list of grader results for this output item.\n */\n results: Array<OutputItemListResponse.Result>;\n\n /**\n * The identifier of the evaluation run associated with this output item.\n */\n run_id: string;\n\n /**\n * A sample containing the input and output of the evaluation run.\n */\n sample: OutputItemListResponse.Sample;\n\n /**\n * The status of the evaluation run.\n */\n status: string;\n}\n\nexport namespace OutputItemListResponse {\n /**\n * A single grader result for an evaluation run output item.\n */\n export interface Result {\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * Whether the grader considered the output a pass.\n */\n passed: boolean;\n\n /**\n * The numeric score produced by the grader.\n */\n score: number;\n\n /**\n * Optional sample or intermediate data produced by the grader.\n */\n sample?: { [key: string]: unknown } | null;\n\n /**\n * The grader type (for example, \"string-check-grader\").\n */\n type?: string;\n\n [k: string]: unknown;\n }\n\n /**\n * A sample containing the input and output of the evaluation run.\n */\n export interface Sample {\n /**\n * An object representing an error response from the Eval API.\n */\n error: RunsAPI.EvalAPIError;\n\n /**\n * The reason why the sample generation was finished.\n */\n finish_reason: string;\n\n /**\n * An array of input messages.\n */\n input: Array<Sample.Input>;\n\n /**\n * The maximum number of tokens allowed for completion.\n */\n max_completion_tokens: number;\n\n /**\n * The model used for generating the sample.\n */\n model: string;\n\n /**\n * An array of output messages.\n */\n output: Array<Sample.Output>;\n\n /**\n * The seed used for generating the sample.\n */\n seed: number;\n\n /**\n * The sampling temperature used.\n */\n temperature: number;\n\n /**\n * The top_p value used for sampling.\n */\n top_p: number;\n\n /**\n * Token usage details for the sample.\n */\n usage: Sample.Usage;\n }\n\n export namespace Sample {\n /**\n * An input message.\n */\n export interface Input {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message sender (e.g., system, user, developer).\n */\n role: string;\n }\n\n export interface Output {\n /**\n * The content of the message.\n */\n content?: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role?: string;\n }\n\n /**\n * Token usage details for the sample.\n */\n export interface Usage {\n /**\n * The number of tokens retrieved from cache.\n */\n cached_tokens: number;\n\n /**\n * The number of completion tokens generated.\n */\n completion_tokens: number;\n\n /**\n * The number of prompt tokens used.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n }\n }\n}\n\nexport interface OutputItemRetrieveParams {\n /**\n * The ID of the evaluation to retrieve runs for.\n */\n eval_id: string;\n\n /**\n * The ID of the run to retrieve.\n */\n run_id: string;\n}\n\nexport interface OutputItemListParams extends CursorPageParams {\n /**\n * Path param: The ID of the evaluation to retrieve runs for.\n */\n eval_id: string;\n\n /**\n * Query param: Sort order for output items by timestamp. Use `asc` for ascending\n * order or `desc` for descending order. Defaults to `asc`.\n */\n order?: 'asc' | 'desc';\n\n /**\n * Query param: Filter output items by status. Use `failed` to filter by failed\n * output items or `pass` to filter by passed output items.\n */\n status?: 'fail' | 'pass';\n}\n\nexport declare namespace OutputItems {\n export {\n type OutputItemRetrieveResponse as OutputItemRetrieveResponse,\n type OutputItemListResponse as OutputItemListResponse,\n type OutputItemListResponsesPage as OutputItemListResponsesPage,\n type OutputItemRetrieveParams as OutputItemRetrieveParams,\n type OutputItemListParams as OutputItemListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as Shared from '../../shared';\nimport * as GraderModelsAPI from '../../graders/grader-models';\nimport * as ResponsesAPI from '../../responses/responses';\nimport * as CompletionsAPI from '../../chat/completions/completions';\nimport * as OutputItemsAPI from './output-items';\nimport {\n OutputItemListParams,\n OutputItemListResponse,\n OutputItemListResponsesPage,\n OutputItemRetrieveParams,\n OutputItemRetrieveResponse,\n OutputItems,\n} from './output-items';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage and run evals in the OpenAI platform.\n */\nexport class Runs extends APIResource {\n outputItems: OutputItemsAPI.OutputItems = new OutputItemsAPI.OutputItems(this._client);\n\n /**\n * Kicks off a new run for a given evaluation, specifying the data source, and what\n * model configuration to use to test. The datasource will be validated against the\n * schema specified in the config of the evaluation.\n */\n create(evalID: string, body: RunCreateParams, options?: RequestOptions): APIPromise<RunCreateResponse> {\n return this._client.post(path`/evals/${evalID}/runs`, { body, ...options });\n }\n\n /**\n * Get an evaluation run by ID.\n */\n retrieve(\n runID: string,\n params: RunRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<RunRetrieveResponse> {\n const { eval_id } = params;\n return this._client.get(path`/evals/${eval_id}/runs/${runID}`, options);\n }\n\n /**\n * Get a list of runs for an evaluation.\n */\n list(\n evalID: string,\n query: RunListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<RunListResponsesPage, RunListResponse> {\n return this._client.getAPIList(path`/evals/${evalID}/runs`, CursorPage<RunListResponse>, {\n query,\n ...options,\n });\n }\n\n /**\n * Delete an eval run.\n */\n delete(runID: string, params: RunDeleteParams, options?: RequestOptions): APIPromise<RunDeleteResponse> {\n const { eval_id } = params;\n return this._client.delete(path`/evals/${eval_id}/runs/${runID}`, options);\n }\n\n /**\n * Cancel an ongoing evaluation run.\n */\n cancel(runID: string, params: RunCancelParams, options?: RequestOptions): APIPromise<RunCancelResponse> {\n const { eval_id } = params;\n return this._client.post(path`/evals/${eval_id}/runs/${runID}`, options);\n }\n}\n\nexport type RunListResponsesPage = CursorPage<RunListResponse>;\n\n/**\n * A CompletionsRunDataSource object describing a model sampling configuration.\n */\nexport interface CreateEvalCompletionsRunDataSource {\n /**\n * Determines what populates the `item` namespace in this run's data source.\n */\n source:\n | CreateEvalCompletionsRunDataSource.FileContent\n | CreateEvalCompletionsRunDataSource.FileID\n | CreateEvalCompletionsRunDataSource.StoredCompletions;\n\n /**\n * The type of run data source. Always `completions`.\n */\n type: 'completions';\n\n /**\n * Used when sampling from a model. Dictates the structure of the messages passed\n * into the model. Can either be a reference to a prebuilt trajectory (ie,\n * `item.input_trajectory`), or a template with variable references to the `item`\n * namespace.\n */\n input_messages?:\n | CreateEvalCompletionsRunDataSource.Template\n | CreateEvalCompletionsRunDataSource.ItemReference;\n\n /**\n * The name of the model to use for generating completions (e.g. \"o3-mini\").\n */\n model?: string;\n\n sampling_params?: CreateEvalCompletionsRunDataSource.SamplingParams;\n}\n\nexport namespace CreateEvalCompletionsRunDataSource {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n\n /**\n * A StoredCompletionsRunDataSource configuration describing a set of filters\n */\n export interface StoredCompletions {\n /**\n * The type of source. Always `stored_completions`.\n */\n type: 'stored_completions';\n\n /**\n * An optional Unix timestamp to filter items created after this time.\n */\n created_after?: number | null;\n\n /**\n * An optional Unix timestamp to filter items created before this time.\n */\n created_before?: number | null;\n\n /**\n * An optional maximum number of items to return.\n */\n limit?: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * An optional model to filter by (e.g., 'gpt-4o').\n */\n model?: string | null;\n }\n\n export interface Template {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n template: Array<ResponsesAPI.EasyInputMessage | Template.EvalItem>;\n\n /**\n * The type of input messages. Always `template`.\n */\n type: 'template';\n }\n\n export namespace Template {\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n export interface ItemReference {\n /**\n * A reference to a variable in the `item` namespace. Ie, \"item.input_trajectory\"\n */\n item_reference: string;\n\n /**\n * The type of input messages. Always `item_reference`.\n */\n type: 'item_reference';\n }\n\n export interface SamplingParams {\n /**\n * The maximum number of tokens in the generated output.\n */\n max_completion_tokens?: number;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * An object specifying the format that the model must output.\n *\n * Setting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured\n * Outputs which ensures the model will match your supplied JSON schema. Learn more\n * in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n response_format?:\n | Shared.ResponseFormatText\n | Shared.ResponseFormatJSONSchema\n | Shared.ResponseFormatJSONObject;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number;\n\n /**\n * A list of tools the model may call. Currently, only functions are supported as a\n * tool. Use this to provide a list of functions the model may generate JSON inputs\n * for. A max of 128 functions are supported.\n */\n tools?: Array<CompletionsAPI.ChatCompletionFunctionTool>;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number;\n }\n}\n\n/**\n * A JsonlRunDataSource object with that specifies a JSONL file that matches the\n * eval\n */\nexport interface CreateEvalJSONLRunDataSource {\n /**\n * Determines what populates the `item` namespace in the data source.\n */\n source: CreateEvalJSONLRunDataSource.FileContent | CreateEvalJSONLRunDataSource.FileID;\n\n /**\n * The type of data source. Always `jsonl`.\n */\n type: 'jsonl';\n}\n\nexport namespace CreateEvalJSONLRunDataSource {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n}\n\n/**\n * An object representing an error response from the Eval API.\n */\nexport interface EvalAPIError {\n /**\n * The error code.\n */\n code: string;\n\n /**\n * The error message.\n */\n message: string;\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunCreateResponse {\n /**\n * Unique identifier for the evaluation run.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the evaluation run was created.\n */\n created_at: number;\n\n /**\n * Information about the run's data source.\n */\n data_source:\n | CreateEvalJSONLRunDataSource\n | CreateEvalCompletionsRunDataSource\n | RunCreateResponse.Responses;\n\n /**\n * An object representing an error response from the Eval API.\n */\n error: EvalAPIError;\n\n /**\n * The identifier of the associated evaluation.\n */\n eval_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The model that is evaluated, if applicable.\n */\n model: string;\n\n /**\n * The name of the evaluation run.\n */\n name: string;\n\n /**\n * The type of the object. Always \"eval.run\".\n */\n object: 'eval.run';\n\n /**\n * Usage statistics for each model during the evaluation run.\n */\n per_model_usage: Array<RunCreateResponse.PerModelUsage>;\n\n /**\n * Results per testing criteria applied during the evaluation run.\n */\n per_testing_criteria_results: Array<RunCreateResponse.PerTestingCriteriaResult>;\n\n /**\n * The URL to the rendered evaluation run report on the UI dashboard.\n */\n report_url: string;\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n result_counts: RunCreateResponse.ResultCounts;\n\n /**\n * The status of the evaluation run.\n */\n status: string;\n}\n\nexport namespace RunCreateResponse {\n /**\n * A ResponsesRunDataSource object describing a model sampling configuration.\n */\n export interface Responses {\n /**\n * Determines what populates the `item` namespace in this run's data source.\n */\n source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Used when sampling from a model. Dictates the structure of the messages passed\n * into the model. Can either be a reference to a prebuilt trajectory (ie,\n * `item.input_trajectory`), or a template with variable references to the `item`\n * namespace.\n */\n input_messages?: Responses.Template | Responses.ItemReference;\n\n /**\n * The name of the model to use for generating completions (e.g. \"o3-mini\").\n */\n model?: string;\n\n sampling_params?: Responses.SamplingParams;\n }\n\n export namespace Responses {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n\n /**\n * A EvalResponsesSource object describing a run data source configuration.\n */\n export interface Responses {\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Only include items created after this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_after?: number | null;\n\n /**\n * Only include items created before this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_before?: number | null;\n\n /**\n * Optional string to search the 'instructions' field. This is a query parameter\n * used to select responses.\n */\n instructions_search?: string | null;\n\n /**\n * Metadata filter for the responses. This is a query parameter used to select\n * responses.\n */\n metadata?: unknown | null;\n\n /**\n * The name of the model to find responses for. This is a query parameter used to\n * select responses.\n */\n model?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Sampling temperature. This is a query parameter used to select responses.\n */\n temperature?: number | null;\n\n /**\n * List of tool names. This is a query parameter used to select responses.\n */\n tools?: Array<string> | null;\n\n /**\n * Nucleus sampling parameter. This is a query parameter used to select responses.\n */\n top_p?: number | null;\n\n /**\n * List of user identifiers. This is a query parameter used to select responses.\n */\n users?: Array<string> | null;\n }\n\n export interface Template {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n template: Array<Template.ChatMessage | Template.EvalItem>;\n\n /**\n * The type of input messages. Always `template`.\n */\n type: 'template';\n }\n\n export namespace Template {\n export interface ChatMessage {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role: string;\n }\n\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n export interface ItemReference {\n /**\n * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n */\n item_reference: string;\n\n /**\n * The type of input messages. Always `item_reference`.\n */\n type: 'item_reference';\n }\n\n export interface SamplingParams {\n /**\n * The maximum number of tokens in the generated output.\n */\n max_completion_tokens?: number;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: SamplingParams.Text;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * The two categories of tools you can provide the model are:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code. Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\n tools?: Array<ResponsesAPI.Tool>;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number;\n }\n\n export namespace SamplingParams {\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n export interface Text {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponsesAPI.ResponseFormatTextConfig;\n }\n }\n }\n\n export interface PerModelUsage {\n /**\n * The number of tokens retrieved from cache.\n */\n cached_tokens: number;\n\n /**\n * The number of completion tokens generated.\n */\n completion_tokens: number;\n\n /**\n * The number of invocations.\n */\n invocation_count: number;\n\n /**\n * The name of the model.\n */\n model_name: string;\n\n /**\n * The number of prompt tokens used.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n }\n\n export interface PerTestingCriteriaResult {\n /**\n * Number of tests failed for this criteria.\n */\n failed: number;\n\n /**\n * Number of tests passed for this criteria.\n */\n passed: number;\n\n /**\n * A description of the testing criteria.\n */\n testing_criteria: string;\n }\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n export interface ResultCounts {\n /**\n * Number of output items that resulted in an error.\n */\n errored: number;\n\n /**\n * Number of output items that failed to pass the evaluation.\n */\n failed: number;\n\n /**\n * Number of output items that passed the evaluation.\n */\n passed: number;\n\n /**\n * Total number of executed output items.\n */\n total: number;\n }\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunRetrieveResponse {\n /**\n * Unique identifier for the evaluation run.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the evaluation run was created.\n */\n created_at: number;\n\n /**\n * Information about the run's data source.\n */\n data_source:\n | CreateEvalJSONLRunDataSource\n | CreateEvalCompletionsRunDataSource\n | RunRetrieveResponse.Responses;\n\n /**\n * An object representing an error response from the Eval API.\n */\n error: EvalAPIError;\n\n /**\n * The identifier of the associated evaluation.\n */\n eval_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The model that is evaluated, if applicable.\n */\n model: string;\n\n /**\n * The name of the evaluation run.\n */\n name: string;\n\n /**\n * The type of the object. Always \"eval.run\".\n */\n object: 'eval.run';\n\n /**\n * Usage statistics for each model during the evaluation run.\n */\n per_model_usage: Array<RunRetrieveResponse.PerModelUsage>;\n\n /**\n * Results per testing criteria applied during the evaluation run.\n */\n per_testing_criteria_results: Array<RunRetrieveResponse.PerTestingCriteriaResult>;\n\n /**\n * The URL to the rendered evaluation run report on the UI dashboard.\n */\n report_url: string;\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n result_counts: RunRetrieveResponse.ResultCounts;\n\n /**\n * The status of the evaluation run.\n */\n status: string;\n}\n\nexport namespace RunRetrieveResponse {\n /**\n * A ResponsesRunDataSource object describing a model sampling configuration.\n */\n export interface Responses {\n /**\n * Determines what populates the `item` namespace in this run's data source.\n */\n source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Used when sampling from a model. Dictates the structure of the messages passed\n * into the model. Can either be a reference to a prebuilt trajectory (ie,\n * `item.input_trajectory`), or a template with variable references to the `item`\n * namespace.\n */\n input_messages?: Responses.Template | Responses.ItemReference;\n\n /**\n * The name of the model to use for generating completions (e.g. \"o3-mini\").\n */\n model?: string;\n\n sampling_params?: Responses.SamplingParams;\n }\n\n export namespace Responses {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n\n /**\n * A EvalResponsesSource object describing a run data source configuration.\n */\n export interface Responses {\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Only include items created after this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_after?: number | null;\n\n /**\n * Only include items created before this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_before?: number | null;\n\n /**\n * Optional string to search the 'instructions' field. This is a query parameter\n * used to select responses.\n */\n instructions_search?: string | null;\n\n /**\n * Metadata filter for the responses. This is a query parameter used to select\n * responses.\n */\n metadata?: unknown | null;\n\n /**\n * The name of the model to find responses for. This is a query parameter used to\n * select responses.\n */\n model?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Sampling temperature. This is a query parameter used to select responses.\n */\n temperature?: number | null;\n\n /**\n * List of tool names. This is a query parameter used to select responses.\n */\n tools?: Array<string> | null;\n\n /**\n * Nucleus sampling parameter. This is a query parameter used to select responses.\n */\n top_p?: number | null;\n\n /**\n * List of user identifiers. This is a query parameter used to select responses.\n */\n users?: Array<string> | null;\n }\n\n export interface Template {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n template: Array<Template.ChatMessage | Template.EvalItem>;\n\n /**\n * The type of input messages. Always `template`.\n */\n type: 'template';\n }\n\n export namespace Template {\n export interface ChatMessage {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role: string;\n }\n\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n export interface ItemReference {\n /**\n * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n */\n item_reference: string;\n\n /**\n * The type of input messages. Always `item_reference`.\n */\n type: 'item_reference';\n }\n\n export interface SamplingParams {\n /**\n * The maximum number of tokens in the generated output.\n */\n max_completion_tokens?: number;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: SamplingParams.Text;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * The two categories of tools you can provide the model are:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code. Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\n tools?: Array<ResponsesAPI.Tool>;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number;\n }\n\n export namespace SamplingParams {\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n export interface Text {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponsesAPI.ResponseFormatTextConfig;\n }\n }\n }\n\n export interface PerModelUsage {\n /**\n * The number of tokens retrieved from cache.\n */\n cached_tokens: number;\n\n /**\n * The number of completion tokens generated.\n */\n completion_tokens: number;\n\n /**\n * The number of invocations.\n */\n invocation_count: number;\n\n /**\n * The name of the model.\n */\n model_name: string;\n\n /**\n * The number of prompt tokens used.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n }\n\n export interface PerTestingCriteriaResult {\n /**\n * Number of tests failed for this criteria.\n */\n failed: number;\n\n /**\n * Number of tests passed for this criteria.\n */\n passed: number;\n\n /**\n * A description of the testing criteria.\n */\n testing_criteria: string;\n }\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n export interface ResultCounts {\n /**\n * Number of output items that resulted in an error.\n */\n errored: number;\n\n /**\n * Number of output items that failed to pass the evaluation.\n */\n failed: number;\n\n /**\n * Number of output items that passed the evaluation.\n */\n passed: number;\n\n /**\n * Total number of executed output items.\n */\n total: number;\n }\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunListResponse {\n /**\n * Unique identifier for the evaluation run.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the evaluation run was created.\n */\n created_at: number;\n\n /**\n * Information about the run's data source.\n */\n data_source: CreateEvalJSONLRunDataSource | CreateEvalCompletionsRunDataSource | RunListResponse.Responses;\n\n /**\n * An object representing an error response from the Eval API.\n */\n error: EvalAPIError;\n\n /**\n * The identifier of the associated evaluation.\n */\n eval_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The model that is evaluated, if applicable.\n */\n model: string;\n\n /**\n * The name of the evaluation run.\n */\n name: string;\n\n /**\n * The type of the object. Always \"eval.run\".\n */\n object: 'eval.run';\n\n /**\n * Usage statistics for each model during the evaluation run.\n */\n per_model_usage: Array<RunListResponse.PerModelUsage>;\n\n /**\n * Results per testing criteria applied during the evaluation run.\n */\n per_testing_criteria_results: Array<RunListResponse.PerTestingCriteriaResult>;\n\n /**\n * The URL to the rendered evaluation run report on the UI dashboard.\n */\n report_url: string;\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n result_counts: RunListResponse.ResultCounts;\n\n /**\n * The status of the evaluation run.\n */\n status: string;\n}\n\nexport namespace RunListResponse {\n /**\n * A ResponsesRunDataSource object describing a model sampling configuration.\n */\n export interface Responses {\n /**\n * Determines what populates the `item` namespace in this run's data source.\n */\n source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Used when sampling from a model. Dictates the structure of the messages passed\n * into the model. Can either be a reference to a prebuilt trajectory (ie,\n * `item.input_trajectory`), or a template with variable references to the `item`\n * namespace.\n */\n input_messages?: Responses.Template | Responses.ItemReference;\n\n /**\n * The name of the model to use for generating completions (e.g. \"o3-mini\").\n */\n model?: string;\n\n sampling_params?: Responses.SamplingParams;\n }\n\n export namespace Responses {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n\n /**\n * A EvalResponsesSource object describing a run data source configuration.\n */\n export interface Responses {\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Only include items created after this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_after?: number | null;\n\n /**\n * Only include items created before this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_before?: number | null;\n\n /**\n * Optional string to search the 'instructions' field. This is a query parameter\n * used to select responses.\n */\n instructions_search?: string | null;\n\n /**\n * Metadata filter for the responses. This is a query parameter used to select\n * responses.\n */\n metadata?: unknown | null;\n\n /**\n * The name of the model to find responses for. This is a query parameter used to\n * select responses.\n */\n model?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Sampling temperature. This is a query parameter used to select responses.\n */\n temperature?: number | null;\n\n /**\n * List of tool names. This is a query parameter used to select responses.\n */\n tools?: Array<string> | null;\n\n /**\n * Nucleus sampling parameter. This is a query parameter used to select responses.\n */\n top_p?: number | null;\n\n /**\n * List of user identifiers. This is a query parameter used to select responses.\n */\n users?: Array<string> | null;\n }\n\n export interface Template {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n template: Array<Template.ChatMessage | Template.EvalItem>;\n\n /**\n * The type of input messages. Always `template`.\n */\n type: 'template';\n }\n\n export namespace Template {\n export interface ChatMessage {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role: string;\n }\n\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n export interface ItemReference {\n /**\n * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n */\n item_reference: string;\n\n /**\n * The type of input messages. Always `item_reference`.\n */\n type: 'item_reference';\n }\n\n export interface SamplingParams {\n /**\n * The maximum number of tokens in the generated output.\n */\n max_completion_tokens?: number;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: SamplingParams.Text;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * The two categories of tools you can provide the model are:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code. Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\n tools?: Array<ResponsesAPI.Tool>;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number;\n }\n\n export namespace SamplingParams {\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n export interface Text {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponsesAPI.ResponseFormatTextConfig;\n }\n }\n }\n\n export interface PerModelUsage {\n /**\n * The number of tokens retrieved from cache.\n */\n cached_tokens: number;\n\n /**\n * The number of completion tokens generated.\n */\n completion_tokens: number;\n\n /**\n * The number of invocations.\n */\n invocation_count: number;\n\n /**\n * The name of the model.\n */\n model_name: string;\n\n /**\n * The number of prompt tokens used.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n }\n\n export interface PerTestingCriteriaResult {\n /**\n * Number of tests failed for this criteria.\n */\n failed: number;\n\n /**\n * Number of tests passed for this criteria.\n */\n passed: number;\n\n /**\n * A description of the testing criteria.\n */\n testing_criteria: string;\n }\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n export interface ResultCounts {\n /**\n * Number of output items that resulted in an error.\n */\n errored: number;\n\n /**\n * Number of output items that failed to pass the evaluation.\n */\n failed: number;\n\n /**\n * Number of output items that passed the evaluation.\n */\n passed: number;\n\n /**\n * Total number of executed output items.\n */\n total: number;\n }\n}\n\nexport interface RunDeleteResponse {\n deleted?: boolean;\n\n object?: string;\n\n run_id?: string;\n}\n\n/**\n * A schema representing an evaluation run.\n */\nexport interface RunCancelResponse {\n /**\n * Unique identifier for the evaluation run.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the evaluation run was created.\n */\n created_at: number;\n\n /**\n * Information about the run's data source.\n */\n data_source:\n | CreateEvalJSONLRunDataSource\n | CreateEvalCompletionsRunDataSource\n | RunCancelResponse.Responses;\n\n /**\n * An object representing an error response from the Eval API.\n */\n error: EvalAPIError;\n\n /**\n * The identifier of the associated evaluation.\n */\n eval_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The model that is evaluated, if applicable.\n */\n model: string;\n\n /**\n * The name of the evaluation run.\n */\n name: string;\n\n /**\n * The type of the object. Always \"eval.run\".\n */\n object: 'eval.run';\n\n /**\n * Usage statistics for each model during the evaluation run.\n */\n per_model_usage: Array<RunCancelResponse.PerModelUsage>;\n\n /**\n * Results per testing criteria applied during the evaluation run.\n */\n per_testing_criteria_results: Array<RunCancelResponse.PerTestingCriteriaResult>;\n\n /**\n * The URL to the rendered evaluation run report on the UI dashboard.\n */\n report_url: string;\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n result_counts: RunCancelResponse.ResultCounts;\n\n /**\n * The status of the evaluation run.\n */\n status: string;\n}\n\nexport namespace RunCancelResponse {\n /**\n * A ResponsesRunDataSource object describing a model sampling configuration.\n */\n export interface Responses {\n /**\n * Determines what populates the `item` namespace in this run's data source.\n */\n source: Responses.FileContent | Responses.FileID | Responses.Responses;\n\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Used when sampling from a model. Dictates the structure of the messages passed\n * into the model. Can either be a reference to a prebuilt trajectory (ie,\n * `item.input_trajectory`), or a template with variable references to the `item`\n * namespace.\n */\n input_messages?: Responses.Template | Responses.ItemReference;\n\n /**\n * The name of the model to use for generating completions (e.g. \"o3-mini\").\n */\n model?: string;\n\n sampling_params?: Responses.SamplingParams;\n }\n\n export namespace Responses {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n\n /**\n * A EvalResponsesSource object describing a run data source configuration.\n */\n export interface Responses {\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Only include items created after this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_after?: number | null;\n\n /**\n * Only include items created before this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_before?: number | null;\n\n /**\n * Optional string to search the 'instructions' field. This is a query parameter\n * used to select responses.\n */\n instructions_search?: string | null;\n\n /**\n * Metadata filter for the responses. This is a query parameter used to select\n * responses.\n */\n metadata?: unknown | null;\n\n /**\n * The name of the model to find responses for. This is a query parameter used to\n * select responses.\n */\n model?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Sampling temperature. This is a query parameter used to select responses.\n */\n temperature?: number | null;\n\n /**\n * List of tool names. This is a query parameter used to select responses.\n */\n tools?: Array<string> | null;\n\n /**\n * Nucleus sampling parameter. This is a query parameter used to select responses.\n */\n top_p?: number | null;\n\n /**\n * List of user identifiers. This is a query parameter used to select responses.\n */\n users?: Array<string> | null;\n }\n\n export interface Template {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n template: Array<Template.ChatMessage | Template.EvalItem>;\n\n /**\n * The type of input messages. Always `template`.\n */\n type: 'template';\n }\n\n export namespace Template {\n export interface ChatMessage {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role: string;\n }\n\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n export interface ItemReference {\n /**\n * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n */\n item_reference: string;\n\n /**\n * The type of input messages. Always `item_reference`.\n */\n type: 'item_reference';\n }\n\n export interface SamplingParams {\n /**\n * The maximum number of tokens in the generated output.\n */\n max_completion_tokens?: number;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: SamplingParams.Text;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * The two categories of tools you can provide the model are:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code. Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\n tools?: Array<ResponsesAPI.Tool>;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number;\n }\n\n export namespace SamplingParams {\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n export interface Text {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponsesAPI.ResponseFormatTextConfig;\n }\n }\n }\n\n export interface PerModelUsage {\n /**\n * The number of tokens retrieved from cache.\n */\n cached_tokens: number;\n\n /**\n * The number of completion tokens generated.\n */\n completion_tokens: number;\n\n /**\n * The number of invocations.\n */\n invocation_count: number;\n\n /**\n * The name of the model.\n */\n model_name: string;\n\n /**\n * The number of prompt tokens used.\n */\n prompt_tokens: number;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n }\n\n export interface PerTestingCriteriaResult {\n /**\n * Number of tests failed for this criteria.\n */\n failed: number;\n\n /**\n * Number of tests passed for this criteria.\n */\n passed: number;\n\n /**\n * A description of the testing criteria.\n */\n testing_criteria: string;\n }\n\n /**\n * Counters summarizing the outcomes of the evaluation run.\n */\n export interface ResultCounts {\n /**\n * Number of output items that resulted in an error.\n */\n errored: number;\n\n /**\n * Number of output items that failed to pass the evaluation.\n */\n failed: number;\n\n /**\n * Number of output items that passed the evaluation.\n */\n passed: number;\n\n /**\n * Total number of executed output items.\n */\n total: number;\n }\n}\n\nexport interface RunCreateParams {\n /**\n * Details about the run's data source.\n */\n data_source:\n | CreateEvalJSONLRunDataSource\n | CreateEvalCompletionsRunDataSource\n | RunCreateParams.CreateEvalResponsesRunDataSource;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The name of the run.\n */\n name?: string;\n}\n\nexport namespace RunCreateParams {\n /**\n * A ResponsesRunDataSource object describing a model sampling configuration.\n */\n export interface CreateEvalResponsesRunDataSource {\n /**\n * Determines what populates the `item` namespace in this run's data source.\n */\n source:\n | CreateEvalResponsesRunDataSource.FileContent\n | CreateEvalResponsesRunDataSource.FileID\n | CreateEvalResponsesRunDataSource.Responses;\n\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Used when sampling from a model. Dictates the structure of the messages passed\n * into the model. Can either be a reference to a prebuilt trajectory (ie,\n * `item.input_trajectory`), or a template with variable references to the `item`\n * namespace.\n */\n input_messages?:\n | CreateEvalResponsesRunDataSource.Template\n | CreateEvalResponsesRunDataSource.ItemReference;\n\n /**\n * The name of the model to use for generating completions (e.g. \"o3-mini\").\n */\n model?: string;\n\n sampling_params?: CreateEvalResponsesRunDataSource.SamplingParams;\n }\n\n export namespace CreateEvalResponsesRunDataSource {\n export interface FileContent {\n /**\n * The content of the jsonl file.\n */\n content: Array<FileContent.Content>;\n\n /**\n * The type of jsonl source. Always `file_content`.\n */\n type: 'file_content';\n }\n\n export namespace FileContent {\n export interface Content {\n item: { [key: string]: unknown };\n\n sample?: { [key: string]: unknown };\n }\n }\n\n export interface FileID {\n /**\n * The identifier of the file.\n */\n id: string;\n\n /**\n * The type of jsonl source. Always `file_id`.\n */\n type: 'file_id';\n }\n\n /**\n * A EvalResponsesSource object describing a run data source configuration.\n */\n export interface Responses {\n /**\n * The type of run data source. Always `responses`.\n */\n type: 'responses';\n\n /**\n * Only include items created after this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_after?: number | null;\n\n /**\n * Only include items created before this timestamp (inclusive). This is a query\n * parameter used to select responses.\n */\n created_before?: number | null;\n\n /**\n * Optional string to search the 'instructions' field. This is a query parameter\n * used to select responses.\n */\n instructions_search?: string | null;\n\n /**\n * Metadata filter for the responses. This is a query parameter used to select\n * responses.\n */\n metadata?: unknown | null;\n\n /**\n * The name of the model to find responses for. This is a query parameter used to\n * select responses.\n */\n model?: string | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * Sampling temperature. This is a query parameter used to select responses.\n */\n temperature?: number | null;\n\n /**\n * List of tool names. This is a query parameter used to select responses.\n */\n tools?: Array<string> | null;\n\n /**\n * Nucleus sampling parameter. This is a query parameter used to select responses.\n */\n top_p?: number | null;\n\n /**\n * List of user identifiers. This is a query parameter used to select responses.\n */\n users?: Array<string> | null;\n }\n\n export interface Template {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n template: Array<Template.ChatMessage | Template.EvalItem>;\n\n /**\n * The type of input messages. Always `template`.\n */\n type: 'template';\n }\n\n export namespace Template {\n export interface ChatMessage {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role: string;\n }\n\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n export interface ItemReference {\n /**\n * A reference to a variable in the `item` namespace. Ie, \"item.name\"\n */\n item_reference: string;\n\n /**\n * The type of input messages. Always `item_reference`.\n */\n type: 'item_reference';\n }\n\n export interface SamplingParams {\n /**\n * The maximum number of tokens in the generated output.\n */\n max_completion_tokens?: number;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: SamplingParams.Text;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * The two categories of tools you can provide the model are:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code. Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\n tools?: Array<ResponsesAPI.Tool>;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number;\n }\n\n export namespace SamplingParams {\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n export interface Text {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponsesAPI.ResponseFormatTextConfig;\n }\n }\n }\n}\n\nexport interface RunRetrieveParams {\n /**\n * The ID of the evaluation to retrieve runs for.\n */\n eval_id: string;\n}\n\nexport interface RunListParams extends CursorPageParams {\n /**\n * Sort order for runs by timestamp. Use `asc` for ascending order or `desc` for\n * descending order. Defaults to `asc`.\n */\n order?: 'asc' | 'desc';\n\n /**\n * Filter runs by status. One of `queued` | `in_progress` | `failed` | `completed`\n * | `canceled`.\n */\n status?: 'queued' | 'in_progress' | 'completed' | 'canceled' | 'failed';\n}\n\nexport interface RunDeleteParams {\n /**\n * The ID of the evaluation to delete the run from.\n */\n eval_id: string;\n}\n\nexport interface RunCancelParams {\n /**\n * The ID of the evaluation whose run you want to cancel.\n */\n eval_id: string;\n}\n\nRuns.OutputItems = OutputItems;\n\nexport declare namespace Runs {\n export {\n type CreateEvalCompletionsRunDataSource as CreateEvalCompletionsRunDataSource,\n type CreateEvalJSONLRunDataSource as CreateEvalJSONLRunDataSource,\n type EvalAPIError as EvalAPIError,\n type RunCreateResponse as RunCreateResponse,\n type RunRetrieveResponse as RunRetrieveResponse,\n type RunListResponse as RunListResponse,\n type RunDeleteResponse as RunDeleteResponse,\n type RunCancelResponse as RunCancelResponse,\n type RunListResponsesPage as RunListResponsesPage,\n type RunCreateParams as RunCreateParams,\n type RunRetrieveParams as RunRetrieveParams,\n type RunListParams as RunListParams,\n type RunDeleteParams as RunDeleteParams,\n type RunCancelParams as RunCancelParams,\n };\n\n export {\n OutputItems as OutputItems,\n type OutputItemRetrieveResponse as OutputItemRetrieveResponse,\n type OutputItemListResponse as OutputItemListResponse,\n type OutputItemListResponsesPage as OutputItemListResponsesPage,\n type OutputItemRetrieveParams as OutputItemRetrieveParams,\n type OutputItemListParams as OutputItemListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as GraderModelsAPI from '../graders/grader-models';\nimport * as ResponsesAPI from '../responses/responses';\nimport * as RunsAPI from './runs/runs';\nimport {\n CreateEvalCompletionsRunDataSource,\n CreateEvalJSONLRunDataSource,\n EvalAPIError,\n RunCancelParams,\n RunCancelResponse,\n RunCreateParams,\n RunCreateResponse,\n RunDeleteParams,\n RunDeleteResponse,\n RunListParams,\n RunListResponse,\n RunListResponsesPage,\n RunRetrieveParams,\n RunRetrieveResponse,\n Runs,\n} from './runs/runs';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Manage and run evals in the OpenAI platform.\n */\nexport class Evals extends APIResource {\n runs: RunsAPI.Runs = new RunsAPI.Runs(this._client);\n\n /**\n * Create the structure of an evaluation that can be used to test a model's\n * performance. An evaluation is a set of testing criteria and the config for a\n * data source, which dictates the schema of the data used in the evaluation. After\n * creating an evaluation, you can run it on different models and model parameters.\n * We support several types of graders and datasources. For more information, see\n * the [Evals guide](https://platform.openai.com/docs/guides/evals).\n */\n create(body: EvalCreateParams, options?: RequestOptions): APIPromise<EvalCreateResponse> {\n return this._client.post('/evals', { body, ...options });\n }\n\n /**\n * Get an evaluation by ID.\n */\n retrieve(evalID: string, options?: RequestOptions): APIPromise<EvalRetrieveResponse> {\n return this._client.get(path`/evals/${evalID}`, options);\n }\n\n /**\n * Update certain properties of an evaluation.\n */\n update(evalID: string, body: EvalUpdateParams, options?: RequestOptions): APIPromise<EvalUpdateResponse> {\n return this._client.post(path`/evals/${evalID}`, { body, ...options });\n }\n\n /**\n * List evaluations for a project.\n */\n list(\n query: EvalListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<EvalListResponsesPage, EvalListResponse> {\n return this._client.getAPIList('/evals', CursorPage<EvalListResponse>, { query, ...options });\n }\n\n /**\n * Delete an evaluation.\n */\n delete(evalID: string, options?: RequestOptions): APIPromise<EvalDeleteResponse> {\n return this._client.delete(path`/evals/${evalID}`, options);\n }\n}\n\nexport type EvalListResponsesPage = CursorPage<EvalListResponse>;\n\n/**\n * A CustomDataSourceConfig which specifies the schema of your `item` and\n * optionally `sample` namespaces. The response schema defines the shape of the\n * data that will be:\n *\n * - Used to define your testing criteria and\n * - What data is required when creating a run\n */\nexport interface EvalCustomDataSourceConfig {\n /**\n * The json schema for the run data source items. Learn how to build JSON schemas\n * [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `custom`.\n */\n type: 'custom';\n}\n\n/**\n * @deprecated Deprecated in favor of LogsDataSourceConfig.\n */\nexport interface EvalStoredCompletionsDataSourceConfig {\n /**\n * The json schema for the run data source items. Learn how to build JSON schemas\n * [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `stored_completions`.\n */\n type: 'stored_completions';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalCreateResponse {\n /**\n * Unique identifier for the evaluation.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the eval was created.\n */\n created_at: number;\n\n /**\n * Configuration of data sources used in runs of the evaluation.\n */\n data_source_config:\n | EvalCustomDataSourceConfig\n | EvalCreateResponse.Logs\n | EvalStoredCompletionsDataSourceConfig;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The name of the evaluation.\n */\n name: string;\n\n /**\n * The object type.\n */\n object: 'eval';\n\n /**\n * A list of testing criteria.\n */\n testing_criteria: Array<\n | GraderModelsAPI.LabelModelGrader\n | GraderModelsAPI.StringCheckGrader\n | EvalCreateResponse.EvalGraderTextSimilarity\n | EvalCreateResponse.EvalGraderPython\n | EvalCreateResponse.EvalGraderScoreModel\n >;\n}\n\nexport namespace EvalCreateResponse {\n /**\n * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n * schema returned by this data source config is used to defined what variables are\n * available in your evals. `item` and `sample` are both defined when using this\n * data source config.\n */\n export interface Logs {\n /**\n * The json schema for the run data source items. Learn how to build JSON schemas\n * [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `logs`.\n */\n type: 'logs';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n /**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\n export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold: number;\n }\n\n /**\n * A PythonGrader object that runs a python script on the input.\n */\n export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n\n /**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\n export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalRetrieveResponse {\n /**\n * Unique identifier for the evaluation.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the eval was created.\n */\n created_at: number;\n\n /**\n * Configuration of data sources used in runs of the evaluation.\n */\n data_source_config:\n | EvalCustomDataSourceConfig\n | EvalRetrieveResponse.Logs\n | EvalStoredCompletionsDataSourceConfig;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The name of the evaluation.\n */\n name: string;\n\n /**\n * The object type.\n */\n object: 'eval';\n\n /**\n * A list of testing criteria.\n */\n testing_criteria: Array<\n | GraderModelsAPI.LabelModelGrader\n | GraderModelsAPI.StringCheckGrader\n | EvalRetrieveResponse.EvalGraderTextSimilarity\n | EvalRetrieveResponse.EvalGraderPython\n | EvalRetrieveResponse.EvalGraderScoreModel\n >;\n}\n\nexport namespace EvalRetrieveResponse {\n /**\n * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n * schema returned by this data source config is used to defined what variables are\n * available in your evals. `item` and `sample` are both defined when using this\n * data source config.\n */\n export interface Logs {\n /**\n * The json schema for the run data source items. Learn how to build JSON schemas\n * [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `logs`.\n */\n type: 'logs';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n /**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\n export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold: number;\n }\n\n /**\n * A PythonGrader object that runs a python script on the input.\n */\n export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n\n /**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\n export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalUpdateResponse {\n /**\n * Unique identifier for the evaluation.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the eval was created.\n */\n created_at: number;\n\n /**\n * Configuration of data sources used in runs of the evaluation.\n */\n data_source_config:\n | EvalCustomDataSourceConfig\n | EvalUpdateResponse.Logs\n | EvalStoredCompletionsDataSourceConfig;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The name of the evaluation.\n */\n name: string;\n\n /**\n * The object type.\n */\n object: 'eval';\n\n /**\n * A list of testing criteria.\n */\n testing_criteria: Array<\n | GraderModelsAPI.LabelModelGrader\n | GraderModelsAPI.StringCheckGrader\n | EvalUpdateResponse.EvalGraderTextSimilarity\n | EvalUpdateResponse.EvalGraderPython\n | EvalUpdateResponse.EvalGraderScoreModel\n >;\n}\n\nexport namespace EvalUpdateResponse {\n /**\n * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n * schema returned by this data source config is used to defined what variables are\n * available in your evals. `item` and `sample` are both defined when using this\n * data source config.\n */\n export interface Logs {\n /**\n * The json schema for the run data source items. Learn how to build JSON schemas\n * [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `logs`.\n */\n type: 'logs';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n /**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\n export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold: number;\n }\n\n /**\n * A PythonGrader object that runs a python script on the input.\n */\n export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n\n /**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\n export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n}\n\n/**\n * An Eval object with a data source config and testing criteria. An Eval\n * represents a task to be done for your LLM integration. Like:\n *\n * - Improve the quality of my chatbot\n * - See how well my chatbot handles customer support\n * - Check if o4-mini is better at my usecase than gpt-4o\n */\nexport interface EvalListResponse {\n /**\n * Unique identifier for the evaluation.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the eval was created.\n */\n created_at: number;\n\n /**\n * Configuration of data sources used in runs of the evaluation.\n */\n data_source_config:\n | EvalCustomDataSourceConfig\n | EvalListResponse.Logs\n | EvalStoredCompletionsDataSourceConfig;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The name of the evaluation.\n */\n name: string;\n\n /**\n * The object type.\n */\n object: 'eval';\n\n /**\n * A list of testing criteria.\n */\n testing_criteria: Array<\n | GraderModelsAPI.LabelModelGrader\n | GraderModelsAPI.StringCheckGrader\n | EvalListResponse.EvalGraderTextSimilarity\n | EvalListResponse.EvalGraderPython\n | EvalListResponse.EvalGraderScoreModel\n >;\n}\n\nexport namespace EvalListResponse {\n /**\n * A LogsDataSourceConfig which specifies the metadata property of your logs query.\n * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc. The\n * schema returned by this data source config is used to defined what variables are\n * available in your evals. `item` and `sample` are both defined when using this\n * data source config.\n */\n export interface Logs {\n /**\n * The json schema for the run data source items. Learn how to build JSON schemas\n * [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `logs`.\n */\n type: 'logs';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n }\n\n /**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\n export interface EvalGraderTextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold: number;\n }\n\n /**\n * A PythonGrader object that runs a python script on the input.\n */\n export interface EvalGraderPython extends GraderModelsAPI.PythonGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n\n /**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\n export interface EvalGraderScoreModel extends GraderModelsAPI.ScoreModelGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n}\n\nexport interface EvalDeleteResponse {\n deleted: boolean;\n\n eval_id: string;\n\n object: string;\n}\n\nexport interface EvalCreateParams {\n /**\n * The configuration for the data source used for the evaluation runs. Dictates the\n * schema of the data used in the evaluation.\n */\n data_source_config: EvalCreateParams.Custom | EvalCreateParams.Logs | EvalCreateParams.StoredCompletions;\n\n /**\n * A list of graders for all eval runs in this group. Graders can reference\n * variables in the data source using double curly braces notation, like\n * `{{item.variable_name}}`. To reference the model's output, use the `sample`\n * namespace (ie, `{{sample.output_text}}`).\n */\n testing_criteria: Array<\n | EvalCreateParams.LabelModel\n | GraderModelsAPI.StringCheckGrader\n | EvalCreateParams.TextSimilarity\n | EvalCreateParams.Python\n | EvalCreateParams.ScoreModel\n >;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The name of the evaluation.\n */\n name?: string;\n}\n\nexport namespace EvalCreateParams {\n /**\n * A CustomDataSourceConfig object that defines the schema for the data source used\n * for the evaluation runs. This schema is used to define the shape of the data\n * that will be:\n *\n * - Used to define your testing criteria and\n * - What data is required when creating a run\n */\n export interface Custom {\n /**\n * The json schema for each row in the data source.\n */\n item_schema: { [key: string]: unknown };\n\n /**\n * The type of data source. Always `custom`.\n */\n type: 'custom';\n\n /**\n * Whether the eval should expect you to populate the sample namespace (ie, by\n * generating responses off of your data source)\n */\n include_sample_schema?: boolean;\n }\n\n /**\n * A data source config which specifies the metadata property of your logs query.\n * This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.\n */\n export interface Logs {\n /**\n * The type of data source. Always `logs`.\n */\n type: 'logs';\n\n /**\n * Metadata filters for the logs data source.\n */\n metadata?: { [key: string]: unknown };\n }\n\n /**\n * @deprecated Deprecated in favor of LogsDataSourceConfig.\n */\n export interface StoredCompletions {\n /**\n * The type of data source. Always `stored_completions`.\n */\n type: 'stored_completions';\n\n /**\n * Metadata filters for the stored completions data source.\n */\n metadata?: { [key: string]: unknown };\n }\n\n /**\n * A LabelModelGrader object which uses a model to assign labels to each item in\n * the evaluation.\n */\n export interface LabelModel {\n /**\n * A list of chat messages forming the prompt or context. May include variable\n * references to the `item` namespace, ie {{item.name}}.\n */\n input: Array<LabelModel.SimpleInputMessage | LabelModel.EvalItem>;\n\n /**\n * The labels to classify to each item in the evaluation.\n */\n labels: Array<string>;\n\n /**\n * The model to use for the evaluation. Must support structured outputs.\n */\n model: string;\n\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The labels that indicate a passing result. Must be a subset of labels.\n */\n passing_labels: Array<string>;\n\n /**\n * The object type, which is always `label_model`.\n */\n type: 'label_model';\n }\n\n export namespace LabelModel {\n export interface SimpleInputMessage {\n /**\n * The content of the message.\n */\n content: string;\n\n /**\n * The role of the message (e.g. \"system\", \"assistant\", \"user\").\n */\n role: string;\n }\n\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface EvalItem {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | EvalItem.OutputText\n | EvalItem.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace EvalItem {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n }\n\n /**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\n export interface TextSimilarity extends GraderModelsAPI.TextSimilarityGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold: number;\n }\n\n /**\n * A PythonGrader object that runs a python script on the input.\n */\n export interface Python extends GraderModelsAPI.PythonGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n\n /**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\n export interface ScoreModel extends GraderModelsAPI.ScoreModelGrader {\n /**\n * The threshold for the score.\n */\n pass_threshold?: number;\n }\n}\n\nexport interface EvalUpdateParams {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * Rename the evaluation.\n */\n name?: string;\n}\n\nexport interface EvalListParams extends CursorPageParams {\n /**\n * Sort order for evals by timestamp. Use `asc` for ascending order or `desc` for\n * descending order.\n */\n order?: 'asc' | 'desc';\n\n /**\n * Evals can be ordered by creation time or last updated time. Use `created_at` for\n * creation time or `updated_at` for last updated time.\n */\n order_by?: 'created_at' | 'updated_at';\n}\n\nEvals.Runs = Runs;\n\nexport declare namespace Evals {\n export {\n type EvalCustomDataSourceConfig as EvalCustomDataSourceConfig,\n type EvalStoredCompletionsDataSourceConfig as EvalStoredCompletionsDataSourceConfig,\n type EvalCreateResponse as EvalCreateResponse,\n type EvalRetrieveResponse as EvalRetrieveResponse,\n type EvalUpdateResponse as EvalUpdateResponse,\n type EvalListResponse as EvalListResponse,\n type EvalDeleteResponse as EvalDeleteResponse,\n type EvalListResponsesPage as EvalListResponsesPage,\n type EvalCreateParams as EvalCreateParams,\n type EvalUpdateParams as EvalUpdateParams,\n type EvalListParams as EvalListParams,\n };\n\n export {\n Runs as Runs,\n type CreateEvalCompletionsRunDataSource as CreateEvalCompletionsRunDataSource,\n type CreateEvalJSONLRunDataSource as CreateEvalJSONLRunDataSource,\n type EvalAPIError as EvalAPIError,\n type RunCreateResponse as RunCreateResponse,\n type RunRetrieveResponse as RunRetrieveResponse,\n type RunListResponse as RunListResponse,\n type RunDeleteResponse as RunDeleteResponse,\n type RunCancelResponse as RunCancelResponse,\n type RunListResponsesPage as RunListResponsesPage,\n type RunCreateParams as RunCreateParams,\n type RunRetrieveParams as RunRetrieveParams,\n type RunListParams as RunListParams,\n type RunDeleteParams as RunDeleteParams,\n type RunCancelParams as RunCancelParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../core/pagination';\nimport { type Uploadable } from '../core/uploads';\nimport { buildHeaders } from '../internal/headers';\nimport { RequestOptions } from '../internal/request-options';\nimport { sleep } from '../internal/utils/sleep';\nimport { APIConnectionTimeoutError } from '../error';\nimport { multipartFormRequestOptions } from '../internal/uploads';\nimport { path } from '../internal/utils/path';\n\n/**\n * Files are used to upload documents that can be used with features like Assistants and Fine-tuning.\n */\nexport class Files extends APIResource {\n /**\n * Upload a file that can be used across various endpoints. Individual files can be\n * up to 512 MB, and each project can store up to 2.5 TB of files in total. There\n * is no organization-wide storage limit.\n *\n * - The Assistants API supports files up to 2 million tokens and of specific file\n * types. See the\n * [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools)\n * for details.\n * - The Fine-tuning API only supports `.jsonl` files. The input also has certain\n * required formats for fine-tuning\n * [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input)\n * or\n * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)\n * models.\n * - The Batch API only supports `.jsonl` files up to 200 MB in size. The input\n * also has a specific required\n * [format](https://platform.openai.com/docs/api-reference/batch/request-input).\n *\n * Please [contact us](https://help.openai.com/) if you need to increase these\n * storage limits.\n */\n create(body: FileCreateParams, options?: RequestOptions): APIPromise<FileObject> {\n return this._client.post('/files', multipartFormRequestOptions({ body, ...options }, this._client));\n }\n\n /**\n * Returns information about a specific file.\n */\n retrieve(fileID: string, options?: RequestOptions): APIPromise<FileObject> {\n return this._client.get(path`/files/${fileID}`, options);\n }\n\n /**\n * Returns a list of files.\n */\n list(\n query: FileListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<FileObjectsPage, FileObject> {\n return this._client.getAPIList('/files', CursorPage<FileObject>, { query, ...options });\n }\n\n /**\n * Delete a file and remove it from all vector stores.\n */\n delete(fileID: string, options?: RequestOptions): APIPromise<FileDeleted> {\n return this._client.delete(path`/files/${fileID}`, options);\n }\n\n /**\n * Returns the contents of the specified file.\n */\n content(fileID: string, options?: RequestOptions): APIPromise<Response> {\n return this._client.get(path`/files/${fileID}/content`, {\n ...options,\n headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n __binaryResponse: true,\n });\n }\n\n /**\n * Waits for the given file to be processed, default timeout is 30 mins.\n */\n async waitForProcessing(\n id: string,\n { pollInterval = 5000, maxWait = 30 * 60 * 1000 }: { pollInterval?: number; maxWait?: number } = {},\n ): Promise<FileObject> {\n const TERMINAL_STATES = new Set(['processed', 'error', 'deleted']);\n\n const start = Date.now();\n let file = await this.retrieve(id);\n\n while (!file.status || !TERMINAL_STATES.has(file.status)) {\n await sleep(pollInterval);\n\n file = await this.retrieve(id);\n if (Date.now() - start > maxWait) {\n throw new APIConnectionTimeoutError({\n message: `Giving up on waiting for file ${id} to finish processing after ${maxWait} milliseconds.`,\n });\n }\n }\n\n return file;\n }\n}\n\nexport type FileObjectsPage = CursorPage<FileObject>;\n\nexport type FileContent = string;\n\nexport interface FileDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'file';\n}\n\n/**\n * The `File` object represents a document that has been uploaded to OpenAI.\n */\nexport interface FileObject {\n /**\n * The file identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The size of the file, in bytes.\n */\n bytes: number;\n\n /**\n * The Unix timestamp (in seconds) for when the file was created.\n */\n created_at: number;\n\n /**\n * The name of the file.\n */\n filename: string;\n\n /**\n * The object type, which is always `file`.\n */\n object: 'file';\n\n /**\n * The intended purpose of the file. Supported values are `assistants`,\n * `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`,\n * `vision`, and `user_data`.\n */\n purpose:\n | 'assistants'\n | 'assistants_output'\n | 'batch'\n | 'batch_output'\n | 'fine-tune'\n | 'fine-tune-results'\n | 'vision'\n | 'user_data';\n\n /**\n * @deprecated Deprecated. The current status of the file, which can be either\n * `uploaded`, `processed`, or `error`.\n */\n status: 'uploaded' | 'processed' | 'error';\n\n /**\n * The Unix timestamp (in seconds) for when the file will expire.\n */\n expires_at?: number;\n\n /**\n * @deprecated Deprecated. For details on why a fine-tuning training file failed\n * validation, see the `error` field on `fine_tuning.job`.\n */\n status_details?: string;\n}\n\n/**\n * The intended purpose of the uploaded file. One of:\n *\n * - `assistants`: Used in the Assistants API\n * - `batch`: Used in the Batch API\n * - `fine-tune`: Used for fine-tuning\n * - `vision`: Images used for vision fine-tuning\n * - `user_data`: Flexible file type for any purpose\n * - `evals`: Used for eval data sets\n */\nexport type FilePurpose = 'assistants' | 'batch' | 'fine-tune' | 'vision' | 'user_data' | 'evals';\n\nexport interface FileCreateParams {\n /**\n * The File object (not file name) to be uploaded.\n */\n file: Uploadable;\n\n /**\n * The intended purpose of the uploaded file. One of:\n *\n * - `assistants`: Used in the Assistants API\n * - `batch`: Used in the Batch API\n * - `fine-tune`: Used for fine-tuning\n * - `vision`: Images used for vision fine-tuning\n * - `user_data`: Flexible file type for any purpose\n * - `evals`: Used for eval data sets\n */\n purpose: FilePurpose;\n\n /**\n * The expiration policy for a file. By default, files with `purpose=batch` expire\n * after 30 days and all other files are persisted until they are manually deleted.\n */\n expires_after?: FileCreateParams.ExpiresAfter;\n}\n\nexport namespace FileCreateParams {\n /**\n * The expiration policy for a file. By default, files with `purpose=batch` expire\n * after 30 days and all other files are persisted until they are manually deleted.\n */\n export interface ExpiresAfter {\n /**\n * Anchor timestamp after which the expiration policy applies. Supported anchors:\n * `created_at`.\n */\n anchor: 'created_at';\n\n /**\n * The number of seconds after the anchor time that the file will expire. Must be\n * between 3600 (1 hour) and 2592000 (30 days).\n */\n seconds: number;\n }\n}\n\nexport interface FileListParams extends CursorPageParams {\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n\n /**\n * Only return files with the given purpose.\n */\n purpose?: string;\n}\n\nexport declare namespace Files {\n export {\n type FileContent as FileContent,\n type FileDeleted as FileDeleted,\n type FileObject as FileObject,\n type FilePurpose as FilePurpose,\n type FileObjectsPage as FileObjectsPage,\n type FileCreateParams as FileCreateParams,\n type FileListParams as FileListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as GraderModelsAPI from '../graders/grader-models';\n\nexport class Methods extends APIResource {}\n\n/**\n * The hyperparameters used for the DPO fine-tuning job.\n */\nexport interface DpoHyperparameters {\n /**\n * Number of examples in each batch. A larger batch size means that model\n * parameters are updated less frequently, but with lower variance.\n */\n batch_size?: 'auto' | number;\n\n /**\n * The beta value for the DPO method. A higher beta value will increase the weight\n * of the penalty between the policy and reference model.\n */\n beta?: 'auto' | number;\n\n /**\n * Scaling factor for the learning rate. A smaller learning rate may be useful to\n * avoid overfitting.\n */\n learning_rate_multiplier?: 'auto' | number;\n\n /**\n * The number of epochs to train the model for. An epoch refers to one full cycle\n * through the training dataset.\n */\n n_epochs?: 'auto' | number;\n}\n\n/**\n * Configuration for the DPO fine-tuning method.\n */\nexport interface DpoMethod {\n /**\n * The hyperparameters used for the DPO fine-tuning job.\n */\n hyperparameters?: DpoHyperparameters;\n}\n\n/**\n * The hyperparameters used for the reinforcement fine-tuning job.\n */\nexport interface ReinforcementHyperparameters {\n /**\n * Number of examples in each batch. A larger batch size means that model\n * parameters are updated less frequently, but with lower variance.\n */\n batch_size?: 'auto' | number;\n\n /**\n * Multiplier on amount of compute used for exploring search space during training.\n */\n compute_multiplier?: 'auto' | number;\n\n /**\n * The number of training steps between evaluation runs.\n */\n eval_interval?: 'auto' | number;\n\n /**\n * Number of evaluation samples to generate per training step.\n */\n eval_samples?: 'auto' | number;\n\n /**\n * Scaling factor for the learning rate. A smaller learning rate may be useful to\n * avoid overfitting.\n */\n learning_rate_multiplier?: 'auto' | number;\n\n /**\n * The number of epochs to train the model for. An epoch refers to one full cycle\n * through the training dataset.\n */\n n_epochs?: 'auto' | number;\n\n /**\n * Level of reasoning effort.\n */\n reasoning_effort?: 'default' | 'low' | 'medium' | 'high';\n}\n\n/**\n * Configuration for the reinforcement fine-tuning method.\n */\nexport interface ReinforcementMethod {\n /**\n * The grader used for the fine-tuning job.\n */\n grader:\n | GraderModelsAPI.StringCheckGrader\n | GraderModelsAPI.TextSimilarityGrader\n | GraderModelsAPI.PythonGrader\n | GraderModelsAPI.ScoreModelGrader\n | GraderModelsAPI.MultiGrader;\n\n /**\n * The hyperparameters used for the reinforcement fine-tuning job.\n */\n hyperparameters?: ReinforcementHyperparameters;\n}\n\n/**\n * The hyperparameters used for the fine-tuning job.\n */\nexport interface SupervisedHyperparameters {\n /**\n * Number of examples in each batch. A larger batch size means that model\n * parameters are updated less frequently, but with lower variance.\n */\n batch_size?: 'auto' | number;\n\n /**\n * Scaling factor for the learning rate. A smaller learning rate may be useful to\n * avoid overfitting.\n */\n learning_rate_multiplier?: 'auto' | number;\n\n /**\n * The number of epochs to train the model for. An epoch refers to one full cycle\n * through the training dataset.\n */\n n_epochs?: 'auto' | number;\n}\n\n/**\n * Configuration for the supervised fine-tuning method.\n */\nexport interface SupervisedMethod {\n /**\n * The hyperparameters used for the fine-tuning job.\n */\n hyperparameters?: SupervisedHyperparameters;\n}\n\nexport declare namespace Methods {\n export {\n type DpoHyperparameters as DpoHyperparameters,\n type DpoMethod as DpoMethod,\n type ReinforcementHyperparameters as ReinforcementHyperparameters,\n type ReinforcementMethod as ReinforcementMethod,\n type SupervisedHyperparameters as SupervisedHyperparameters,\n type SupervisedMethod as SupervisedMethod,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as GraderModelsAPI from '../../graders/grader-models';\nimport { APIPromise } from '../../../core/api-promise';\nimport { RequestOptions } from '../../../internal/request-options';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Graders extends APIResource {\n /**\n * Run a grader.\n *\n * @example\n * ```ts\n * const response = await client.fineTuning.alpha.graders.run({\n * grader: {\n * input: 'input',\n * name: 'name',\n * operation: 'eq',\n * reference: 'reference',\n * type: 'string_check',\n * },\n * model_sample: 'model_sample',\n * });\n * ```\n */\n run(body: GraderRunParams, options?: RequestOptions): APIPromise<GraderRunResponse> {\n return this._client.post('/fine_tuning/alpha/graders/run', { body, ...options });\n }\n\n /**\n * Validate a grader.\n *\n * @example\n * ```ts\n * const response =\n * await client.fineTuning.alpha.graders.validate({\n * grader: {\n * input: 'input',\n * name: 'name',\n * operation: 'eq',\n * reference: 'reference',\n * type: 'string_check',\n * },\n * });\n * ```\n */\n validate(body: GraderValidateParams, options?: RequestOptions): APIPromise<GraderValidateResponse> {\n return this._client.post('/fine_tuning/alpha/graders/validate', { body, ...options });\n }\n}\n\nexport interface GraderRunResponse {\n metadata: GraderRunResponse.Metadata;\n\n model_grader_token_usage_per_model: { [key: string]: unknown };\n\n reward: number;\n\n sub_rewards: { [key: string]: unknown };\n}\n\nexport namespace GraderRunResponse {\n export interface Metadata {\n errors: Metadata.Errors;\n\n execution_time: number;\n\n name: string;\n\n sampled_model_name: string | null;\n\n scores: { [key: string]: unknown };\n\n token_usage: number | null;\n\n type: string;\n }\n\n export namespace Metadata {\n export interface Errors {\n formula_parse_error: boolean;\n\n invalid_variable_error: boolean;\n\n model_grader_parse_error: boolean;\n\n model_grader_refusal_error: boolean;\n\n model_grader_server_error: boolean;\n\n model_grader_server_error_details: string | null;\n\n other_error: boolean;\n\n python_grader_runtime_error: boolean;\n\n python_grader_runtime_error_details: string | null;\n\n python_grader_server_error: boolean;\n\n python_grader_server_error_type: string | null;\n\n sample_parse_error: boolean;\n\n truncated_observation_error: boolean;\n\n unresponsive_reward_error: boolean;\n }\n }\n}\n\nexport interface GraderValidateResponse {\n /**\n * The grader used for the fine-tuning job.\n */\n grader?:\n | GraderModelsAPI.StringCheckGrader\n | GraderModelsAPI.TextSimilarityGrader\n | GraderModelsAPI.PythonGrader\n | GraderModelsAPI.ScoreModelGrader\n | GraderModelsAPI.MultiGrader;\n}\n\nexport interface GraderRunParams {\n /**\n * The grader used for the fine-tuning job.\n */\n grader:\n | GraderModelsAPI.StringCheckGrader\n | GraderModelsAPI.TextSimilarityGrader\n | GraderModelsAPI.PythonGrader\n | GraderModelsAPI.ScoreModelGrader\n | GraderModelsAPI.MultiGrader;\n\n /**\n * The model sample to be evaluated. This value will be used to populate the\n * `sample` namespace. See\n * [the guide](https://platform.openai.com/docs/guides/graders) for more details.\n * The `output_json` variable will be populated if the model sample is a valid JSON\n * string.\n */\n model_sample: string;\n\n /**\n * The dataset item provided to the grader. This will be used to populate the\n * `item` namespace. See\n * [the guide](https://platform.openai.com/docs/guides/graders) for more details.\n */\n item?: unknown;\n}\n\nexport interface GraderValidateParams {\n /**\n * The grader used for the fine-tuning job.\n */\n grader:\n | GraderModelsAPI.StringCheckGrader\n | GraderModelsAPI.TextSimilarityGrader\n | GraderModelsAPI.PythonGrader\n | GraderModelsAPI.ScoreModelGrader\n | GraderModelsAPI.MultiGrader;\n}\n\nexport declare namespace Graders {\n export {\n type GraderRunResponse as GraderRunResponse,\n type GraderValidateResponse as GraderValidateResponse,\n type GraderRunParams as GraderRunParams,\n type GraderValidateParams as GraderValidateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as GradersAPI from './graders';\nimport {\n GraderRunParams,\n GraderRunResponse,\n GraderValidateParams,\n GraderValidateResponse,\n Graders,\n} from './graders';\n\nexport class Alpha extends APIResource {\n graders: GradersAPI.Graders = new GradersAPI.Graders(this._client);\n}\n\nAlpha.Graders = Graders;\n\nexport declare namespace Alpha {\n export {\n Graders as Graders,\n type GraderRunResponse as GraderRunResponse,\n type GraderValidateResponse as GraderValidateResponse,\n type GraderRunParams as GraderRunParams,\n type GraderValidateParams as GraderValidateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport {\n ConversationCursorPage,\n type ConversationCursorPageParams,\n Page,\n PagePromise,\n} from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Permissions extends APIResource {\n /**\n * **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys).\n *\n * This enables organization owners to share fine-tuned models with other projects\n * in their organization.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const permissionCreateResponse of client.fineTuning.checkpoints.permissions.create(\n * 'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n * { project_ids: ['string'] },\n * )) {\n * // ...\n * }\n * ```\n */\n create(\n fineTunedModelCheckpoint: string,\n body: PermissionCreateParams,\n options?: RequestOptions,\n ): PagePromise<PermissionCreateResponsesPage, PermissionCreateResponse> {\n return this._client.getAPIList(\n path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`,\n Page<PermissionCreateResponse>,\n { body, method: 'post', ...options },\n );\n }\n\n /**\n * **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).\n *\n * Organization owners can use this endpoint to view all permissions for a\n * fine-tuned model checkpoint.\n *\n * @deprecated Retrieve is deprecated. Please swap to the paginated list method instead.\n */\n retrieve(\n fineTunedModelCheckpoint: string,\n query: PermissionRetrieveParams | null | undefined = {},\n options?: RequestOptions,\n ): APIPromise<PermissionRetrieveResponse> {\n return this._client.get(path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`, {\n query,\n ...options,\n });\n }\n\n /**\n * **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).\n *\n * Organization owners can use this endpoint to view all permissions for a\n * fine-tuned model checkpoint.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const permissionListResponse of client.fineTuning.checkpoints.permissions.list(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * )) {\n * // ...\n * }\n * ```\n */\n list(\n fineTunedModelCheckpoint: string,\n query: PermissionListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<PermissionListResponsesPage, PermissionListResponse> {\n return this._client.getAPIList(\n path`/fine_tuning/checkpoints/${fineTunedModelCheckpoint}/permissions`,\n ConversationCursorPage<PermissionListResponse>,\n { query, ...options },\n );\n }\n\n /**\n * **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).\n *\n * Organization owners can use this endpoint to delete a permission for a\n * fine-tuned model checkpoint.\n *\n * @example\n * ```ts\n * const permission =\n * await client.fineTuning.checkpoints.permissions.delete(\n * 'cp_zc4Q7MP6XxulcVzj4MZdwsAB',\n * {\n * fine_tuned_model_checkpoint:\n * 'ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd',\n * },\n * );\n * ```\n */\n delete(\n permissionID: string,\n params: PermissionDeleteParams,\n options?: RequestOptions,\n ): APIPromise<PermissionDeleteResponse> {\n const { fine_tuned_model_checkpoint } = params;\n return this._client.delete(\n path`/fine_tuning/checkpoints/${fine_tuned_model_checkpoint}/permissions/${permissionID}`,\n options,\n );\n }\n}\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type PermissionCreateResponsesPage = Page<PermissionCreateResponse>;\n\nexport type PermissionListResponsesPage = ConversationCursorPage<PermissionListResponse>;\n\n/**\n * The `checkpoint.permission` object represents a permission for a fine-tuned\n * model checkpoint.\n */\nexport interface PermissionCreateResponse {\n /**\n * The permission identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the permission was created.\n */\n created_at: number;\n\n /**\n * The object type, which is always \"checkpoint.permission\".\n */\n object: 'checkpoint.permission';\n\n /**\n * The project identifier that the permission is for.\n */\n project_id: string;\n}\n\nexport interface PermissionRetrieveResponse {\n data: Array<PermissionRetrieveResponse.Data>;\n\n has_more: boolean;\n\n object: 'list';\n\n first_id?: string | null;\n\n last_id?: string | null;\n}\n\nexport namespace PermissionRetrieveResponse {\n /**\n * The `checkpoint.permission` object represents a permission for a fine-tuned\n * model checkpoint.\n */\n export interface Data {\n /**\n * The permission identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the permission was created.\n */\n created_at: number;\n\n /**\n * The object type, which is always \"checkpoint.permission\".\n */\n object: 'checkpoint.permission';\n\n /**\n * The project identifier that the permission is for.\n */\n project_id: string;\n }\n}\n\n/**\n * The `checkpoint.permission` object represents a permission for a fine-tuned\n * model checkpoint.\n */\nexport interface PermissionListResponse {\n /**\n * The permission identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the permission was created.\n */\n created_at: number;\n\n /**\n * The object type, which is always \"checkpoint.permission\".\n */\n object: 'checkpoint.permission';\n\n /**\n * The project identifier that the permission is for.\n */\n project_id: string;\n}\n\nexport interface PermissionDeleteResponse {\n /**\n * The ID of the fine-tuned model checkpoint permission that was deleted.\n */\n id: string;\n\n /**\n * Whether the fine-tuned model checkpoint permission was successfully deleted.\n */\n deleted: boolean;\n\n /**\n * The object type, which is always \"checkpoint.permission\".\n */\n object: 'checkpoint.permission';\n}\n\nexport interface PermissionCreateParams {\n /**\n * The project identifiers to grant access to.\n */\n project_ids: Array<string>;\n}\n\nexport interface PermissionRetrieveParams {\n /**\n * Identifier for the last permission ID from the previous pagination request.\n */\n after?: string;\n\n /**\n * Number of permissions to retrieve.\n */\n limit?: number;\n\n /**\n * The order in which to retrieve permissions.\n */\n order?: 'ascending' | 'descending';\n\n /**\n * The ID of the project to get permissions for.\n */\n project_id?: string;\n}\n\nexport interface PermissionListParams extends ConversationCursorPageParams {\n /**\n * The order in which to retrieve permissions.\n */\n order?: 'ascending' | 'descending';\n\n /**\n * The ID of the project to get permissions for.\n */\n project_id?: string;\n}\n\nexport interface PermissionDeleteParams {\n /**\n * The ID of the fine-tuned model checkpoint to delete a permission for.\n */\n fine_tuned_model_checkpoint: string;\n}\n\nexport declare namespace Permissions {\n export {\n type PermissionCreateResponse as PermissionCreateResponse,\n type PermissionRetrieveResponse as PermissionRetrieveResponse,\n type PermissionListResponse as PermissionListResponse,\n type PermissionDeleteResponse as PermissionDeleteResponse,\n type PermissionCreateResponsesPage as PermissionCreateResponsesPage,\n type PermissionListResponsesPage as PermissionListResponsesPage,\n type PermissionCreateParams as PermissionCreateParams,\n type PermissionRetrieveParams as PermissionRetrieveParams,\n type PermissionListParams as PermissionListParams,\n type PermissionDeleteParams as PermissionDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as PermissionsAPI from './permissions';\nimport {\n PermissionCreateParams,\n PermissionCreateResponse,\n PermissionCreateResponsesPage,\n PermissionDeleteParams,\n PermissionDeleteResponse,\n PermissionListParams,\n PermissionListResponse,\n PermissionListResponsesPage,\n PermissionRetrieveParams,\n PermissionRetrieveResponse,\n Permissions,\n} from './permissions';\n\nexport class Checkpoints extends APIResource {\n permissions: PermissionsAPI.Permissions = new PermissionsAPI.Permissions(this._client);\n}\n\nCheckpoints.Permissions = Permissions;\n\nexport declare namespace Checkpoints {\n export {\n Permissions as Permissions,\n type PermissionCreateResponse as PermissionCreateResponse,\n type PermissionRetrieveResponse as PermissionRetrieveResponse,\n type PermissionListResponse as PermissionListResponse,\n type PermissionDeleteResponse as PermissionDeleteResponse,\n type PermissionCreateResponsesPage as PermissionCreateResponsesPage,\n type PermissionListResponsesPage as PermissionListResponsesPage,\n type PermissionCreateParams as PermissionCreateParams,\n type PermissionRetrieveParams as PermissionRetrieveParams,\n type PermissionListParams as PermissionListParams,\n type PermissionDeleteParams as PermissionDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Checkpoints extends APIResource {\n /**\n * List checkpoints for a fine-tuning job.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const fineTuningJobCheckpoint of client.fineTuning.jobs.checkpoints.list(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * )) {\n * // ...\n * }\n * ```\n */\n list(\n fineTuningJobID: string,\n query: CheckpointListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<FineTuningJobCheckpointsPage, FineTuningJobCheckpoint> {\n return this._client.getAPIList(\n path`/fine_tuning/jobs/${fineTuningJobID}/checkpoints`,\n CursorPage<FineTuningJobCheckpoint>,\n { query, ...options },\n );\n }\n}\n\nexport type FineTuningJobCheckpointsPage = CursorPage<FineTuningJobCheckpoint>;\n\n/**\n * The `fine_tuning.job.checkpoint` object represents a model checkpoint for a\n * fine-tuning job that is ready to use.\n */\nexport interface FineTuningJobCheckpoint {\n /**\n * The checkpoint identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the checkpoint was created.\n */\n created_at: number;\n\n /**\n * The name of the fine-tuned checkpoint model that is created.\n */\n fine_tuned_model_checkpoint: string;\n\n /**\n * The name of the fine-tuning job that this checkpoint was created from.\n */\n fine_tuning_job_id: string;\n\n /**\n * Metrics at the step number during the fine-tuning job.\n */\n metrics: FineTuningJobCheckpoint.Metrics;\n\n /**\n * The object type, which is always \"fine_tuning.job.checkpoint\".\n */\n object: 'fine_tuning.job.checkpoint';\n\n /**\n * The step number that the checkpoint was created at.\n */\n step_number: number;\n}\n\nexport namespace FineTuningJobCheckpoint {\n /**\n * Metrics at the step number during the fine-tuning job.\n */\n export interface Metrics {\n full_valid_loss?: number;\n\n full_valid_mean_token_accuracy?: number;\n\n step?: number;\n\n train_loss?: number;\n\n train_mean_token_accuracy?: number;\n\n valid_loss?: number;\n\n valid_mean_token_accuracy?: number;\n }\n}\n\nexport interface CheckpointListParams extends CursorPageParams {}\n\nexport declare namespace Checkpoints {\n export {\n type FineTuningJobCheckpoint as FineTuningJobCheckpoint,\n type FineTuningJobCheckpointsPage as FineTuningJobCheckpointsPage,\n type CheckpointListParams as CheckpointListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as Shared from '../../shared';\nimport * as MethodsAPI from '../methods';\nimport * as CheckpointsAPI from './checkpoints';\nimport {\n CheckpointListParams,\n Checkpoints,\n FineTuningJobCheckpoint,\n FineTuningJobCheckpointsPage,\n} from './checkpoints';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\n/**\n * Manage fine-tuning jobs to tailor a model to your specific training data.\n */\nexport class Jobs extends APIResource {\n checkpoints: CheckpointsAPI.Checkpoints = new CheckpointsAPI.Checkpoints(this._client);\n\n /**\n * Creates a fine-tuning job which begins the process of creating a new model from\n * a given dataset.\n *\n * Response includes details of the enqueued job including job status and the name\n * of the fine-tuned models once complete.\n *\n * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)\n *\n * @example\n * ```ts\n * const fineTuningJob = await client.fineTuning.jobs.create({\n * model: 'gpt-4o-mini',\n * training_file: 'file-abc123',\n * });\n * ```\n */\n create(body: JobCreateParams, options?: RequestOptions): APIPromise<FineTuningJob> {\n return this._client.post('/fine_tuning/jobs', { body, ...options });\n }\n\n /**\n * Get info about a fine-tuning job.\n *\n * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/model-optimization)\n *\n * @example\n * ```ts\n * const fineTuningJob = await client.fineTuning.jobs.retrieve(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * );\n * ```\n */\n retrieve(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n return this._client.get(path`/fine_tuning/jobs/${fineTuningJobID}`, options);\n }\n\n /**\n * List your organization's fine-tuning jobs\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const fineTuningJob of client.fineTuning.jobs.list()) {\n * // ...\n * }\n * ```\n */\n list(\n query: JobListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<FineTuningJobsPage, FineTuningJob> {\n return this._client.getAPIList('/fine_tuning/jobs', CursorPage<FineTuningJob>, { query, ...options });\n }\n\n /**\n * Immediately cancel a fine-tune job.\n *\n * @example\n * ```ts\n * const fineTuningJob = await client.fineTuning.jobs.cancel(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * );\n * ```\n */\n cancel(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n return this._client.post(path`/fine_tuning/jobs/${fineTuningJobID}/cancel`, options);\n }\n\n /**\n * Get status updates for a fine-tuning job.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const fineTuningJobEvent of client.fineTuning.jobs.listEvents(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * )) {\n * // ...\n * }\n * ```\n */\n listEvents(\n fineTuningJobID: string,\n query: JobListEventsParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<FineTuningJobEventsPage, FineTuningJobEvent> {\n return this._client.getAPIList(\n path`/fine_tuning/jobs/${fineTuningJobID}/events`,\n CursorPage<FineTuningJobEvent>,\n { query, ...options },\n );\n }\n\n /**\n * Pause a fine-tune job.\n *\n * @example\n * ```ts\n * const fineTuningJob = await client.fineTuning.jobs.pause(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * );\n * ```\n */\n pause(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n return this._client.post(path`/fine_tuning/jobs/${fineTuningJobID}/pause`, options);\n }\n\n /**\n * Resume a fine-tune job.\n *\n * @example\n * ```ts\n * const fineTuningJob = await client.fineTuning.jobs.resume(\n * 'ft-AF1WoRqd3aJAHsqc9NY7iL8F',\n * );\n * ```\n */\n resume(fineTuningJobID: string, options?: RequestOptions): APIPromise<FineTuningJob> {\n return this._client.post(path`/fine_tuning/jobs/${fineTuningJobID}/resume`, options);\n }\n}\n\nexport type FineTuningJobsPage = CursorPage<FineTuningJob>;\n\nexport type FineTuningJobEventsPage = CursorPage<FineTuningJobEvent>;\n\n/**\n * The `fine_tuning.job` object represents a fine-tuning job that has been created\n * through the API.\n */\nexport interface FineTuningJob {\n /**\n * The object identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the fine-tuning job was created.\n */\n created_at: number;\n\n /**\n * For fine-tuning jobs that have `failed`, this will contain more information on\n * the cause of the failure.\n */\n error: FineTuningJob.Error | null;\n\n /**\n * The name of the fine-tuned model that is being created. The value will be null\n * if the fine-tuning job is still running.\n */\n fine_tuned_model: string | null;\n\n /**\n * The Unix timestamp (in seconds) for when the fine-tuning job was finished. The\n * value will be null if the fine-tuning job is still running.\n */\n finished_at: number | null;\n\n /**\n * The hyperparameters used for the fine-tuning job. This value will only be\n * returned when running `supervised` jobs.\n */\n hyperparameters: FineTuningJob.Hyperparameters;\n\n /**\n * The base model that is being fine-tuned.\n */\n model: string;\n\n /**\n * The object type, which is always \"fine_tuning.job\".\n */\n object: 'fine_tuning.job';\n\n /**\n * The organization that owns the fine-tuning job.\n */\n organization_id: string;\n\n /**\n * The compiled results file ID(s) for the fine-tuning job. You can retrieve the\n * results with the\n * [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).\n */\n result_files: Array<string>;\n\n /**\n * The seed used for the fine-tuning job.\n */\n seed: number;\n\n /**\n * The current status of the fine-tuning job, which can be either\n * `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.\n */\n status: 'validating_files' | 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled';\n\n /**\n * The total number of billable tokens processed by this fine-tuning job. The value\n * will be null if the fine-tuning job is still running.\n */\n trained_tokens: number | null;\n\n /**\n * The file ID used for training. You can retrieve the training data with the\n * [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).\n */\n training_file: string;\n\n /**\n * The file ID used for validation. You can retrieve the validation results with\n * the\n * [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).\n */\n validation_file: string | null;\n\n /**\n * The Unix timestamp (in seconds) for when the fine-tuning job is estimated to\n * finish. The value will be null if the fine-tuning job is not running.\n */\n estimated_finish?: number | null;\n\n /**\n * A list of integrations to enable for this fine-tuning job.\n */\n integrations?: Array<FineTuningJobWandbIntegrationObject> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The method used for fine-tuning.\n */\n method?: FineTuningJob.Method;\n}\n\nexport namespace FineTuningJob {\n /**\n * For fine-tuning jobs that have `failed`, this will contain more information on\n * the cause of the failure.\n */\n export interface Error {\n /**\n * A machine-readable error code.\n */\n code: string;\n\n /**\n * A human-readable error message.\n */\n message: string;\n\n /**\n * The parameter that was invalid, usually `training_file` or `validation_file`.\n * This field will be null if the failure was not parameter-specific.\n */\n param: string | null;\n }\n\n /**\n * The hyperparameters used for the fine-tuning job. This value will only be\n * returned when running `supervised` jobs.\n */\n export interface Hyperparameters {\n /**\n * Number of examples in each batch. A larger batch size means that model\n * parameters are updated less frequently, but with lower variance.\n */\n batch_size?: 'auto' | number | null;\n\n /**\n * Scaling factor for the learning rate. A smaller learning rate may be useful to\n * avoid overfitting.\n */\n learning_rate_multiplier?: 'auto' | number;\n\n /**\n * The number of epochs to train the model for. An epoch refers to one full cycle\n * through the training dataset.\n */\n n_epochs?: 'auto' | number;\n }\n\n /**\n * The method used for fine-tuning.\n */\n export interface Method {\n /**\n * The type of method. Is either `supervised`, `dpo`, or `reinforcement`.\n */\n type: 'supervised' | 'dpo' | 'reinforcement';\n\n /**\n * Configuration for the DPO fine-tuning method.\n */\n dpo?: MethodsAPI.DpoMethod;\n\n /**\n * Configuration for the reinforcement fine-tuning method.\n */\n reinforcement?: MethodsAPI.ReinforcementMethod;\n\n /**\n * Configuration for the supervised fine-tuning method.\n */\n supervised?: MethodsAPI.SupervisedMethod;\n }\n}\n\n/**\n * Fine-tuning job event object\n */\nexport interface FineTuningJobEvent {\n /**\n * The object identifier.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the fine-tuning job was created.\n */\n created_at: number;\n\n /**\n * The log level of the event.\n */\n level: 'info' | 'warn' | 'error';\n\n /**\n * The message of the event.\n */\n message: string;\n\n /**\n * The object type, which is always \"fine_tuning.job.event\".\n */\n object: 'fine_tuning.job.event';\n\n /**\n * The data associated with the event.\n */\n data?: unknown;\n\n /**\n * The type of event.\n */\n type?: 'message' | 'metrics';\n}\n\n/**\n * The settings for your integration with Weights and Biases. This payload\n * specifies the project that metrics will be sent to. Optionally, you can set an\n * explicit display name for your run, add tags to your run, and set a default\n * entity (team, username, etc) to be associated with your run.\n */\nexport interface FineTuningJobWandbIntegration {\n /**\n * The name of the project that the new run will be created under.\n */\n project: string;\n\n /**\n * The entity to use for the run. This allows you to set the team or username of\n * the WandB user that you would like associated with the run. If not set, the\n * default entity for the registered WandB API key is used.\n */\n entity?: string | null;\n\n /**\n * A display name to set for the run. If not set, we will use the Job ID as the\n * name.\n */\n name?: string | null;\n\n /**\n * A list of tags to be attached to the newly created run. These tags are passed\n * through directly to WandB. Some default tags are generated by OpenAI:\n * \"openai/finetune\", \"openai/{base-model}\", \"openai/{ftjob-abcdef}\".\n */\n tags?: Array<string>;\n}\n\nexport interface FineTuningJobWandbIntegrationObject {\n /**\n * The type of the integration being enabled for the fine-tuning job\n */\n type: 'wandb';\n\n /**\n * The settings for your integration with Weights and Biases. This payload\n * specifies the project that metrics will be sent to. Optionally, you can set an\n * explicit display name for your run, add tags to your run, and set a default\n * entity (team, username, etc) to be associated with your run.\n */\n wandb: FineTuningJobWandbIntegration;\n}\n\nexport type FineTuningJobIntegration = FineTuningJobWandbIntegrationObject;\n\nexport interface JobCreateParams {\n /**\n * The name of the model to fine-tune. You can select one of the\n * [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned).\n */\n model: (string & {}) | 'babbage-002' | 'davinci-002' | 'gpt-3.5-turbo' | 'gpt-4o-mini';\n\n /**\n * The ID of an uploaded file that contains training data.\n *\n * See [upload file](https://platform.openai.com/docs/api-reference/files/create)\n * for how to upload a file.\n *\n * Your dataset must be formatted as a JSONL file. Additionally, you must upload\n * your file with the purpose `fine-tune`.\n *\n * The contents of the file should differ depending on if the model uses the\n * [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input),\n * [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)\n * format, or if the fine-tuning method uses the\n * [preference](https://platform.openai.com/docs/api-reference/fine-tuning/preference-input)\n * format.\n *\n * See the\n * [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)\n * for more details.\n */\n training_file: string;\n\n /**\n * @deprecated The hyperparameters used for the fine-tuning job. This value is now\n * deprecated in favor of `method`, and should be passed in under the `method`\n * parameter.\n */\n hyperparameters?: JobCreateParams.Hyperparameters;\n\n /**\n * A list of integrations to enable for your fine-tuning job.\n */\n integrations?: Array<JobCreateParams.Integration> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The method used for fine-tuning.\n */\n method?: JobCreateParams.Method;\n\n /**\n * The seed controls the reproducibility of the job. Passing in the same seed and\n * job parameters should produce the same results, but may differ in rare cases. If\n * a seed is not specified, one will be generated for you.\n */\n seed?: number | null;\n\n /**\n * A string of up to 64 characters that will be added to your fine-tuned model\n * name.\n *\n * For example, a `suffix` of \"custom-model-name\" would produce a model name like\n * `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`.\n */\n suffix?: string | null;\n\n /**\n * The ID of an uploaded file that contains validation data.\n *\n * If you provide this file, the data is used to generate validation metrics\n * periodically during fine-tuning. These metrics can be viewed in the fine-tuning\n * results file. The same data should not be present in both train and validation\n * files.\n *\n * Your dataset must be formatted as a JSONL file. You must upload your file with\n * the purpose `fine-tune`.\n *\n * See the\n * [fine-tuning guide](https://platform.openai.com/docs/guides/model-optimization)\n * for more details.\n */\n validation_file?: string | null;\n}\n\nexport namespace JobCreateParams {\n /**\n * @deprecated The hyperparameters used for the fine-tuning job. This value is now\n * deprecated in favor of `method`, and should be passed in under the `method`\n * parameter.\n */\n export interface Hyperparameters {\n /**\n * Number of examples in each batch. A larger batch size means that model\n * parameters are updated less frequently, but with lower variance.\n */\n batch_size?: 'auto' | number;\n\n /**\n * Scaling factor for the learning rate. A smaller learning rate may be useful to\n * avoid overfitting.\n */\n learning_rate_multiplier?: 'auto' | number;\n\n /**\n * The number of epochs to train the model for. An epoch refers to one full cycle\n * through the training dataset.\n */\n n_epochs?: 'auto' | number;\n }\n\n export interface Integration {\n /**\n * The type of integration to enable. Currently, only \"wandb\" (Weights and Biases)\n * is supported.\n */\n type: 'wandb';\n\n /**\n * The settings for your integration with Weights and Biases. This payload\n * specifies the project that metrics will be sent to. Optionally, you can set an\n * explicit display name for your run, add tags to your run, and set a default\n * entity (team, username, etc) to be associated with your run.\n */\n wandb: Integration.Wandb;\n }\n\n export namespace Integration {\n /**\n * The settings for your integration with Weights and Biases. This payload\n * specifies the project that metrics will be sent to. Optionally, you can set an\n * explicit display name for your run, add tags to your run, and set a default\n * entity (team, username, etc) to be associated with your run.\n */\n export interface Wandb {\n /**\n * The name of the project that the new run will be created under.\n */\n project: string;\n\n /**\n * The entity to use for the run. This allows you to set the team or username of\n * the WandB user that you would like associated with the run. If not set, the\n * default entity for the registered WandB API key is used.\n */\n entity?: string | null;\n\n /**\n * A display name to set for the run. If not set, we will use the Job ID as the\n * name.\n */\n name?: string | null;\n\n /**\n * A list of tags to be attached to the newly created run. These tags are passed\n * through directly to WandB. Some default tags are generated by OpenAI:\n * \"openai/finetune\", \"openai/{base-model}\", \"openai/{ftjob-abcdef}\".\n */\n tags?: Array<string>;\n }\n }\n\n /**\n * The method used for fine-tuning.\n */\n export interface Method {\n /**\n * The type of method. Is either `supervised`, `dpo`, or `reinforcement`.\n */\n type: 'supervised' | 'dpo' | 'reinforcement';\n\n /**\n * Configuration for the DPO fine-tuning method.\n */\n dpo?: MethodsAPI.DpoMethod;\n\n /**\n * Configuration for the reinforcement fine-tuning method.\n */\n reinforcement?: MethodsAPI.ReinforcementMethod;\n\n /**\n * Configuration for the supervised fine-tuning method.\n */\n supervised?: MethodsAPI.SupervisedMethod;\n }\n}\n\nexport interface JobListParams extends CursorPageParams {\n /**\n * Optional metadata filter. To filter, use the syntax `metadata[k]=v`.\n * Alternatively, set `metadata=null` to indicate no metadata.\n */\n metadata?: { [key: string]: string } | null;\n}\n\nexport interface JobListEventsParams extends CursorPageParams {}\n\nJobs.Checkpoints = Checkpoints;\n\nexport declare namespace Jobs {\n export {\n type FineTuningJob as FineTuningJob,\n type FineTuningJobEvent as FineTuningJobEvent,\n type FineTuningJobWandbIntegration as FineTuningJobWandbIntegration,\n type FineTuningJobWandbIntegrationObject as FineTuningJobWandbIntegrationObject,\n type FineTuningJobIntegration as FineTuningJobIntegration,\n type FineTuningJobsPage as FineTuningJobsPage,\n type FineTuningJobEventsPage as FineTuningJobEventsPage,\n type JobCreateParams as JobCreateParams,\n type JobListParams as JobListParams,\n type JobListEventsParams as JobListEventsParams,\n };\n\n export {\n Checkpoints as Checkpoints,\n type FineTuningJobCheckpoint as FineTuningJobCheckpoint,\n type FineTuningJobCheckpointsPage as FineTuningJobCheckpointsPage,\n type CheckpointListParams as CheckpointListParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as MethodsAPI from './methods';\nimport {\n DpoHyperparameters,\n DpoMethod,\n Methods,\n ReinforcementHyperparameters,\n ReinforcementMethod,\n SupervisedHyperparameters,\n SupervisedMethod,\n} from './methods';\nimport * as AlphaAPI from './alpha/alpha';\nimport { Alpha } from './alpha/alpha';\nimport * as CheckpointsAPI from './checkpoints/checkpoints';\nimport { Checkpoints } from './checkpoints/checkpoints';\nimport * as JobsAPI from './jobs/jobs';\nimport {\n FineTuningJob,\n FineTuningJobEvent,\n FineTuningJobEventsPage,\n FineTuningJobIntegration,\n FineTuningJobWandbIntegration,\n FineTuningJobWandbIntegrationObject,\n FineTuningJobsPage,\n JobCreateParams,\n JobListEventsParams,\n JobListParams,\n Jobs,\n} from './jobs/jobs';\n\nexport class FineTuning extends APIResource {\n methods: MethodsAPI.Methods = new MethodsAPI.Methods(this._client);\n jobs: JobsAPI.Jobs = new JobsAPI.Jobs(this._client);\n checkpoints: CheckpointsAPI.Checkpoints = new CheckpointsAPI.Checkpoints(this._client);\n alpha: AlphaAPI.Alpha = new AlphaAPI.Alpha(this._client);\n}\n\nFineTuning.Methods = Methods;\nFineTuning.Jobs = Jobs;\nFineTuning.Checkpoints = Checkpoints;\nFineTuning.Alpha = Alpha;\n\nexport declare namespace FineTuning {\n export {\n Methods as Methods,\n type DpoHyperparameters as DpoHyperparameters,\n type DpoMethod as DpoMethod,\n type ReinforcementHyperparameters as ReinforcementHyperparameters,\n type ReinforcementMethod as ReinforcementMethod,\n type SupervisedHyperparameters as SupervisedHyperparameters,\n type SupervisedMethod as SupervisedMethod,\n };\n\n export {\n Jobs as Jobs,\n type FineTuningJob as FineTuningJob,\n type FineTuningJobEvent as FineTuningJobEvent,\n type FineTuningJobWandbIntegration as FineTuningJobWandbIntegration,\n type FineTuningJobWandbIntegrationObject as FineTuningJobWandbIntegrationObject,\n type FineTuningJobIntegration as FineTuningJobIntegration,\n type FineTuningJobsPage as FineTuningJobsPage,\n type FineTuningJobEventsPage as FineTuningJobEventsPage,\n type JobCreateParams as JobCreateParams,\n type JobListParams as JobListParams,\n type JobListEventsParams as JobListEventsParams,\n };\n\n export { Checkpoints as Checkpoints };\n\n export { Alpha as Alpha };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as GraderModelsAPI from './grader-models';\nimport * as Shared from '../shared';\nimport * as ResponsesAPI from '../responses/responses';\n\nexport class GraderModels extends APIResource {}\n\n/**\n * A list of inputs, each of which may be either an input text, output text, input\n * image, or input audio object.\n */\nexport type GraderInputs = Array<\n | string\n | ResponsesAPI.ResponseInputText\n | GraderInputs.OutputText\n | GraderInputs.InputImage\n | ResponsesAPI.ResponseInputAudio\n>;\n\nexport namespace GraderInputs {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n}\n\n/**\n * A LabelModelGrader object which uses a model to assign labels to each item in\n * the evaluation.\n */\nexport interface LabelModelGrader {\n input: Array<LabelModelGrader.Input>;\n\n /**\n * The labels to assign to each item in the evaluation.\n */\n labels: Array<string>;\n\n /**\n * The model to use for the evaluation. Must support structured outputs.\n */\n model: string;\n\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The labels that indicate a passing result. Must be a subset of labels.\n */\n passing_labels: Array<string>;\n\n /**\n * The object type, which is always `label_model`.\n */\n type: 'label_model';\n}\n\nexport namespace LabelModelGrader {\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface Input {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | Input.OutputText\n | Input.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace Input {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n}\n\n/**\n * A MultiGrader object combines the output of multiple graders to produce a single\n * score.\n */\nexport interface MultiGrader {\n /**\n * A formula to calculate the output based on grader results.\n */\n calculate_output: string;\n\n /**\n * A StringCheckGrader object that performs a string comparison between input and\n * reference using a specified operation.\n */\n graders: StringCheckGrader | TextSimilarityGrader | PythonGrader | ScoreModelGrader | LabelModelGrader;\n\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The object type, which is always `multi`.\n */\n type: 'multi';\n}\n\n/**\n * A PythonGrader object that runs a python script on the input.\n */\nexport interface PythonGrader {\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The source code of the python script.\n */\n source: string;\n\n /**\n * The object type, which is always `python`.\n */\n type: 'python';\n\n /**\n * The image tag to use for the python script.\n */\n image_tag?: string;\n}\n\n/**\n * A ScoreModelGrader object that uses a model to assign a score to the input.\n */\nexport interface ScoreModelGrader {\n /**\n * The input messages evaluated by the grader. Supports text, output text, input\n * image, and input audio content blocks, and may include template strings.\n */\n input: Array<ScoreModelGrader.Input>;\n\n /**\n * The model to use for the evaluation.\n */\n model: string;\n\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The object type, which is always `score_model`.\n */\n type: 'score_model';\n\n /**\n * The range of the score. Defaults to `[0, 1]`.\n */\n range?: Array<number>;\n\n /**\n * The sampling parameters for the model.\n */\n sampling_params?: ScoreModelGrader.SamplingParams;\n}\n\nexport namespace ScoreModelGrader {\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\n export interface Input {\n /**\n * Inputs to the model - can contain template strings. Supports text, output text,\n * input images, and input audio, either as a single item or an array of items.\n */\n content:\n | string\n | ResponsesAPI.ResponseInputText\n | Input.OutputText\n | Input.InputImage\n | ResponsesAPI.ResponseInputAudio\n | GraderModelsAPI.GraderInputs;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n }\n\n export namespace Input {\n /**\n * A text output from the model.\n */\n export interface OutputText {\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n }\n\n /**\n * An image input block used within EvalItem content arrays.\n */\n export interface InputImage {\n /**\n * The URL of the image input.\n */\n image_url: string;\n\n /**\n * The type of the image input. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`, or\n * `auto`. Defaults to `auto`.\n */\n detail?: string;\n }\n }\n\n /**\n * The sampling parameters for the model.\n */\n export interface SamplingParams {\n /**\n * The maximum number of tokens the grader model may generate in its response.\n */\n max_completions_tokens?: number | null;\n\n /**\n * Constrains effort on reasoning for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently\n * supported values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`.\n * Reducing reasoning effort can result in faster responses and fewer tokens used\n * on reasoning in a response.\n *\n * - `gpt-5.1` defaults to `none`, which does not perform reasoning. The supported\n * reasoning values for `gpt-5.1` are `none`, `low`, `medium`, and `high`. Tool\n * calls are supported for all reasoning values in gpt-5.1.\n * - All models before `gpt-5.1` default to `medium` reasoning effort, and do not\n * support `none`.\n * - The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.\n * - `xhigh` is supported for all models after `gpt-5.1-codex-max`.\n */\n reasoning_effort?: Shared.ReasoningEffort | null;\n\n /**\n * A seed value to initialize the randomness, during sampling.\n */\n seed?: number | null;\n\n /**\n * A higher temperature increases randomness in the outputs.\n */\n temperature?: number | null;\n\n /**\n * An alternative to temperature for nucleus sampling; 1.0 includes all tokens.\n */\n top_p?: number | null;\n }\n}\n\n/**\n * A StringCheckGrader object that performs a string comparison between input and\n * reference using a specified operation.\n */\nexport interface StringCheckGrader {\n /**\n * The input text. This may include template strings.\n */\n input: string;\n\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.\n */\n operation: 'eq' | 'ne' | 'like' | 'ilike';\n\n /**\n * The reference text. This may include template strings.\n */\n reference: string;\n\n /**\n * The object type, which is always `string_check`.\n */\n type: 'string_check';\n}\n\n/**\n * A TextSimilarityGrader object which grades text based on similarity metrics.\n */\nexport interface TextSimilarityGrader {\n /**\n * The evaluation metric to use. One of `cosine`, `fuzzy_match`, `bleu`, `gleu`,\n * `meteor`, `rouge_1`, `rouge_2`, `rouge_3`, `rouge_4`, `rouge_5`, or `rouge_l`.\n */\n evaluation_metric:\n | 'cosine'\n | 'fuzzy_match'\n | 'bleu'\n | 'gleu'\n | 'meteor'\n | 'rouge_1'\n | 'rouge_2'\n | 'rouge_3'\n | 'rouge_4'\n | 'rouge_5'\n | 'rouge_l';\n\n /**\n * The text being graded.\n */\n input: string;\n\n /**\n * The name of the grader.\n */\n name: string;\n\n /**\n * The text being graded against.\n */\n reference: string;\n\n /**\n * The type of grader.\n */\n type: 'text_similarity';\n}\n\nexport declare namespace GraderModels {\n export {\n type GraderInputs as GraderInputs,\n type LabelModelGrader as LabelModelGrader,\n type MultiGrader as MultiGrader,\n type PythonGrader as PythonGrader,\n type ScoreModelGrader as ScoreModelGrader,\n type StringCheckGrader as StringCheckGrader,\n type TextSimilarityGrader as TextSimilarityGrader,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as GraderModelsAPI from './grader-models';\nimport {\n GraderInputs,\n GraderModels,\n LabelModelGrader,\n MultiGrader,\n PythonGrader,\n ScoreModelGrader,\n StringCheckGrader,\n TextSimilarityGrader,\n} from './grader-models';\n\nexport class Graders extends APIResource {\n graderModels: GraderModelsAPI.GraderModels = new GraderModelsAPI.GraderModels(this._client);\n}\n\nGraders.GraderModels = GraderModels;\n\nexport declare namespace Graders {\n export {\n GraderModels as GraderModels,\n type GraderInputs as GraderInputs,\n type LabelModelGrader as LabelModelGrader,\n type MultiGrader as MultiGrader,\n type PythonGrader as PythonGrader,\n type ScoreModelGrader as ScoreModelGrader,\n type StringCheckGrader as StringCheckGrader,\n type TextSimilarityGrader as TextSimilarityGrader,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport * as ImagesAPI from './images';\nimport { APIPromise } from '../core/api-promise';\nimport { Stream } from '../core/streaming';\nimport { type Uploadable } from '../core/uploads';\nimport { RequestOptions } from '../internal/request-options';\nimport { multipartFormRequestOptions } from '../internal/uploads';\n\n/**\n * Given a prompt and/or an input image, the model will generate a new image.\n */\nexport class Images extends APIResource {\n /**\n * Creates a variation of a given image. This endpoint only supports `dall-e-2`.\n *\n * @example\n * ```ts\n * const imagesResponse = await client.images.createVariation({\n * image: fs.createReadStream('otter.png'),\n * });\n * ```\n */\n createVariation(body: ImageCreateVariationParams, options?: RequestOptions): APIPromise<ImagesResponse> {\n return this._client.post(\n '/images/variations',\n multipartFormRequestOptions({ body, ...options }, this._client),\n );\n }\n\n /**\n * Creates an edited or extended image given one or more source images and a\n * prompt. This endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`,\n * `gpt-image-1-mini`, and `chatgpt-image-latest`) and `dall-e-2`.\n *\n * @example\n * ```ts\n * const imagesResponse = await client.images.edit({\n * image: fs.createReadStream('path/to/file'),\n * prompt: 'A cute baby sea otter wearing a beret',\n * });\n * ```\n */\n edit(body: ImageEditParamsNonStreaming, options?: RequestOptions): APIPromise<ImagesResponse>;\n edit(body: ImageEditParamsStreaming, options?: RequestOptions): APIPromise<Stream<ImageEditStreamEvent>>;\n edit(\n body: ImageEditParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<ImageEditStreamEvent> | ImagesResponse>;\n edit(\n body: ImageEditParams,\n options?: RequestOptions,\n ): APIPromise<ImagesResponse> | APIPromise<Stream<ImageEditStreamEvent>> {\n return this._client.post(\n '/images/edits',\n multipartFormRequestOptions({ body, ...options, stream: body.stream ?? false }, this._client),\n ) as APIPromise<ImagesResponse> | APIPromise<Stream<ImageEditStreamEvent>>;\n }\n\n /**\n * Creates an image given a prompt.\n * [Learn more](https://platform.openai.com/docs/guides/images).\n *\n * @example\n * ```ts\n * const imagesResponse = await client.images.generate({\n * prompt: 'A cute baby sea otter',\n * });\n * ```\n */\n generate(body: ImageGenerateParamsNonStreaming, options?: RequestOptions): APIPromise<ImagesResponse>;\n generate(\n body: ImageGenerateParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<ImageGenStreamEvent>>;\n generate(\n body: ImageGenerateParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<ImageGenStreamEvent> | ImagesResponse>;\n generate(\n body: ImageGenerateParams,\n options?: RequestOptions,\n ): APIPromise<ImagesResponse> | APIPromise<Stream<ImageGenStreamEvent>> {\n return this._client.post('/images/generations', { body, ...options, stream: body.stream ?? false }) as\n | APIPromise<ImagesResponse>\n | APIPromise<Stream<ImageGenStreamEvent>>;\n }\n}\n\n/**\n * Represents the content or the URL of an image generated by the OpenAI API.\n */\nexport interface Image {\n /**\n * The base64-encoded JSON of the generated image. Returned by default for the GPT\n * image models, and only present if `response_format` is set to `b64_json` for\n * `dall-e-2` and `dall-e-3`.\n */\n b64_json?: string;\n\n /**\n * For `dall-e-3` only, the revised prompt that was used to generate the image.\n */\n revised_prompt?: string;\n\n /**\n * When using `dall-e-2` or `dall-e-3`, the URL of the generated image if\n * `response_format` is set to `url` (default value). Unsupported for the GPT image\n * models.\n */\n url?: string;\n}\n\n/**\n * Emitted when image editing has completed and the final image is available.\n */\nexport interface ImageEditCompletedEvent {\n /**\n * Base64-encoded final edited image data, suitable for rendering as an image.\n */\n b64_json: string;\n\n /**\n * The background setting for the edited image.\n */\n background: 'transparent' | 'opaque' | 'auto';\n\n /**\n * The Unix timestamp when the event was created.\n */\n created_at: number;\n\n /**\n * The output format for the edited image.\n */\n output_format: 'png' | 'webp' | 'jpeg';\n\n /**\n * The quality setting for the edited image.\n */\n quality: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * The size of the edited image.\n */\n size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n /**\n * The type of the event. Always `image_edit.completed`.\n */\n type: 'image_edit.completed';\n\n /**\n * For the GPT image models only, the token usage information for the image\n * generation.\n */\n usage: ImageEditCompletedEvent.Usage;\n}\n\nexport namespace ImageEditCompletedEvent {\n /**\n * For the GPT image models only, the token usage information for the image\n * generation.\n */\n export interface Usage {\n /**\n * The number of tokens (images and text) in the input prompt.\n */\n input_tokens: number;\n\n /**\n * The input tokens detailed information for the image generation.\n */\n input_tokens_details: Usage.InputTokensDetails;\n\n /**\n * The number of image tokens in the output image.\n */\n output_tokens: number;\n\n /**\n * The total number of tokens (images and text) used for the image generation.\n */\n total_tokens: number;\n }\n\n export namespace Usage {\n /**\n * The input tokens detailed information for the image generation.\n */\n export interface InputTokensDetails {\n /**\n * The number of image tokens in the input prompt.\n */\n image_tokens: number;\n\n /**\n * The number of text tokens in the input prompt.\n */\n text_tokens: number;\n }\n }\n}\n\n/**\n * Emitted when a partial image is available during image editing streaming.\n */\nexport interface ImageEditPartialImageEvent {\n /**\n * Base64-encoded partial image data, suitable for rendering as an image.\n */\n b64_json: string;\n\n /**\n * The background setting for the requested edited image.\n */\n background: 'transparent' | 'opaque' | 'auto';\n\n /**\n * The Unix timestamp when the event was created.\n */\n created_at: number;\n\n /**\n * The output format for the requested edited image.\n */\n output_format: 'png' | 'webp' | 'jpeg';\n\n /**\n * 0-based index for the partial image (streaming).\n */\n partial_image_index: number;\n\n /**\n * The quality setting for the requested edited image.\n */\n quality: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * The size of the requested edited image.\n */\n size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n /**\n * The type of the event. Always `image_edit.partial_image`.\n */\n type: 'image_edit.partial_image';\n}\n\n/**\n * Emitted when a partial image is available during image editing streaming.\n */\nexport type ImageEditStreamEvent = ImageEditPartialImageEvent | ImageEditCompletedEvent;\n\n/**\n * Emitted when image generation has completed and the final image is available.\n */\nexport interface ImageGenCompletedEvent {\n /**\n * Base64-encoded image data, suitable for rendering as an image.\n */\n b64_json: string;\n\n /**\n * The background setting for the generated image.\n */\n background: 'transparent' | 'opaque' | 'auto';\n\n /**\n * The Unix timestamp when the event was created.\n */\n created_at: number;\n\n /**\n * The output format for the generated image.\n */\n output_format: 'png' | 'webp' | 'jpeg';\n\n /**\n * The quality setting for the generated image.\n */\n quality: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * The size of the generated image.\n */\n size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n /**\n * The type of the event. Always `image_generation.completed`.\n */\n type: 'image_generation.completed';\n\n /**\n * For the GPT image models only, the token usage information for the image\n * generation.\n */\n usage: ImageGenCompletedEvent.Usage;\n}\n\nexport namespace ImageGenCompletedEvent {\n /**\n * For the GPT image models only, the token usage information for the image\n * generation.\n */\n export interface Usage {\n /**\n * The number of tokens (images and text) in the input prompt.\n */\n input_tokens: number;\n\n /**\n * The input tokens detailed information for the image generation.\n */\n input_tokens_details: Usage.InputTokensDetails;\n\n /**\n * The number of image tokens in the output image.\n */\n output_tokens: number;\n\n /**\n * The total number of tokens (images and text) used for the image generation.\n */\n total_tokens: number;\n }\n\n export namespace Usage {\n /**\n * The input tokens detailed information for the image generation.\n */\n export interface InputTokensDetails {\n /**\n * The number of image tokens in the input prompt.\n */\n image_tokens: number;\n\n /**\n * The number of text tokens in the input prompt.\n */\n text_tokens: number;\n }\n }\n}\n\n/**\n * Emitted when a partial image is available during image generation streaming.\n */\nexport interface ImageGenPartialImageEvent {\n /**\n * Base64-encoded partial image data, suitable for rendering as an image.\n */\n b64_json: string;\n\n /**\n * The background setting for the requested image.\n */\n background: 'transparent' | 'opaque' | 'auto';\n\n /**\n * The Unix timestamp when the event was created.\n */\n created_at: number;\n\n /**\n * The output format for the requested image.\n */\n output_format: 'png' | 'webp' | 'jpeg';\n\n /**\n * 0-based index for the partial image (streaming).\n */\n partial_image_index: number;\n\n /**\n * The quality setting for the requested image.\n */\n quality: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * The size of the requested image.\n */\n size: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n\n /**\n * The type of the event. Always `image_generation.partial_image`.\n */\n type: 'image_generation.partial_image';\n}\n\n/**\n * Emitted when a partial image is available during image generation streaming.\n */\nexport type ImageGenStreamEvent = ImageGenPartialImageEvent | ImageGenCompletedEvent;\n\nexport type ImageModel = 'gpt-image-1.5' | 'dall-e-2' | 'dall-e-3' | 'gpt-image-1' | 'gpt-image-1-mini';\n\n/**\n * The response from the image generation endpoint.\n */\nexport interface ImagesResponse {\n /**\n * The Unix timestamp (in seconds) of when the image was created.\n */\n created: number;\n\n /**\n * The background parameter used for the image generation. Either `transparent` or\n * `opaque`.\n */\n background?: 'transparent' | 'opaque';\n\n /**\n * The list of generated images.\n */\n data?: Array<Image>;\n\n /**\n * The output format of the image generation. Either `png`, `webp`, or `jpeg`.\n */\n output_format?: 'png' | 'webp' | 'jpeg';\n\n /**\n * The quality of the image generated. Either `low`, `medium`, or `high`.\n */\n quality?: 'low' | 'medium' | 'high';\n\n /**\n * The size of the image generated. Either `1024x1024`, `1024x1536`, or\n * `1536x1024`.\n */\n size?: '1024x1024' | '1024x1536' | '1536x1024';\n\n /**\n * For `gpt-image-1` only, the token usage information for the image generation.\n */\n usage?: ImagesResponse.Usage;\n}\n\nexport namespace ImagesResponse {\n /**\n * For `gpt-image-1` only, the token usage information for the image generation.\n */\n export interface Usage {\n /**\n * The number of tokens (images and text) in the input prompt.\n */\n input_tokens: number;\n\n /**\n * The input tokens detailed information for the image generation.\n */\n input_tokens_details: Usage.InputTokensDetails;\n\n /**\n * The number of output tokens generated by the model.\n */\n output_tokens: number;\n\n /**\n * The total number of tokens (images and text) used for the image generation.\n */\n total_tokens: number;\n\n /**\n * The output token details for the image generation.\n */\n output_tokens_details?: Usage.OutputTokensDetails;\n }\n\n export namespace Usage {\n /**\n * The input tokens detailed information for the image generation.\n */\n export interface InputTokensDetails {\n /**\n * The number of image tokens in the input prompt.\n */\n image_tokens: number;\n\n /**\n * The number of text tokens in the input prompt.\n */\n text_tokens: number;\n }\n\n /**\n * The output token details for the image generation.\n */\n export interface OutputTokensDetails {\n /**\n * The number of image output tokens generated by the model.\n */\n image_tokens: number;\n\n /**\n * The number of text output tokens generated by the model.\n */\n text_tokens: number;\n }\n }\n}\n\nexport interface ImageCreateVariationParams {\n /**\n * The image to use as the basis for the variation(s). Must be a valid PNG file,\n * less than 4MB, and square.\n */\n image: Uploadable;\n\n /**\n * The model to use for image generation. Only `dall-e-2` is supported at this\n * time.\n */\n model?: (string & {}) | ImageModel | null;\n\n /**\n * The number of images to generate. Must be between 1 and 10.\n */\n n?: number | null;\n\n /**\n * The format in which the generated images are returned. Must be one of `url` or\n * `b64_json`. URLs are only valid for 60 minutes after the image has been\n * generated.\n */\n response_format?: 'url' | 'b64_json' | null;\n\n /**\n * The size of the generated images. Must be one of `256x256`, `512x512`, or\n * `1024x1024`.\n */\n size?: '256x256' | '512x512' | '1024x1024' | null;\n\n /**\n * A unique identifier representing your end-user, which can help OpenAI to monitor\n * and detect abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n */\n user?: string;\n}\n\nexport type ImageEditParams = ImageEditParamsNonStreaming | ImageEditParamsStreaming;\n\nexport interface ImageEditParamsBase {\n /**\n * The image(s) to edit. Must be a supported image file or an array of images.\n *\n * For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, and\n * `gpt-image-1.5`), each image should be a `png`, `webp`, or `jpg` file less than\n * 50MB. You can provide up to 16 images. `chatgpt-image-latest` follows the same\n * input constraints as GPT image models.\n *\n * For `dall-e-2`, you can only provide one image, and it should be a square `png`\n * file less than 4MB.\n */\n image: Uploadable | Array<Uploadable>;\n\n /**\n * A text description of the desired image(s). The maximum length is 1000\n * characters for `dall-e-2`, and 32000 characters for the GPT image models.\n */\n prompt: string;\n\n /**\n * Allows to set transparency for the background of the generated image(s). This\n * parameter is only supported for the GPT image models. Must be one of\n * `transparent`, `opaque` or `auto` (default value). When `auto` is used, the\n * model will automatically determine the best background for the image.\n *\n * If `transparent`, the output format needs to support transparency, so it should\n * be set to either `png` (default value) or `webp`.\n */\n background?: 'transparent' | 'opaque' | 'auto' | null;\n\n /**\n * Control how much effort the model will exert to match the style and features,\n * especially facial features, of input images. This parameter is only supported\n * for `gpt-image-1` and `gpt-image-1.5` and later models, unsupported for\n * `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.\n */\n input_fidelity?: 'high' | 'low' | null;\n\n /**\n * An additional image whose fully transparent areas (e.g. where alpha is zero)\n * indicate where `image` should be edited. If there are multiple images provided,\n * the mask will be applied on the first image. Must be a valid PNG file, less than\n * 4MB, and have the same dimensions as `image`.\n */\n mask?: Uploadable;\n\n /**\n * The model to use for image generation. Defaults to `gpt-image-1.5`.\n */\n model?: (string & {}) | ImageModel | null;\n\n /**\n * The number of images to generate. Must be between 1 and 10.\n */\n n?: number | null;\n\n /**\n * The compression level (0-100%) for the generated images. This parameter is only\n * supported for the GPT image models with the `webp` or `jpeg` output formats, and\n * defaults to 100.\n */\n output_compression?: number | null;\n\n /**\n * The format in which the generated images are returned. This parameter is only\n * supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`. The\n * default value is `png`.\n */\n output_format?: 'png' | 'jpeg' | 'webp' | null;\n\n /**\n * The number of partial images to generate. This parameter is used for streaming\n * responses that return partial images. Value must be between 0 and 3. When set to\n * 0, the response will be a single image sent in one streaming event.\n *\n * Note that the final image may be sent before the full number of partial images\n * are generated if the full image is generated more quickly.\n */\n partial_images?: number | null;\n\n /**\n * The quality of the image that will be generated for GPT image models. Defaults\n * to `auto`.\n */\n quality?: 'standard' | 'low' | 'medium' | 'high' | 'auto' | null;\n\n /**\n * The format in which the generated images are returned. Must be one of `url` or\n * `b64_json`. URLs are only valid for 60 minutes after the image has been\n * generated. This parameter is only supported for `dall-e-2` (default is `url` for\n * `dall-e-2`), as GPT image models always return base64-encoded images.\n */\n response_format?: 'url' | 'b64_json' | null;\n\n /**\n * The size of the generated images. Must be one of `1024x1024`, `1536x1024`\n * (landscape), `1024x1536` (portrait), or `auto` (default value) for the GPT image\n * models, and one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`.\n */\n size?: '256x256' | '512x512' | '1024x1024' | '1536x1024' | '1024x1536' | 'auto' | null;\n\n /**\n * Edit the image in streaming mode. Defaults to `false`. See the\n * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n * for more information.\n */\n stream?: boolean | null;\n\n /**\n * A unique identifier representing your end-user, which can help OpenAI to monitor\n * and detect abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n */\n user?: string;\n}\n\nexport namespace ImageEditParams {\n export type ImageEditParamsNonStreaming = ImagesAPI.ImageEditParamsNonStreaming;\n export type ImageEditParamsStreaming = ImagesAPI.ImageEditParamsStreaming;\n}\n\nexport interface ImageEditParamsNonStreaming extends ImageEditParamsBase {\n /**\n * Edit the image in streaming mode. Defaults to `false`. See the\n * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n * for more information.\n */\n stream?: false | null;\n}\n\nexport interface ImageEditParamsStreaming extends ImageEditParamsBase {\n /**\n * Edit the image in streaming mode. Defaults to `false`. See the\n * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n * for more information.\n */\n stream: true;\n}\n\nexport type ImageGenerateParams = ImageGenerateParamsNonStreaming | ImageGenerateParamsStreaming;\n\nexport interface ImageGenerateParamsBase {\n /**\n * A text description of the desired image(s). The maximum length is 32000\n * characters for the GPT image models, 1000 characters for `dall-e-2` and 4000\n * characters for `dall-e-3`.\n */\n prompt: string;\n\n /**\n * Allows to set transparency for the background of the generated image(s). This\n * parameter is only supported for the GPT image models. Must be one of\n * `transparent`, `opaque` or `auto` (default value). When `auto` is used, the\n * model will automatically determine the best background for the image.\n *\n * If `transparent`, the output format needs to support transparency, so it should\n * be set to either `png` (default value) or `webp`.\n */\n background?: 'transparent' | 'opaque' | 'auto' | null;\n\n /**\n * The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or a GPT\n * image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`). Defaults to\n * `dall-e-2` unless a parameter specific to the GPT image models is used.\n */\n model?: (string & {}) | ImageModel | null;\n\n /**\n * Control the content-moderation level for images generated by the GPT image\n * models. Must be either `low` for less restrictive filtering or `auto` (default\n * value).\n */\n moderation?: 'low' | 'auto' | null;\n\n /**\n * The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only\n * `n=1` is supported.\n */\n n?: number | null;\n\n /**\n * The compression level (0-100%) for the generated images. This parameter is only\n * supported for the GPT image models with the `webp` or `jpeg` output formats, and\n * defaults to 100.\n */\n output_compression?: number | null;\n\n /**\n * The format in which the generated images are returned. This parameter is only\n * supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.\n */\n output_format?: 'png' | 'jpeg' | 'webp' | null;\n\n /**\n * The number of partial images to generate. This parameter is used for streaming\n * responses that return partial images. Value must be between 0 and 3. When set to\n * 0, the response will be a single image sent in one streaming event.\n *\n * Note that the final image may be sent before the full number of partial images\n * are generated if the full image is generated more quickly.\n */\n partial_images?: number | null;\n\n /**\n * The quality of the image that will be generated.\n *\n * - `auto` (default value) will automatically select the best quality for the\n * given model.\n * - `high`, `medium` and `low` are supported for the GPT image models.\n * - `hd` and `standard` are supported for `dall-e-3`.\n * - `standard` is the only option for `dall-e-2`.\n */\n quality?: 'standard' | 'hd' | 'low' | 'medium' | 'high' | 'auto' | null;\n\n /**\n * The format in which generated images with `dall-e-2` and `dall-e-3` are\n * returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes\n * after the image has been generated. This parameter isn't supported for the GPT\n * image models, which always return base64-encoded images.\n */\n response_format?: 'url' | 'b64_json' | null;\n\n /**\n * The size of the generated images. Must be one of `1024x1024`, `1536x1024`\n * (landscape), `1024x1536` (portrait), or `auto` (default value) for the GPT image\n * models, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of\n * `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.\n */\n size?:\n | 'auto'\n | '1024x1024'\n | '1536x1024'\n | '1024x1536'\n | '256x256'\n | '512x512'\n | '1792x1024'\n | '1024x1792'\n | null;\n\n /**\n * Generate the image in streaming mode. Defaults to `false`. See the\n * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n * for more information. This parameter is only supported for the GPT image models.\n */\n stream?: boolean | null;\n\n /**\n * The style of the generated images. This parameter is only supported for\n * `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean\n * towards generating hyper-real and dramatic images. Natural causes the model to\n * produce more natural, less hyper-real looking images.\n */\n style?: 'vivid' | 'natural' | null;\n\n /**\n * A unique identifier representing your end-user, which can help OpenAI to monitor\n * and detect abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).\n */\n user?: string;\n}\n\nexport namespace ImageGenerateParams {\n export type ImageGenerateParamsNonStreaming = ImagesAPI.ImageGenerateParamsNonStreaming;\n export type ImageGenerateParamsStreaming = ImagesAPI.ImageGenerateParamsStreaming;\n}\n\nexport interface ImageGenerateParamsNonStreaming extends ImageGenerateParamsBase {\n /**\n * Generate the image in streaming mode. Defaults to `false`. See the\n * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n * for more information. This parameter is only supported for the GPT image models.\n */\n stream?: false | null;\n}\n\nexport interface ImageGenerateParamsStreaming extends ImageGenerateParamsBase {\n /**\n * Generate the image in streaming mode. Defaults to `false`. See the\n * [Image generation guide](https://platform.openai.com/docs/guides/image-generation)\n * for more information. This parameter is only supported for the GPT image models.\n */\n stream: true;\n}\n\nexport declare namespace Images {\n export {\n type Image as Image,\n type ImageEditCompletedEvent as ImageEditCompletedEvent,\n type ImageEditPartialImageEvent as ImageEditPartialImageEvent,\n type ImageEditStreamEvent as ImageEditStreamEvent,\n type ImageGenCompletedEvent as ImageGenCompletedEvent,\n type ImageGenPartialImageEvent as ImageGenPartialImageEvent,\n type ImageGenStreamEvent as ImageGenStreamEvent,\n type ImageModel as ImageModel,\n type ImagesResponse as ImagesResponse,\n type ImageCreateVariationParams as ImageCreateVariationParams,\n type ImageEditParams as ImageEditParams,\n type ImageEditParamsNonStreaming as ImageEditParamsNonStreaming,\n type ImageEditParamsStreaming as ImageEditParamsStreaming,\n type ImageGenerateParams as ImageGenerateParams,\n type ImageGenerateParamsNonStreaming as ImageGenerateParamsNonStreaming,\n type ImageGenerateParamsStreaming as ImageGenerateParamsStreaming,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { Page, PagePromise } from '../core/pagination';\nimport { RequestOptions } from '../internal/request-options';\nimport { path } from '../internal/utils/path';\n\n/**\n * List and describe the various models available in the API.\n */\nexport class Models extends APIResource {\n /**\n * Retrieves a model instance, providing basic information about the model such as\n * the owner and permissioning.\n */\n retrieve(model: string, options?: RequestOptions): APIPromise<Model> {\n return this._client.get(path`/models/${model}`, options);\n }\n\n /**\n * Lists the currently available models, and provides basic information about each\n * one such as the owner and availability.\n */\n list(options?: RequestOptions): PagePromise<ModelsPage, Model> {\n return this._client.getAPIList('/models', Page<Model>, options);\n }\n\n /**\n * Delete a fine-tuned model. You must have the Owner role in your organization to\n * delete a model.\n */\n delete(model: string, options?: RequestOptions): APIPromise<ModelDeleted> {\n return this._client.delete(path`/models/${model}`, options);\n }\n}\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type ModelsPage = Page<Model>;\n\n/**\n * Describes an OpenAI model offering that can be used with the API.\n */\nexport interface Model {\n /**\n * The model identifier, which can be referenced in the API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) when the model was created.\n */\n created: number;\n\n /**\n * The object type, which is always \"model\".\n */\n object: 'model';\n\n /**\n * The organization that owns the model.\n */\n owned_by: string;\n}\n\nexport interface ModelDeleted {\n id: string;\n\n deleted: boolean;\n\n object: string;\n}\n\nexport declare namespace Models {\n export { type Model as Model, type ModelDeleted as ModelDeleted, type ModelsPage as ModelsPage };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { RequestOptions } from '../internal/request-options';\n\n/**\n * Given text and/or image inputs, classifies if those inputs are potentially harmful.\n */\nexport class Moderations extends APIResource {\n /**\n * Classifies if text and/or image inputs are potentially harmful. Learn more in\n * the [moderation guide](https://platform.openai.com/docs/guides/moderation).\n */\n create(body: ModerationCreateParams, options?: RequestOptions): APIPromise<ModerationCreateResponse> {\n return this._client.post('/moderations', { body, ...options });\n }\n}\n\nexport interface Moderation {\n /**\n * A list of the categories, and whether they are flagged or not.\n */\n categories: Moderation.Categories;\n\n /**\n * A list of the categories along with the input type(s) that the score applies to.\n */\n category_applied_input_types: Moderation.CategoryAppliedInputTypes;\n\n /**\n * A list of the categories along with their scores as predicted by model.\n */\n category_scores: Moderation.CategoryScores;\n\n /**\n * Whether any of the below categories are flagged.\n */\n flagged: boolean;\n}\n\nexport namespace Moderation {\n /**\n * A list of the categories, and whether they are flagged or not.\n */\n export interface Categories {\n /**\n * Content that expresses, incites, or promotes harassing language towards any\n * target.\n */\n harassment: boolean;\n\n /**\n * Harassment content that also includes violence or serious harm towards any\n * target.\n */\n 'harassment/threatening': boolean;\n\n /**\n * Content that expresses, incites, or promotes hate based on race, gender,\n * ethnicity, religion, nationality, sexual orientation, disability status, or\n * caste. Hateful content aimed at non-protected groups (e.g., chess players) is\n * harassment.\n */\n hate: boolean;\n\n /**\n * Hateful content that also includes violence or serious harm towards the targeted\n * group based on race, gender, ethnicity, religion, nationality, sexual\n * orientation, disability status, or caste.\n */\n 'hate/threatening': boolean;\n\n /**\n * Content that includes instructions or advice that facilitate the planning or\n * execution of wrongdoing, or that gives advice or instruction on how to commit\n * illicit acts. For example, \"how to shoplift\" would fit this category.\n */\n illicit: boolean | null;\n\n /**\n * Content that includes instructions or advice that facilitate the planning or\n * execution of wrongdoing that also includes violence, or that gives advice or\n * instruction on the procurement of any weapon.\n */\n 'illicit/violent': boolean | null;\n\n /**\n * Content that promotes, encourages, or depicts acts of self-harm, such as\n * suicide, cutting, and eating disorders.\n */\n 'self-harm': boolean;\n\n /**\n * Content that encourages performing acts of self-harm, such as suicide, cutting,\n * and eating disorders, or that gives instructions or advice on how to commit such\n * acts.\n */\n 'self-harm/instructions': boolean;\n\n /**\n * Content where the speaker expresses that they are engaging or intend to engage\n * in acts of self-harm, such as suicide, cutting, and eating disorders.\n */\n 'self-harm/intent': boolean;\n\n /**\n * Content meant to arouse sexual excitement, such as the description of sexual\n * activity, or that promotes sexual services (excluding sex education and\n * wellness).\n */\n sexual: boolean;\n\n /**\n * Sexual content that includes an individual who is under 18 years old.\n */\n 'sexual/minors': boolean;\n\n /**\n * Content that depicts death, violence, or physical injury.\n */\n violence: boolean;\n\n /**\n * Content that depicts death, violence, or physical injury in graphic detail.\n */\n 'violence/graphic': boolean;\n }\n\n /**\n * A list of the categories along with the input type(s) that the score applies to.\n */\n export interface CategoryAppliedInputTypes {\n /**\n * The applied input type(s) for the category 'harassment'.\n */\n harassment: Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'harassment/threatening'.\n */\n 'harassment/threatening': Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'hate'.\n */\n hate: Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'hate/threatening'.\n */\n 'hate/threatening': Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'illicit'.\n */\n illicit: Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'illicit/violent'.\n */\n 'illicit/violent': Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'self-harm'.\n */\n 'self-harm': Array<'text' | 'image'>;\n\n /**\n * The applied input type(s) for the category 'self-harm/instructions'.\n */\n 'self-harm/instructions': Array<'text' | 'image'>;\n\n /**\n * The applied input type(s) for the category 'self-harm/intent'.\n */\n 'self-harm/intent': Array<'text' | 'image'>;\n\n /**\n * The applied input type(s) for the category 'sexual'.\n */\n sexual: Array<'text' | 'image'>;\n\n /**\n * The applied input type(s) for the category 'sexual/minors'.\n */\n 'sexual/minors': Array<'text'>;\n\n /**\n * The applied input type(s) for the category 'violence'.\n */\n violence: Array<'text' | 'image'>;\n\n /**\n * The applied input type(s) for the category 'violence/graphic'.\n */\n 'violence/graphic': Array<'text' | 'image'>;\n }\n\n /**\n * A list of the categories along with their scores as predicted by model.\n */\n export interface CategoryScores {\n /**\n * The score for the category 'harassment'.\n */\n harassment: number;\n\n /**\n * The score for the category 'harassment/threatening'.\n */\n 'harassment/threatening': number;\n\n /**\n * The score for the category 'hate'.\n */\n hate: number;\n\n /**\n * The score for the category 'hate/threatening'.\n */\n 'hate/threatening': number;\n\n /**\n * The score for the category 'illicit'.\n */\n illicit: number;\n\n /**\n * The score for the category 'illicit/violent'.\n */\n 'illicit/violent': number;\n\n /**\n * The score for the category 'self-harm'.\n */\n 'self-harm': number;\n\n /**\n * The score for the category 'self-harm/instructions'.\n */\n 'self-harm/instructions': number;\n\n /**\n * The score for the category 'self-harm/intent'.\n */\n 'self-harm/intent': number;\n\n /**\n * The score for the category 'sexual'.\n */\n sexual: number;\n\n /**\n * The score for the category 'sexual/minors'.\n */\n 'sexual/minors': number;\n\n /**\n * The score for the category 'violence'.\n */\n violence: number;\n\n /**\n * The score for the category 'violence/graphic'.\n */\n 'violence/graphic': number;\n }\n}\n\n/**\n * An object describing an image to classify.\n */\nexport interface ModerationImageURLInput {\n /**\n * Contains either an image URL or a data URL for a base64 encoded image.\n */\n image_url: ModerationImageURLInput.ImageURL;\n\n /**\n * Always `image_url`.\n */\n type: 'image_url';\n}\n\nexport namespace ModerationImageURLInput {\n /**\n * Contains either an image URL or a data URL for a base64 encoded image.\n */\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n }\n}\n\nexport type ModerationModel =\n | 'omni-moderation-latest'\n | 'omni-moderation-2024-09-26'\n | 'text-moderation-latest'\n | 'text-moderation-stable';\n\n/**\n * An object describing an image to classify.\n */\nexport type ModerationMultiModalInput = ModerationImageURLInput | ModerationTextInput;\n\n/**\n * An object describing text to classify.\n */\nexport interface ModerationTextInput {\n /**\n * A string of text to classify.\n */\n text: string;\n\n /**\n * Always `text`.\n */\n type: 'text';\n}\n\n/**\n * Represents if a given text input is potentially harmful.\n */\nexport interface ModerationCreateResponse {\n /**\n * The unique identifier for the moderation request.\n */\n id: string;\n\n /**\n * The model used to generate the moderation results.\n */\n model: string;\n\n /**\n * A list of moderation objects.\n */\n results: Array<Moderation>;\n}\n\nexport interface ModerationCreateParams {\n /**\n * Input (or inputs) to classify. Can be a single string, an array of strings, or\n * an array of multi-modal input objects similar to other models.\n */\n input: string | Array<string> | Array<ModerationMultiModalInput>;\n\n /**\n * The content moderation model you would like to use. Learn more in\n * [the moderation guide](https://platform.openai.com/docs/guides/moderation), and\n * learn about available models\n * [here](https://platform.openai.com/docs/models#moderation).\n */\n model?: (string & {}) | ModerationModel;\n}\n\nexport declare namespace Moderations {\n export {\n type Moderation as Moderation,\n type ModerationImageURLInput as ModerationImageURLInput,\n type ModerationModel as ModerationModel,\n type ModerationMultiModalInput as ModerationMultiModalInput,\n type ModerationTextInput as ModerationTextInput,\n type ModerationCreateResponse as ModerationCreateResponse,\n type ModerationCreateParams as ModerationCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as RealtimeAPI from './realtime';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class Calls extends APIResource {\n /**\n * Accept an incoming SIP call and configure the realtime session that will handle\n * it.\n *\n * @example\n * ```ts\n * await client.realtime.calls.accept('call_id', {\n * type: 'realtime',\n * });\n * ```\n */\n accept(callID: string, body: CallAcceptParams, options?: RequestOptions): APIPromise<void> {\n return this._client.post(path`/realtime/calls/${callID}/accept`, {\n body,\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n\n /**\n * End an active Realtime API call, whether it was initiated over SIP or WebRTC.\n *\n * @example\n * ```ts\n * await client.realtime.calls.hangup('call_id');\n * ```\n */\n hangup(callID: string, options?: RequestOptions): APIPromise<void> {\n return this._client.post(path`/realtime/calls/${callID}/hangup`, {\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n\n /**\n * Transfer an active SIP call to a new destination using the SIP REFER verb.\n *\n * @example\n * ```ts\n * await client.realtime.calls.refer('call_id', {\n * target_uri: 'tel:+14155550123',\n * });\n * ```\n */\n refer(callID: string, body: CallReferParams, options?: RequestOptions): APIPromise<void> {\n return this._client.post(path`/realtime/calls/${callID}/refer`, {\n body,\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n\n /**\n * Decline an incoming SIP call by returning a SIP status code to the caller.\n *\n * @example\n * ```ts\n * await client.realtime.calls.reject('call_id');\n * ```\n */\n reject(\n callID: string,\n body: CallRejectParams | null | undefined = {},\n options?: RequestOptions,\n ): APIPromise<void> {\n return this._client.post(path`/realtime/calls/${callID}/reject`, {\n body,\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n}\n\nexport interface CallAcceptParams {\n /**\n * The type of session to create. Always `realtime` for the Realtime API.\n */\n type: 'realtime';\n\n /**\n * Configuration for input and output audio.\n */\n audio?: RealtimeAPI.RealtimeAudioConfig;\n\n /**\n * Additional fields to include in server outputs.\n *\n * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n * transcription.\n */\n include?: Array<'item.input_audio_transcription.logprobs'>;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_output_tokens?: number | 'inf';\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | (string & {})\n | 'gpt-realtime'\n | 'gpt-realtime-1.5'\n | 'gpt-realtime-2025-08-28'\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17'\n | 'gpt-realtime-mini'\n | 'gpt-realtime-mini-2025-10-06'\n | 'gpt-realtime-mini-2025-12-15'\n | 'gpt-audio-1.5'\n | 'gpt-audio-mini'\n | 'gpt-audio-mini-2025-10-06'\n | 'gpt-audio-mini-2025-12-15';\n\n /**\n * The set of modalities the model can respond with. It defaults to `[\"audio\"]`,\n * indicating that the model will respond with audio plus a transcript. `[\"text\"]`\n * can be used to make the model respond with text only. It is not possible to\n * request both `text` and `audio` at the same time.\n */\n output_modalities?: Array<'text' | 'audio'>;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsesAPI.ResponsePrompt | null;\n\n /**\n * How the model chooses tools. Provide one of the string modes or force a specific\n * function/MCP tool.\n */\n tool_choice?: RealtimeAPI.RealtimeToolChoiceConfig;\n\n /**\n * Tools available to the model.\n */\n tools?: RealtimeAPI.RealtimeToolsConfig;\n\n /**\n * Realtime API can write session traces to the\n * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n * tracing is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: RealtimeAPI.RealtimeTracingConfig | null;\n\n /**\n * When the number of tokens in a conversation exceeds the model's input token\n * limit, the conversation be truncated, meaning messages (starting from the\n * oldest) will not be included in the model's context. A 32k context model with\n * 4,096 max output tokens can only include 28,224 tokens in the context before\n * truncation occurs.\n *\n * Clients can configure truncation behavior to truncate with a lower max token\n * limit, which is an effective way to control token usage and cost.\n *\n * Truncation will reduce the number of cached tokens on the next turn (busting the\n * cache), since messages are dropped from the beginning of the context. However,\n * clients can also configure truncation to retain messages up to a fraction of the\n * maximum context size, which will reduce the need for future truncations and thus\n * improve the cache rate.\n *\n * Truncation can be disabled entirely, which means the server will never truncate\n * but would instead return an error if the conversation exceeds the model's input\n * token limit.\n */\n truncation?: RealtimeAPI.RealtimeTruncation;\n}\n\nexport interface CallReferParams {\n /**\n * URI that should appear in the SIP Refer-To header. Supports values like\n * `tel:+14155550123` or `sip:agent@example.com`.\n */\n target_uri: string;\n}\n\nexport interface CallRejectParams {\n /**\n * SIP response code to send back to the caller. Defaults to `603` (Decline) when\n * omitted.\n */\n status_code?: number;\n}\n\nexport declare namespace Calls {\n export {\n type CallAcceptParams as CallAcceptParams,\n type CallReferParams as CallReferParams,\n type CallRejectParams as CallRejectParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ClientSecretsAPI from './client-secrets';\nimport * as RealtimeAPI from './realtime';\nimport * as ResponsesAPI from '../responses/responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\n\nexport class ClientSecrets extends APIResource {\n /**\n * Create a Realtime client secret with an associated session configuration.\n *\n * Client secrets are short-lived tokens that can be passed to a client app, such\n * as a web frontend or mobile client, which grants access to the Realtime API\n * without leaking your main API key. You can configure a custom TTL for each\n * client secret.\n *\n * You can also attach session configuration options to the client secret, which\n * will be applied to any sessions created using that client secret, but these can\n * also be overridden by the client connection.\n *\n * [Learn more about authentication with client secrets over WebRTC](https://platform.openai.com/docs/guides/realtime-webrtc).\n *\n * Returns the created client secret and the effective session object. The client\n * secret is a string that looks like `ek_1234`.\n *\n * @example\n * ```ts\n * const clientSecret =\n * await client.realtime.clientSecrets.create();\n * ```\n */\n create(body: ClientSecretCreateParams, options?: RequestOptions): APIPromise<ClientSecretCreateResponse> {\n return this._client.post('/realtime/client_secrets', { body, ...options });\n }\n}\n\n/**\n * Ephemeral key returned by the API.\n */\nexport interface RealtimeSessionClientSecret {\n /**\n * Timestamp for when the token expires. Currently, all tokens expire after one\n * minute.\n */\n expires_at: number;\n\n /**\n * Ephemeral key usable in client environments to authenticate connections to the\n * Realtime API. Use this in client-side environments rather than a standard API\n * token, which should only be used server-side.\n */\n value: string;\n}\n\n/**\n * A new Realtime session configuration, with an ephemeral key. Default TTL for\n * keys is one minute.\n */\nexport interface RealtimeSessionCreateResponse {\n /**\n * Ephemeral key returned by the API.\n */\n client_secret: RealtimeSessionClientSecret;\n\n /**\n * The type of session to create. Always `realtime` for the Realtime API.\n */\n type: 'realtime';\n\n /**\n * Configuration for input and output audio.\n */\n audio?: RealtimeSessionCreateResponse.Audio;\n\n /**\n * Additional fields to include in server outputs.\n *\n * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n * transcription.\n */\n include?: Array<'item.input_audio_transcription.logprobs'>;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_output_tokens?: number | 'inf';\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | (string & {})\n | 'gpt-realtime'\n | 'gpt-realtime-1.5'\n | 'gpt-realtime-2025-08-28'\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17'\n | 'gpt-realtime-mini'\n | 'gpt-realtime-mini-2025-10-06'\n | 'gpt-realtime-mini-2025-12-15'\n | 'gpt-audio-1.5'\n | 'gpt-audio-mini'\n | 'gpt-audio-mini-2025-10-06'\n | 'gpt-audio-mini-2025-12-15';\n\n /**\n * The set of modalities the model can respond with. It defaults to `[\"audio\"]`,\n * indicating that the model will respond with audio plus a transcript. `[\"text\"]`\n * can be used to make the model respond with text only. It is not possible to\n * request both `text` and `audio` at the same time.\n */\n output_modalities?: Array<'text' | 'audio'>;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsesAPI.ResponsePrompt | null;\n\n /**\n * How the model chooses tools. Provide one of the string modes or force a specific\n * function/MCP tool.\n */\n tool_choice?: ResponsesAPI.ToolChoiceOptions | ResponsesAPI.ToolChoiceFunction | ResponsesAPI.ToolChoiceMcp;\n\n /**\n * Tools available to the model.\n */\n tools?: Array<RealtimeAPI.RealtimeFunctionTool | RealtimeSessionCreateResponse.McpTool>;\n\n /**\n * Realtime API can write session traces to the\n * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n * tracing is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: 'auto' | RealtimeSessionCreateResponse.TracingConfiguration | null;\n\n /**\n * When the number of tokens in a conversation exceeds the model's input token\n * limit, the conversation be truncated, meaning messages (starting from the\n * oldest) will not be included in the model's context. A 32k context model with\n * 4,096 max output tokens can only include 28,224 tokens in the context before\n * truncation occurs.\n *\n * Clients can configure truncation behavior to truncate with a lower max token\n * limit, which is an effective way to control token usage and cost.\n *\n * Truncation will reduce the number of cached tokens on the next turn (busting the\n * cache), since messages are dropped from the beginning of the context. However,\n * clients can also configure truncation to retain messages up to a fraction of the\n * maximum context size, which will reduce the need for future truncations and thus\n * improve the cache rate.\n *\n * Truncation can be disabled entirely, which means the server will never truncate\n * but would instead return an error if the conversation exceeds the model's input\n * token limit.\n */\n truncation?: RealtimeAPI.RealtimeTruncation;\n}\n\nexport namespace RealtimeSessionCreateResponse {\n /**\n * Configuration for input and output audio.\n */\n export interface Audio {\n input?: Audio.Input;\n\n output?: Audio.Output;\n }\n\n export namespace Audio {\n export interface Input {\n /**\n * The format of the input audio.\n */\n format?: RealtimeAPI.RealtimeAudioFormats;\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n noise_reduction?: Input.NoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n transcription?: RealtimeAPI.AudioTranscription;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\n turn_detection?: Input.ServerVad | Input.SemanticVad | null;\n }\n\n export namespace Input {\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface NoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: RealtimeAPI.NoiseReductionType;\n }\n\n /**\n * Server-side voice activity detection (VAD) which flips on when user speech is\n * detected and off after a period of silence.\n */\n export interface ServerVad {\n /**\n * Type of turn detection, `server_vad` to turn on simple Server VAD.\n */\n type: 'server_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs. If `interrupt_response` is set to `false` this may fail to create a\n * response if the model is already responding.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n create_response?: boolean;\n\n /**\n * Optional timeout after which a model response will be triggered automatically.\n * This is useful for situations in which a long pause from the user is unexpected,\n * such as a phone call. The model will effectively prompt the user to continue the\n * conversation based on the current context.\n *\n * The timeout value will be applied after the last model response's audio has\n * finished playing, i.e. it's set to the `response.done` time plus audio playback\n * duration.\n *\n * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n * Response) will be emitted when the timeout is reached. Idle timeout is currently\n * only supported for `server_vad` mode.\n */\n idle_timeout_ms?: number | null;\n\n /**\n * Whether or not to automatically interrupt (cancel) any ongoing response with\n * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n * start event occurs. If `true` then the response will be cancelled, otherwise it\n * will continue until complete.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n }\n\n /**\n * Server-side semantic turn detection which uses a model to determine when the\n * user has finished speaking.\n */\n export interface SemanticVad {\n /**\n * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n */\n type: 'semantic_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n }\n }\n\n export interface Output {\n /**\n * The format of the output audio.\n */\n format?: RealtimeAPI.RealtimeAudioFormats;\n\n /**\n * The speed of the model's spoken response as a multiple of the original speed.\n * 1.0 is the default speed. 0.25 is the minimum speed. 1.5 is the maximum speed.\n * This value can only be changed in between model turns, not while a response is\n * in progress.\n *\n * This parameter is a post-processing adjustment to the audio after it is\n * generated, it's also possible to prompt the model to speak faster or slower.\n */\n speed?: number;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`,\n * and `cedar`. We recommend `marin` and `cedar` for best quality.\n */\n voice?:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n }\n }\n\n /**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\n export interface McpTool {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n server_label: string;\n\n /**\n * The type of the MCP tool. Always `mcp`.\n */\n type: 'mcp';\n\n /**\n * List of allowed tool names or a filter object.\n */\n allowed_tools?: Array<string> | McpTool.McpToolFilter | null;\n\n /**\n * An OAuth access token that can be used with a remote MCP server, either with a\n * custom MCP server URL or a service connector. Your application must handle the\n * OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n\n /**\n * Identifier for service connectors, like those available in ChatGPT. One of\n * `server_url` or `connector_id` must be provided. Learn more about service\n * connectors\n * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n *\n * Currently supported `connector_id` values are:\n *\n * - Dropbox: `connector_dropbox`\n * - Gmail: `connector_gmail`\n * - Google Calendar: `connector_googlecalendar`\n * - Google Drive: `connector_googledrive`\n * - Microsoft Teams: `connector_microsoftteams`\n * - Outlook Calendar: `connector_outlookcalendar`\n * - Outlook Email: `connector_outlookemail`\n * - SharePoint: `connector_sharepoint`\n */\n connector_id?:\n | 'connector_dropbox'\n | 'connector_gmail'\n | 'connector_googlecalendar'\n | 'connector_googledrive'\n | 'connector_microsoftteams'\n | 'connector_outlookcalendar'\n | 'connector_outlookemail'\n | 'connector_sharepoint';\n\n /**\n * Whether this MCP tool is deferred and discovered via tool search.\n */\n defer_loading?: boolean;\n\n /**\n * Optional HTTP headers to send to the MCP server. Use for authentication or other\n * purposes.\n */\n headers?: { [key: string]: string } | null;\n\n /**\n * Specify which of the MCP server's tools require approval.\n */\n require_approval?: McpTool.McpToolApprovalFilter | 'always' | 'never' | null;\n\n /**\n * Optional description of the MCP server, used to provide more context.\n */\n server_description?: string;\n\n /**\n * The URL for the MCP server. One of `server_url` or `connector_id` must be\n * provided.\n */\n server_url?: string;\n }\n\n export namespace McpTool {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface McpToolFilter {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * Specify which of the MCP server's tools require approval. Can be `always`,\n * `never`, or a filter object associated with tools that require approval.\n */\n export interface McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n always?: McpToolApprovalFilter.Always;\n\n /**\n * A filter object to specify which tools are allowed.\n */\n never?: McpToolApprovalFilter.Never;\n }\n\n export namespace McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Always {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Never {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n }\n }\n\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * Traces Dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the Traces\n * Dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the Traces Dashboard.\n */\n workflow_name?: string;\n }\n}\n\n/**\n * A Realtime transcription session configuration object.\n */\nexport interface RealtimeTranscriptionSessionCreateResponse {\n /**\n * Unique identifier for the session that looks like `sess_1234567890abcdef`.\n */\n id: string;\n\n /**\n * The object type. Always `realtime.transcription_session`.\n */\n object: string;\n\n /**\n * The type of session. Always `transcription` for transcription sessions.\n */\n type: 'transcription';\n\n /**\n * Configuration for input audio for the session.\n */\n audio?: RealtimeTranscriptionSessionCreateResponse.Audio;\n\n /**\n * Expiration timestamp for the session, in seconds since epoch.\n */\n expires_at?: number;\n\n /**\n * Additional fields to include in server outputs.\n *\n * - `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n * transcription.\n */\n include?: Array<'item.input_audio_transcription.logprobs'>;\n}\n\nexport namespace RealtimeTranscriptionSessionCreateResponse {\n /**\n * Configuration for input audio for the session.\n */\n export interface Audio {\n input?: Audio.Input;\n }\n\n export namespace Audio {\n export interface Input {\n /**\n * The PCM audio format. Only a 24kHz sample rate is supported.\n */\n format?: RealtimeAPI.RealtimeAudioFormats;\n\n /**\n * Configuration for input audio noise reduction.\n */\n noise_reduction?: Input.NoiseReduction;\n\n /**\n * Configuration of the transcription model.\n */\n transcription?: RealtimeAPI.AudioTranscription;\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n turn_detection?: ClientSecretsAPI.RealtimeTranscriptionSessionTurnDetection;\n }\n\n export namespace Input {\n /**\n * Configuration for input audio noise reduction.\n */\n export interface NoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: RealtimeAPI.NoiseReductionType;\n }\n }\n }\n}\n\n/**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\nexport interface RealtimeTranscriptionSessionTurnDetection {\n /**\n * Amount of audio to include before the VAD detected speech (in milliseconds).\n * Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n * With shorter values the model will respond more quickly, but may jump in on\n * short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n * threshold will require louder audio to activate the model, and thus might\n * perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection, only `server_vad` is currently supported.\n */\n type?: string;\n}\n\n/**\n * Response from creating a session and client secret for the Realtime API.\n */\nexport interface ClientSecretCreateResponse {\n /**\n * Expiration timestamp for the client secret, in seconds since epoch.\n */\n expires_at: number;\n\n /**\n * The session configuration for either a realtime or transcription session.\n */\n session: RealtimeSessionCreateResponse | RealtimeTranscriptionSessionCreateResponse;\n\n /**\n * The generated client secret value.\n */\n value: string;\n}\n\nexport interface ClientSecretCreateParams {\n /**\n * Configuration for the client secret expiration. Expiration refers to the time\n * after which a client secret will no longer be valid for creating sessions. The\n * session itself may continue after that time once started. A secret can be used\n * to create multiple sessions until it expires.\n */\n expires_after?: ClientSecretCreateParams.ExpiresAfter;\n\n /**\n * Session configuration to use for the client secret. Choose either a realtime\n * session or a transcription session.\n */\n session?: RealtimeAPI.RealtimeSessionCreateRequest | RealtimeAPI.RealtimeTranscriptionSessionCreateRequest;\n}\n\nexport namespace ClientSecretCreateParams {\n /**\n * Configuration for the client secret expiration. Expiration refers to the time\n * after which a client secret will no longer be valid for creating sessions. The\n * session itself may continue after that time once started. A secret can be used\n * to create multiple sessions until it expires.\n */\n export interface ExpiresAfter {\n /**\n * The anchor point for the client secret expiration, meaning that `seconds` will\n * be added to the `created_at` time of the client secret to produce an expiration\n * timestamp. Only `created_at` is currently supported.\n */\n anchor?: 'created_at';\n\n /**\n * The number of seconds from the anchor point to the expiration. Select a value\n * between `10` and `7200` (2 hours). This default to 600 seconds (10 minutes) if\n * not specified.\n */\n seconds?: number;\n }\n}\n\nexport declare namespace ClientSecrets {\n export {\n type RealtimeSessionClientSecret as RealtimeSessionClientSecret,\n type RealtimeSessionCreateResponse as RealtimeSessionCreateResponse,\n type RealtimeTranscriptionSessionCreateResponse as RealtimeTranscriptionSessionCreateResponse,\n type RealtimeTranscriptionSessionTurnDetection as RealtimeTranscriptionSessionTurnDetection,\n type ClientSecretCreateResponse as ClientSecretCreateResponse,\n type ClientSecretCreateParams as ClientSecretCreateParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as RealtimeAPI from './realtime';\nimport * as Shared from '../shared';\nimport * as CallsAPI from './calls';\nimport { CallAcceptParams, CallReferParams, CallRejectParams, Calls } from './calls';\nimport * as ClientSecretsAPI from './client-secrets';\nimport {\n ClientSecretCreateParams,\n ClientSecretCreateResponse,\n ClientSecrets,\n RealtimeSessionClientSecret,\n RealtimeSessionCreateResponse,\n RealtimeTranscriptionSessionCreateResponse,\n RealtimeTranscriptionSessionTurnDetection,\n} from './client-secrets';\nimport * as ResponsesAPI from '../responses/responses';\n\nexport class Realtime extends APIResource {\n clientSecrets: ClientSecretsAPI.ClientSecrets = new ClientSecretsAPI.ClientSecrets(this._client);\n calls: CallsAPI.Calls = new CallsAPI.Calls(this._client);\n}\n\nexport interface AudioTranscription {\n /**\n * The language of the input audio. Supplying the input language in\n * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`)\n * format will improve accuracy and latency.\n */\n language?: string;\n\n /**\n * The model to use for transcription. Current options are `whisper-1`,\n * `gpt-4o-mini-transcribe`, `gpt-4o-mini-transcribe-2025-12-15`,\n * `gpt-4o-transcribe`, and `gpt-4o-transcribe-diarize`. Use\n * `gpt-4o-transcribe-diarize` when you need diarization with speaker labels.\n */\n model?:\n | (string & {})\n | 'whisper-1'\n | 'gpt-4o-mini-transcribe'\n | 'gpt-4o-mini-transcribe-2025-12-15'\n | 'gpt-4o-transcribe'\n | 'gpt-4o-transcribe-diarize';\n\n /**\n * An optional text to guide the model's style or continue a previous audio\n * segment. For `whisper-1`, the\n * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting).\n * For `gpt-4o-transcribe` models (excluding `gpt-4o-transcribe-diarize`), the\n * prompt is a free text string, for example \"expect words related to technology\".\n */\n prompt?: string;\n}\n\n/**\n * Returned when a conversation is created. Emitted right after session creation.\n */\nexport interface ConversationCreatedEvent {\n /**\n * The conversation resource.\n */\n conversation: ConversationCreatedEvent.Conversation;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The event type, must be `conversation.created`.\n */\n type: 'conversation.created';\n}\n\nexport namespace ConversationCreatedEvent {\n /**\n * The conversation resource.\n */\n export interface Conversation {\n /**\n * The unique ID of the conversation.\n */\n id?: string;\n\n /**\n * The object type, must be `realtime.conversation`.\n */\n object?: 'realtime.conversation';\n }\n}\n\n/**\n * A single item within a Realtime conversation.\n */\nexport type ConversationItem =\n | RealtimeConversationItemSystemMessage\n | RealtimeConversationItemUserMessage\n | RealtimeConversationItemAssistantMessage\n | RealtimeConversationItemFunctionCall\n | RealtimeConversationItemFunctionCallOutput\n | RealtimeMcpApprovalResponse\n | RealtimeMcpListTools\n | RealtimeMcpToolCall\n | RealtimeMcpApprovalRequest;\n\n/**\n * Sent by the server when an Item is added to the default Conversation. This can\n * happen in several cases:\n *\n * - When the client sends a `conversation.item.create` event.\n * - When the input audio buffer is committed. In this case the item will be a user\n * message containing the audio from the buffer.\n * - When the model is generating a Response. In this case the\n * `conversation.item.added` event will be sent when the model starts generating\n * a specific Item, and thus it will not yet have any content (and `status` will\n * be `in_progress`).\n *\n * The event will include the full content of the Item (except when model is\n * generating a Response) except for audio data, which can be retrieved separately\n * with a `conversation.item.retrieve` event if necessary.\n */\nexport interface ConversationItemAdded {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A single item within a Realtime conversation.\n */\n item: ConversationItem;\n\n /**\n * The event type, must be `conversation.item.added`.\n */\n type: 'conversation.item.added';\n\n /**\n * The ID of the item that precedes this one, if any. This is used to maintain\n * ordering when items are inserted.\n */\n previous_item_id?: string | null;\n}\n\n/**\n * Add a new Item to the Conversation's context, including messages, function\n * calls, and function call responses. This event can be used both to populate a\n * \"history\" of the conversation and to add new items mid-stream, but has the\n * current limitation that it cannot populate assistant audio messages.\n *\n * If successful, the server will respond with a `conversation.item.created` event,\n * otherwise an `error` event will be sent.\n */\nexport interface ConversationItemCreateEvent {\n /**\n * A single item within a Realtime conversation.\n */\n item: ConversationItem;\n\n /**\n * The event type, must be `conversation.item.create`.\n */\n type: 'conversation.item.create';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n\n /**\n * The ID of the preceding item after which the new item will be inserted. If not\n * set, the new item will be appended to the end of the conversation.\n *\n * If set to `root`, the new item will be added to the beginning of the\n * conversation.\n *\n * If set to an existing ID, it allows an item to be inserted mid-conversation. If\n * the ID cannot be found, an error will be returned and the item will not be\n * added.\n */\n previous_item_id?: string;\n}\n\n/**\n * Returned when a conversation item is created. There are several scenarios that\n * produce this event:\n *\n * - The server is generating a Response, which if successful will produce either\n * one or two Items, which will be of type `message` (role `assistant`) or type\n * `function_call`.\n * - The input audio buffer has been committed, either by the client or the server\n * (in `server_vad` mode). The server will take the content of the input audio\n * buffer and add it to a new user message Item.\n * - The client has sent a `conversation.item.create` event to add a new Item to\n * the Conversation.\n */\nexport interface ConversationItemCreatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A single item within a Realtime conversation.\n */\n item: ConversationItem;\n\n /**\n * The event type, must be `conversation.item.created`.\n */\n type: 'conversation.item.created';\n\n /**\n * The ID of the preceding item in the Conversation context, allows the client to\n * understand the order of the conversation. Can be `null` if the item has no\n * predecessor.\n */\n previous_item_id?: string | null;\n}\n\n/**\n * Send this event when you want to remove any item from the conversation history.\n * The server will respond with a `conversation.item.deleted` event, unless the\n * item does not exist in the conversation history, in which case the server will\n * respond with an error.\n */\nexport interface ConversationItemDeleteEvent {\n /**\n * The ID of the item to delete.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.delete`.\n */\n type: 'conversation.item.delete';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when an item in the conversation is deleted by the client with a\n * `conversation.item.delete` event. This event is used to synchronize the server's\n * understanding of the conversation history with the client's view.\n */\nexport interface ConversationItemDeletedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item that was deleted.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.deleted`.\n */\n type: 'conversation.item.deleted';\n}\n\n/**\n * Returned when a conversation item is finalized.\n *\n * The event will include the full content of the Item except for audio data, which\n * can be retrieved separately with a `conversation.item.retrieve` event if needed.\n */\nexport interface ConversationItemDone {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A single item within a Realtime conversation.\n */\n item: ConversationItem;\n\n /**\n * The event type, must be `conversation.item.done`.\n */\n type: 'conversation.item.done';\n\n /**\n * The ID of the item that precedes this one, if any. This is used to maintain\n * ordering when items are inserted.\n */\n previous_item_id?: string | null;\n}\n\n/**\n * This event is the output of audio transcription for user audio written to the\n * user audio buffer. Transcription begins when the input audio buffer is committed\n * by the client or server (when VAD is enabled). Transcription runs asynchronously\n * with Response creation, so this event may come before or after the Response\n * events.\n *\n * Realtime API models accept audio natively, and thus input transcription is a\n * separate process run on a separate ASR (Automatic Speech Recognition) model. The\n * transcript may diverge somewhat from the model's interpretation, and should be\n * treated as a rough guide.\n */\nexport interface ConversationItemInputAudioTranscriptionCompletedEvent {\n /**\n * The index of the content part containing the audio.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item containing the audio that is being transcribed.\n */\n item_id: string;\n\n /**\n * The transcribed text.\n */\n transcript: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.completed`.\n */\n type: 'conversation.item.input_audio_transcription.completed';\n\n /**\n * Usage statistics for the transcription, this is billed according to the ASR\n * model's pricing rather than the realtime model's pricing.\n */\n usage:\n | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageTokens\n | ConversationItemInputAudioTranscriptionCompletedEvent.TranscriptTextUsageDuration;\n\n /**\n * The log probabilities of the transcription.\n */\n logprobs?: Array<LogProbProperties> | null;\n}\n\nexport namespace ConversationItemInputAudioTranscriptionCompletedEvent {\n /**\n * Usage statistics for models billed by token usage.\n */\n export interface TranscriptTextUsageTokens {\n /**\n * Number of input tokens billed for this request.\n */\n input_tokens: number;\n\n /**\n * Number of output tokens generated.\n */\n output_tokens: number;\n\n /**\n * Total number of tokens used (input + output).\n */\n total_tokens: number;\n\n /**\n * The type of the usage object. Always `tokens` for this variant.\n */\n type: 'tokens';\n\n /**\n * Details about the input tokens billed for this request.\n */\n input_token_details?: TranscriptTextUsageTokens.InputTokenDetails;\n }\n\n export namespace TranscriptTextUsageTokens {\n /**\n * Details about the input tokens billed for this request.\n */\n export interface InputTokenDetails {\n /**\n * Number of audio tokens billed for this request.\n */\n audio_tokens?: number;\n\n /**\n * Number of text tokens billed for this request.\n */\n text_tokens?: number;\n }\n }\n\n /**\n * Usage statistics for models billed by audio input duration.\n */\n export interface TranscriptTextUsageDuration {\n /**\n * Duration of the input audio in seconds.\n */\n seconds: number;\n\n /**\n * The type of the usage object. Always `duration` for this variant.\n */\n type: 'duration';\n }\n}\n\n/**\n * Returned when the text value of an input audio transcription content part is\n * updated with incremental transcription results.\n */\nexport interface ConversationItemInputAudioTranscriptionDeltaEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item containing the audio that is being transcribed.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.delta`.\n */\n type: 'conversation.item.input_audio_transcription.delta';\n\n /**\n * The index of the content part in the item's content array.\n */\n content_index?: number;\n\n /**\n * The text delta.\n */\n delta?: string;\n\n /**\n * The log probabilities of the transcription. These can be enabled by\n * configurating the session with\n * `\"include\": [\"item.input_audio_transcription.logprobs\"]`. Each entry in the\n * array corresponds a log probability of which token would be selected for this\n * chunk of transcription. This can help to identify if it was possible there were\n * multiple valid options for a given chunk of transcription.\n */\n logprobs?: Array<LogProbProperties> | null;\n}\n\n/**\n * Returned when input audio transcription is configured, and a transcription\n * request for a user message failed. These events are separate from other `error`\n * events so that the client can identify the related Item.\n */\nexport interface ConversationItemInputAudioTranscriptionFailedEvent {\n /**\n * The index of the content part containing the audio.\n */\n content_index: number;\n\n /**\n * Details of the transcription error.\n */\n error: ConversationItemInputAudioTranscriptionFailedEvent.Error;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.failed`.\n */\n type: 'conversation.item.input_audio_transcription.failed';\n}\n\nexport namespace ConversationItemInputAudioTranscriptionFailedEvent {\n /**\n * Details of the transcription error.\n */\n export interface Error {\n /**\n * Error code, if any.\n */\n code?: string;\n\n /**\n * A human-readable error message.\n */\n message?: string;\n\n /**\n * Parameter related to the error, if any.\n */\n param?: string;\n\n /**\n * The type of error.\n */\n type?: string;\n }\n}\n\n/**\n * Returned when an input audio transcription segment is identified for an item.\n */\nexport interface ConversationItemInputAudioTranscriptionSegment {\n /**\n * The segment identifier.\n */\n id: string;\n\n /**\n * The index of the input audio content part within the item.\n */\n content_index: number;\n\n /**\n * End time of the segment in seconds.\n */\n end: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item containing the input audio content.\n */\n item_id: string;\n\n /**\n * The detected speaker label for this segment.\n */\n speaker: string;\n\n /**\n * Start time of the segment in seconds.\n */\n start: number;\n\n /**\n * The text for this segment.\n */\n text: string;\n\n /**\n * The event type, must be `conversation.item.input_audio_transcription.segment`.\n */\n type: 'conversation.item.input_audio_transcription.segment';\n}\n\n/**\n * Send this event when you want to retrieve the server's representation of a\n * specific item in the conversation history. This is useful, for example, to\n * inspect user audio after noise cancellation and VAD. The server will respond\n * with a `conversation.item.retrieved` event, unless the item does not exist in\n * the conversation history, in which case the server will respond with an error.\n */\nexport interface ConversationItemRetrieveEvent {\n /**\n * The ID of the item to retrieve.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.retrieve`.\n */\n type: 'conversation.item.retrieve';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Send this event to truncate a previous assistant message’s audio. The server\n * will produce audio faster than realtime, so this event is useful when the user\n * interrupts to truncate audio that has already been sent to the client but not\n * yet played. This will synchronize the server's understanding of the audio with\n * the client's playback.\n *\n * Truncating audio will delete the server-side text transcript to ensure there is\n * not text in the context that hasn't been heard by the user.\n *\n * If successful, the server will respond with a `conversation.item.truncated`\n * event.\n */\nexport interface ConversationItemTruncateEvent {\n /**\n * Inclusive duration up to which audio is truncated, in milliseconds. If the\n * audio_end_ms is greater than the actual audio duration, the server will respond\n * with an error.\n */\n audio_end_ms: number;\n\n /**\n * The index of the content part to truncate. Set this to `0`.\n */\n content_index: number;\n\n /**\n * The ID of the assistant message item to truncate. Only assistant message items\n * can be truncated.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.truncate`.\n */\n type: 'conversation.item.truncate';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when an earlier assistant audio message item is truncated by the client\n * with a `conversation.item.truncate` event. This event is used to synchronize the\n * server's understanding of the audio with the client's playback.\n *\n * This action will truncate the audio and remove the server-side text transcript\n * to ensure there is no text in the context that hasn't been heard by the user.\n */\nexport interface ConversationItemTruncatedEvent {\n /**\n * The duration up to which the audio was truncated, in milliseconds.\n */\n audio_end_ms: number;\n\n /**\n * The index of the content part that was truncated.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the assistant message item that was truncated.\n */\n item_id: string;\n\n /**\n * The event type, must be `conversation.item.truncated`.\n */\n type: 'conversation.item.truncated';\n}\n\n/**\n * The item to add to the conversation.\n */\nexport interface ConversationItemWithReference {\n /**\n * For an item of type (`message` | `function_call` | `function_call_output`) this\n * field allows the client to assign the unique ID of the item. It is not required\n * because the server will generate one if not provided.\n *\n * For an item of type `item_reference`, this field is required and is a reference\n * to any item that has previously existed in the conversation.\n */\n id?: string;\n\n /**\n * The arguments of the function call (for `function_call` items).\n */\n arguments?: string;\n\n /**\n * The ID of the function call (for `function_call` and `function_call_output`\n * items). If passed on a `function_call_output` item, the server will check that a\n * `function_call` item with the same ID exists in the conversation history.\n */\n call_id?: string;\n\n /**\n * The content of the message, applicable for `message` items.\n *\n * - Message items of role `system` support only `input_text` content\n * - Message items of role `user` support `input_text` and `input_audio` content\n * - Message items of role `assistant` support `text` content.\n */\n content?: Array<ConversationItemWithReference.Content>;\n\n /**\n * The name of the function being called (for `function_call` items).\n */\n name?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`.\n */\n object?: 'realtime.item';\n\n /**\n * The output of the function call (for `function_call_output` items).\n */\n output?: string;\n\n /**\n * The role of the message sender (`user`, `assistant`, `system`), only applicable\n * for `message` items.\n */\n role?: 'user' | 'assistant' | 'system';\n\n /**\n * The status of the item (`completed`, `incomplete`, `in_progress`). These have no\n * effect on the conversation, but are accepted for consistency with the\n * `conversation.item.created` event.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n\n /**\n * The type of the item (`message`, `function_call`, `function_call_output`,\n * `item_reference`).\n */\n type?: 'message' | 'function_call' | 'function_call_output' | 'item_reference';\n}\n\nexport namespace ConversationItemWithReference {\n export interface Content {\n /**\n * ID of a previous conversation item to reference (for `item_reference` content\n * types in `response.create` events). These can reference both client and server\n * created items.\n */\n id?: string;\n\n /**\n * Base64-encoded audio bytes, used for `input_audio` content type.\n */\n audio?: string;\n\n /**\n * The text content, used for `input_text` and `text` content types.\n */\n text?: string;\n\n /**\n * The transcript of the audio, used for `input_audio` content type.\n */\n transcript?: string;\n\n /**\n * The content type (`input_text`, `input_audio`, `item_reference`, `text`).\n */\n type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';\n }\n}\n\n/**\n * Send this event to append audio bytes to the input audio buffer. The audio\n * buffer is temporary storage you can write to and later commit. A \"commit\" will\n * create a new user message item in the conversation history from the buffer\n * content and clear the buffer. Input audio transcription (if enabled) will be\n * generated when the buffer is committed.\n *\n * If VAD is enabled the audio buffer is used to detect speech and the server will\n * decide when to commit. When Server VAD is disabled, you must commit the audio\n * buffer manually. Input audio noise reduction operates on writes to the audio\n * buffer.\n *\n * The client may choose how much audio to place in each event up to a maximum of\n * 15 MiB, for example streaming smaller chunks from the client may allow the VAD\n * to be more responsive. Unlike most other client events, the server will not send\n * a confirmation response to this event.\n */\nexport interface InputAudioBufferAppendEvent {\n /**\n * Base64-encoded audio bytes. This must be in the format specified by the\n * `input_audio_format` field in the session configuration.\n */\n audio: string;\n\n /**\n * The event type, must be `input_audio_buffer.append`.\n */\n type: 'input_audio_buffer.append';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Send this event to clear the audio bytes in the buffer. The server will respond\n * with an `input_audio_buffer.cleared` event.\n */\nexport interface InputAudioBufferClearEvent {\n /**\n * The event type, must be `input_audio_buffer.clear`.\n */\n type: 'input_audio_buffer.clear';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when the input audio buffer is cleared by the client with a\n * `input_audio_buffer.clear` event.\n */\nexport interface InputAudioBufferClearedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.cleared`.\n */\n type: 'input_audio_buffer.cleared';\n}\n\n/**\n * Send this event to commit the user input audio buffer, which will create a new\n * user message item in the conversation. This event will produce an error if the\n * input audio buffer is empty. When in Server VAD mode, the client does not need\n * to send this event, the server will commit the audio buffer automatically.\n *\n * Committing the input audio buffer will trigger input audio transcription (if\n * enabled in session configuration), but it will not create a response from the\n * model. The server will respond with an `input_audio_buffer.committed` event.\n */\nexport interface InputAudioBufferCommitEvent {\n /**\n * The event type, must be `input_audio_buffer.commit`.\n */\n type: 'input_audio_buffer.commit';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\n/**\n * Returned when an input audio buffer is committed, either by the client or\n * automatically in server VAD mode. The `item_id` property is the ID of the user\n * message item that will be created, thus a `conversation.item.created` event will\n * also be sent to the client.\n */\nexport interface InputAudioBufferCommittedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item that will be created.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.committed`.\n */\n type: 'input_audio_buffer.committed';\n\n /**\n * The ID of the preceding item after which the new item will be inserted. Can be\n * `null` if the item has no predecessor.\n */\n previous_item_id?: string | null;\n}\n\n/**\n * **SIP Only:** Returned when an DTMF event is received. A DTMF event is a message\n * that represents a telephone keypad press (0–9, \\*, #, A–D). The `event` property\n * is the keypad that the user press. The `received_at` is the UTC Unix Timestamp\n * that the server received the event.\n */\nexport interface InputAudioBufferDtmfEventReceivedEvent {\n /**\n * The telephone keypad that was pressed by the user.\n */\n event: string;\n\n /**\n * UTC Unix Timestamp when DTMF Event was received by server.\n */\n received_at: number;\n\n /**\n * The event type, must be `input_audio_buffer.dtmf_event_received`.\n */\n type: 'input_audio_buffer.dtmf_event_received';\n}\n\n/**\n * Sent by the server when in `server_vad` mode to indicate that speech has been\n * detected in the audio buffer. This can happen any time audio is added to the\n * buffer (unless speech is already detected). The client may want to use this\n * event to interrupt audio playback or provide visual feedback to the user.\n *\n * The client should expect to receive a `input_audio_buffer.speech_stopped` event\n * when speech stops. The `item_id` property is the ID of the user message item\n * that will be created when speech stops and will also be included in the\n * `input_audio_buffer.speech_stopped` event (unless the client manually commits\n * the audio buffer during VAD activation).\n */\nexport interface InputAudioBufferSpeechStartedEvent {\n /**\n * Milliseconds from the start of all audio written to the buffer during the\n * session when speech was first detected. This will correspond to the beginning of\n * audio sent to the model, and thus includes the `prefix_padding_ms` configured in\n * the Session.\n */\n audio_start_ms: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item that will be created when speech stops.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.speech_started`.\n */\n type: 'input_audio_buffer.speech_started';\n}\n\n/**\n * Returned in `server_vad` mode when the server detects the end of speech in the\n * audio buffer. The server will also send an `conversation.item.created` event\n * with the user message item that is created from the audio buffer.\n */\nexport interface InputAudioBufferSpeechStoppedEvent {\n /**\n * Milliseconds since the session started when speech stopped. This will correspond\n * to the end of audio sent to the model, and thus includes the\n * `min_silence_duration_ms` configured in the Session.\n */\n audio_end_ms: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the user message item that will be created.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.speech_stopped`.\n */\n type: 'input_audio_buffer.speech_stopped';\n}\n\n/**\n * Returned when the Server VAD timeout is triggered for the input audio buffer.\n * This is configured with `idle_timeout_ms` in the `turn_detection` settings of\n * the session, and it indicates that there hasn't been any speech detected for the\n * configured duration.\n *\n * The `audio_start_ms` and `audio_end_ms` fields indicate the segment of audio\n * after the last model response up to the triggering time, as an offset from the\n * beginning of audio written to the input audio buffer. This means it demarcates\n * the segment of audio that was silent and the difference between the start and\n * end values will roughly match the configured timeout.\n *\n * The empty audio will be committed to the conversation as an `input_audio` item\n * (there will be a `input_audio_buffer.committed` event) and a model response will\n * be generated. There may be speech that didn't trigger VAD but is still detected\n * by the model, so the model may respond with something relevant to the\n * conversation or a prompt to continue speaking.\n */\nexport interface InputAudioBufferTimeoutTriggered {\n /**\n * Millisecond offset of audio written to the input audio buffer at the time the\n * timeout was triggered.\n */\n audio_end_ms: number;\n\n /**\n * Millisecond offset of audio written to the input audio buffer that was after the\n * playback time of the last model response.\n */\n audio_start_ms: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item associated with this segment.\n */\n item_id: string;\n\n /**\n * The event type, must be `input_audio_buffer.timeout_triggered`.\n */\n type: 'input_audio_buffer.timeout_triggered';\n}\n\n/**\n * A log probability object.\n */\nexport interface LogProbProperties {\n /**\n * The token that was used to generate the log probability.\n */\n token: string;\n\n /**\n * The bytes that were used to generate the log probability.\n */\n bytes: Array<number>;\n\n /**\n * The log probability of the token.\n */\n logprob: number;\n}\n\n/**\n * Returned when listing MCP tools has completed for an item.\n */\nexport interface McpListToolsCompleted {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP list tools item.\n */\n item_id: string;\n\n /**\n * The event type, must be `mcp_list_tools.completed`.\n */\n type: 'mcp_list_tools.completed';\n}\n\n/**\n * Returned when listing MCP tools has failed for an item.\n */\nexport interface McpListToolsFailed {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP list tools item.\n */\n item_id: string;\n\n /**\n * The event type, must be `mcp_list_tools.failed`.\n */\n type: 'mcp_list_tools.failed';\n}\n\n/**\n * Returned when listing MCP tools is in progress for an item.\n */\nexport interface McpListToolsInProgress {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP list tools item.\n */\n item_id: string;\n\n /**\n * The event type, must be `mcp_list_tools.in_progress`.\n */\n type: 'mcp_list_tools.in_progress';\n}\n\n/**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\nexport type NoiseReductionType = 'near_field' | 'far_field';\n\n/**\n * **WebRTC/SIP Only:** Emit to cut off the current audio response. This will\n * trigger the server to stop generating audio and emit a\n * `output_audio_buffer.cleared` event. This event should be preceded by a\n * `response.cancel` client event to stop the generation of the current response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\nexport interface OutputAudioBufferClearEvent {\n /**\n * The event type, must be `output_audio_buffer.clear`.\n */\n type: 'output_audio_buffer.clear';\n\n /**\n * The unique ID of the client event used for error handling.\n */\n event_id?: string;\n}\n\n/**\n * Emitted at the beginning of a Response to indicate the updated rate limits. When\n * a Response is created some tokens will be \"reserved\" for the output tokens, the\n * rate limits shown here reflect that reservation, which is then adjusted\n * accordingly once the Response is completed.\n */\nexport interface RateLimitsUpdatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * List of rate limit information.\n */\n rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;\n\n /**\n * The event type, must be `rate_limits.updated`.\n */\n type: 'rate_limits.updated';\n}\n\nexport namespace RateLimitsUpdatedEvent {\n export interface RateLimit {\n /**\n * The maximum allowed value for the rate limit.\n */\n limit?: number;\n\n /**\n * The name of the rate limit (`requests`, `tokens`).\n */\n name?: 'requests' | 'tokens';\n\n /**\n * The remaining value before the limit is reached.\n */\n remaining?: number;\n\n /**\n * Seconds until the rate limit resets.\n */\n reset_seconds?: number;\n }\n}\n\n/**\n * Configuration for input and output audio.\n */\nexport interface RealtimeAudioConfig {\n input?: RealtimeAudioConfigInput;\n\n output?: RealtimeAudioConfigOutput;\n}\n\nexport interface RealtimeAudioConfigInput {\n /**\n * The format of the input audio.\n */\n format?: RealtimeAudioFormats;\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n noise_reduction?: RealtimeAudioConfigInput.NoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n transcription?: AudioTranscription;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\n turn_detection?: RealtimeAudioInputTurnDetection | null;\n}\n\nexport namespace RealtimeAudioConfigInput {\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface NoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: RealtimeAPI.NoiseReductionType;\n }\n}\n\nexport interface RealtimeAudioConfigOutput {\n /**\n * The format of the output audio.\n */\n format?: RealtimeAudioFormats;\n\n /**\n * The speed of the model's spoken response as a multiple of the original speed.\n * 1.0 is the default speed. 0.25 is the minimum speed. 1.5 is the maximum speed.\n * This value can only be changed in between model turns, not while a response is\n * in progress.\n *\n * This parameter is a post-processing adjustment to the audio after it is\n * generated, it's also possible to prompt the model to speak faster or slower.\n */\n speed?: number;\n\n /**\n * The voice the model uses to respond. Supported built-in voices are `alloy`,\n * `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`, and\n * `cedar`. Voice cannot be changed during the session once the model has responded\n * with audio at least once. We recommend `marin` and `cedar` for best quality.\n */\n voice?:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n}\n\n/**\n * The PCM audio format. Only a 24kHz sample rate is supported.\n */\nexport type RealtimeAudioFormats =\n | RealtimeAudioFormats.AudioPCM\n | RealtimeAudioFormats.AudioPCMU\n | RealtimeAudioFormats.AudioPCMA;\n\nexport namespace RealtimeAudioFormats {\n /**\n * The PCM audio format. Only a 24kHz sample rate is supported.\n */\n export interface AudioPCM {\n /**\n * The sample rate of the audio. Always `24000`.\n */\n rate?: 24000;\n\n /**\n * The audio format. Always `audio/pcm`.\n */\n type?: 'audio/pcm';\n }\n\n /**\n * The G.711 μ-law format.\n */\n export interface AudioPCMU {\n /**\n * The audio format. Always `audio/pcmu`.\n */\n type?: 'audio/pcmu';\n }\n\n /**\n * The G.711 A-law format.\n */\n export interface AudioPCMA {\n /**\n * The audio format. Always `audio/pcma`.\n */\n type?: 'audio/pcma';\n }\n}\n\n/**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\nexport type RealtimeAudioInputTurnDetection =\n | RealtimeAudioInputTurnDetection.ServerVad\n | RealtimeAudioInputTurnDetection.SemanticVad;\n\nexport namespace RealtimeAudioInputTurnDetection {\n /**\n * Server-side voice activity detection (VAD) which flips on when user speech is\n * detected and off after a period of silence.\n */\n export interface ServerVad {\n /**\n * Type of turn detection, `server_vad` to turn on simple Server VAD.\n */\n type: 'server_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs. If `interrupt_response` is set to `false` this may fail to create a\n * response if the model is already responding.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n create_response?: boolean;\n\n /**\n * Optional timeout after which a model response will be triggered automatically.\n * This is useful for situations in which a long pause from the user is unexpected,\n * such as a phone call. The model will effectively prompt the user to continue the\n * conversation based on the current context.\n *\n * The timeout value will be applied after the last model response's audio has\n * finished playing, i.e. it's set to the `response.done` time plus audio playback\n * duration.\n *\n * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n * Response) will be emitted when the timeout is reached. Idle timeout is currently\n * only supported for `server_vad` mode.\n */\n idle_timeout_ms?: number | null;\n\n /**\n * Whether or not to automatically interrupt (cancel) any ongoing response with\n * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n * start event occurs. If `true` then the response will be cancelled, otherwise it\n * will continue until complete.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n }\n\n /**\n * Server-side semantic turn detection which uses a model to determine when the\n * user has finished speaking.\n */\n export interface SemanticVad {\n /**\n * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n */\n type: 'semantic_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n }\n}\n\n/**\n * A realtime client event.\n */\nexport type RealtimeClientEvent =\n | ConversationItemCreateEvent\n | ConversationItemDeleteEvent\n | ConversationItemRetrieveEvent\n | ConversationItemTruncateEvent\n | InputAudioBufferAppendEvent\n | InputAudioBufferClearEvent\n | OutputAudioBufferClearEvent\n | InputAudioBufferCommitEvent\n | ResponseCancelEvent\n | ResponseCreateEvent\n | SessionUpdateEvent;\n\n/**\n * An assistant message item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemAssistantMessage {\n /**\n * The content of the message.\n */\n content: Array<RealtimeConversationItemAssistantMessage.Content>;\n\n /**\n * The role of the message sender. Always `assistant`.\n */\n role: 'assistant';\n\n /**\n * The type of the item. Always `message`.\n */\n type: 'message';\n\n /**\n * The unique ID of the item. This may be provided by the client or generated by\n * the server.\n */\n id?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`. Optional\n * when creating a new item.\n */\n object?: 'realtime.item';\n\n /**\n * The status of the item. Has no effect on the conversation.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\nexport namespace RealtimeConversationItemAssistantMessage {\n export interface Content {\n /**\n * Base64-encoded audio bytes, these will be parsed as the format specified in the\n * session output audio type configuration. This defaults to PCM 16-bit 24kHz mono\n * if not specified.\n */\n audio?: string;\n\n /**\n * The text content.\n */\n text?: string;\n\n /**\n * The transcript of the audio content, this will always be present if the output\n * type is `audio`.\n */\n transcript?: string;\n\n /**\n * The content type, `output_text` or `output_audio` depending on the session\n * `output_modalities` configuration.\n */\n type?: 'output_text' | 'output_audio';\n }\n}\n\n/**\n * A function call item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemFunctionCall {\n /**\n * The arguments of the function call. This is a JSON-encoded string representing\n * the arguments passed to the function, for example\n * `{\"arg1\": \"value1\", \"arg2\": 42}`.\n */\n arguments: string;\n\n /**\n * The name of the function being called.\n */\n name: string;\n\n /**\n * The type of the item. Always `function_call`.\n */\n type: 'function_call';\n\n /**\n * The unique ID of the item. This may be provided by the client or generated by\n * the server.\n */\n id?: string;\n\n /**\n * The ID of the function call.\n */\n call_id?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`. Optional\n * when creating a new item.\n */\n object?: 'realtime.item';\n\n /**\n * The status of the item. Has no effect on the conversation.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\n/**\n * A function call output item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemFunctionCallOutput {\n /**\n * The ID of the function call this output is for.\n */\n call_id: string;\n\n /**\n * The output of the function call, this is free text and can contain any\n * information or simply be empty.\n */\n output: string;\n\n /**\n * The type of the item. Always `function_call_output`.\n */\n type: 'function_call_output';\n\n /**\n * The unique ID of the item. This may be provided by the client or generated by\n * the server.\n */\n id?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`. Optional\n * when creating a new item.\n */\n object?: 'realtime.item';\n\n /**\n * The status of the item. Has no effect on the conversation.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\n/**\n * A system message in a Realtime conversation can be used to provide additional\n * context or instructions to the model. This is similar but distinct from the\n * instruction prompt provided at the start of a conversation, as system messages\n * can be added at any point in the conversation. For major changes to the\n * conversation's behavior, use instructions, but for smaller updates (e.g. \"the\n * user is now asking about a different topic\"), use system messages.\n */\nexport interface RealtimeConversationItemSystemMessage {\n /**\n * The content of the message.\n */\n content: Array<RealtimeConversationItemSystemMessage.Content>;\n\n /**\n * The role of the message sender. Always `system`.\n */\n role: 'system';\n\n /**\n * The type of the item. Always `message`.\n */\n type: 'message';\n\n /**\n * The unique ID of the item. This may be provided by the client or generated by\n * the server.\n */\n id?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`. Optional\n * when creating a new item.\n */\n object?: 'realtime.item';\n\n /**\n * The status of the item. Has no effect on the conversation.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\nexport namespace RealtimeConversationItemSystemMessage {\n export interface Content {\n /**\n * The text content.\n */\n text?: string;\n\n /**\n * The content type. Always `input_text` for system messages.\n */\n type?: 'input_text';\n }\n}\n\n/**\n * A user message item in a Realtime conversation.\n */\nexport interface RealtimeConversationItemUserMessage {\n /**\n * The content of the message.\n */\n content: Array<RealtimeConversationItemUserMessage.Content>;\n\n /**\n * The role of the message sender. Always `user`.\n */\n role: 'user';\n\n /**\n * The type of the item. Always `message`.\n */\n type: 'message';\n\n /**\n * The unique ID of the item. This may be provided by the client or generated by\n * the server.\n */\n id?: string;\n\n /**\n * Identifier for the API object being returned - always `realtime.item`. Optional\n * when creating a new item.\n */\n object?: 'realtime.item';\n\n /**\n * The status of the item. Has no effect on the conversation.\n */\n status?: 'completed' | 'incomplete' | 'in_progress';\n}\n\nexport namespace RealtimeConversationItemUserMessage {\n export interface Content {\n /**\n * Base64-encoded audio bytes (for `input_audio`), these will be parsed as the\n * format specified in the session input audio type configuration. This defaults to\n * PCM 16-bit 24kHz mono if not specified.\n */\n audio?: string;\n\n /**\n * The detail level of the image (for `input_image`). `auto` will default to\n * `high`.\n */\n detail?: 'auto' | 'low' | 'high';\n\n /**\n * Base64-encoded image bytes (for `input_image`) as a data URI. For example\n * `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...`. Supported formats are PNG\n * and JPEG.\n */\n image_url?: string;\n\n /**\n * The text content (for `input_text`).\n */\n text?: string;\n\n /**\n * Transcript of the audio (for `input_audio`). This is not sent to the model, but\n * will be attached to the message item for reference.\n */\n transcript?: string;\n\n /**\n * The content type (`input_text`, `input_audio`, or `input_image`).\n */\n type?: 'input_text' | 'input_audio' | 'input_image';\n }\n}\n\n/**\n * Details of the error.\n */\nexport interface RealtimeError {\n /**\n * A human-readable error message.\n */\n message: string;\n\n /**\n * The type of error (e.g., \"invalid_request_error\", \"server_error\").\n */\n type: string;\n\n /**\n * Error code, if any.\n */\n code?: string | null;\n\n /**\n * The event_id of the client event that caused the error, if applicable.\n */\n event_id?: string | null;\n\n /**\n * Parameter related to the error, if any.\n */\n param?: string | null;\n}\n\n/**\n * Returned when an error occurs, which could be a client problem or a server\n * problem. Most errors are recoverable and the session will stay open, we\n * recommend to implementors to monitor and log error messages by default.\n */\nexport interface RealtimeErrorEvent {\n /**\n * Details of the error.\n */\n error: RealtimeError;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The event type, must be `error`.\n */\n type: 'error';\n}\n\nexport interface RealtimeFunctionTool {\n /**\n * The description of the function, including guidance on when and how to call it,\n * and guidance about what to tell the user when calling (if anything).\n */\n description?: string;\n\n /**\n * The name of the function.\n */\n name?: string;\n\n /**\n * Parameters of the function in JSON Schema.\n */\n parameters?: unknown;\n\n /**\n * The type of the tool, i.e. `function`.\n */\n type?: 'function';\n}\n\n/**\n * A Realtime item requesting human approval of a tool invocation.\n */\nexport interface RealtimeMcpApprovalRequest {\n /**\n * The unique ID of the approval request.\n */\n id: string;\n\n /**\n * A JSON string of arguments for the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool to run.\n */\n name: string;\n\n /**\n * The label of the MCP server making the request.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_approval_request`.\n */\n type: 'mcp_approval_request';\n}\n\n/**\n * A Realtime item responding to an MCP approval request.\n */\nexport interface RealtimeMcpApprovalResponse {\n /**\n * The unique ID of the approval response.\n */\n id: string;\n\n /**\n * The ID of the approval request being answered.\n */\n approval_request_id: string;\n\n /**\n * Whether the request was approved.\n */\n approve: boolean;\n\n /**\n * The type of the item. Always `mcp_approval_response`.\n */\n type: 'mcp_approval_response';\n\n /**\n * Optional reason for the decision.\n */\n reason?: string | null;\n}\n\n/**\n * A Realtime item listing tools available on an MCP server.\n */\nexport interface RealtimeMcpListTools {\n /**\n * The label of the MCP server.\n */\n server_label: string;\n\n /**\n * The tools available on the server.\n */\n tools: Array<RealtimeMcpListTools.Tool>;\n\n /**\n * The type of the item. Always `mcp_list_tools`.\n */\n type: 'mcp_list_tools';\n\n /**\n * The unique ID of the list.\n */\n id?: string;\n}\n\nexport namespace RealtimeMcpListTools {\n /**\n * A tool available on an MCP server.\n */\n export interface Tool {\n /**\n * The JSON schema describing the tool's input.\n */\n input_schema: unknown;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * Additional annotations about the tool.\n */\n annotations?: unknown | null;\n\n /**\n * The description of the tool.\n */\n description?: string | null;\n }\n}\n\nexport interface RealtimeMcpProtocolError {\n code: number;\n\n message: string;\n\n type: 'protocol_error';\n}\n\n/**\n * A Realtime item representing an invocation of a tool on an MCP server.\n */\nexport interface RealtimeMcpToolCall {\n /**\n * The unique ID of the tool call.\n */\n id: string;\n\n /**\n * A JSON string of the arguments passed to the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool that was run.\n */\n name: string;\n\n /**\n * The label of the MCP server running the tool.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_call`.\n */\n type: 'mcp_call';\n\n /**\n * The ID of an associated approval request, if any.\n */\n approval_request_id?: string | null;\n\n /**\n * The error from the tool call, if any.\n */\n error?: RealtimeMcpProtocolError | RealtimeMcpToolExecutionError | RealtimeMcphttpError | null;\n\n /**\n * The output from the tool call.\n */\n output?: string | null;\n}\n\nexport interface RealtimeMcpToolExecutionError {\n message: string;\n\n type: 'tool_execution_error';\n}\n\nexport interface RealtimeMcphttpError {\n code: number;\n\n message: string;\n\n type: 'http_error';\n}\n\n/**\n * The response resource.\n */\nexport interface RealtimeResponse {\n /**\n * The unique ID of the response, will look like `resp_1234`.\n */\n id?: string;\n\n /**\n * Configuration for audio output.\n */\n audio?: RealtimeResponse.Audio;\n\n /**\n * Which conversation the response is added to, determined by the `conversation`\n * field in the `response.create` event. If `auto`, the response will be added to\n * the default conversation and the value of `conversation_id` will be an id like\n * `conv_1234`. If `none`, the response will not be added to any conversation and\n * the value of `conversation_id` will be `null`. If responses are being triggered\n * automatically by VAD the response will be added to the default conversation\n */\n conversation_id?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls, that was used in this response.\n */\n max_output_tokens?: number | 'inf';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The object type, must be `realtime.response`.\n */\n object?: 'realtime.response';\n\n /**\n * The list of output items generated by the response.\n */\n output?: Array<ConversationItem>;\n\n /**\n * The set of modalities the model used to respond, currently the only possible\n * values are `[\\\"audio\\\"]`, `[\\\"text\\\"]`. Audio output always include a text\n * transcript. Setting the output to mode `text` will disable audio output from the\n * model.\n */\n output_modalities?: Array<'text' | 'audio'>;\n\n /**\n * The final status of the response (`completed`, `cancelled`, `failed`, or\n * `incomplete`, `in_progress`).\n */\n status?: 'completed' | 'cancelled' | 'failed' | 'incomplete' | 'in_progress';\n\n /**\n * Additional details about the status.\n */\n status_details?: RealtimeResponseStatus;\n\n /**\n * Usage statistics for the Response, this will correspond to billing. A Realtime\n * API session will maintain a conversation context and append new Items to the\n * Conversation, thus output from previous turns (text and audio tokens) will\n * become the input for later turns.\n */\n usage?: RealtimeResponseUsage;\n}\n\nexport namespace RealtimeResponse {\n /**\n * Configuration for audio output.\n */\n export interface Audio {\n output?: Audio.Output;\n }\n\n export namespace Audio {\n export interface Output {\n /**\n * The format of the output audio.\n */\n format?: RealtimeAPI.RealtimeAudioFormats;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`,\n * and `cedar`. We recommend `marin` and `cedar` for best quality.\n */\n voice?:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n }\n }\n}\n\n/**\n * Configuration for audio input and output.\n */\nexport interface RealtimeResponseCreateAudioOutput {\n output?: RealtimeResponseCreateAudioOutput.Output;\n}\n\nexport namespace RealtimeResponseCreateAudioOutput {\n export interface Output {\n /**\n * The format of the output audio.\n */\n format?: RealtimeAPI.RealtimeAudioFormats;\n\n /**\n * The voice the model uses to respond. Supported built-in voices are `alloy`,\n * `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, `verse`, `marin`, and\n * `cedar`. Voice cannot be changed during the session once the model has responded\n * with audio at least once.\n */\n voice?:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n }\n}\n\n/**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\nexport interface RealtimeResponseCreateMcpTool {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n server_label: string;\n\n /**\n * The type of the MCP tool. Always `mcp`.\n */\n type: 'mcp';\n\n /**\n * List of allowed tool names or a filter object.\n */\n allowed_tools?: Array<string> | RealtimeResponseCreateMcpTool.McpToolFilter | null;\n\n /**\n * An OAuth access token that can be used with a remote MCP server, either with a\n * custom MCP server URL or a service connector. Your application must handle the\n * OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n\n /**\n * Identifier for service connectors, like those available in ChatGPT. One of\n * `server_url` or `connector_id` must be provided. Learn more about service\n * connectors\n * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n *\n * Currently supported `connector_id` values are:\n *\n * - Dropbox: `connector_dropbox`\n * - Gmail: `connector_gmail`\n * - Google Calendar: `connector_googlecalendar`\n * - Google Drive: `connector_googledrive`\n * - Microsoft Teams: `connector_microsoftteams`\n * - Outlook Calendar: `connector_outlookcalendar`\n * - Outlook Email: `connector_outlookemail`\n * - SharePoint: `connector_sharepoint`\n */\n connector_id?:\n | 'connector_dropbox'\n | 'connector_gmail'\n | 'connector_googlecalendar'\n | 'connector_googledrive'\n | 'connector_microsoftteams'\n | 'connector_outlookcalendar'\n | 'connector_outlookemail'\n | 'connector_sharepoint';\n\n /**\n * Whether this MCP tool is deferred and discovered via tool search.\n */\n defer_loading?: boolean;\n\n /**\n * Optional HTTP headers to send to the MCP server. Use for authentication or other\n * purposes.\n */\n headers?: { [key: string]: string } | null;\n\n /**\n * Specify which of the MCP server's tools require approval.\n */\n require_approval?: RealtimeResponseCreateMcpTool.McpToolApprovalFilter | 'always' | 'never' | null;\n\n /**\n * Optional description of the MCP server, used to provide more context.\n */\n server_description?: string;\n\n /**\n * The URL for the MCP server. One of `server_url` or `connector_id` must be\n * provided.\n */\n server_url?: string;\n}\n\nexport namespace RealtimeResponseCreateMcpTool {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface McpToolFilter {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * Specify which of the MCP server's tools require approval. Can be `always`,\n * `never`, or a filter object associated with tools that require approval.\n */\n export interface McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n always?: McpToolApprovalFilter.Always;\n\n /**\n * A filter object to specify which tools are allowed.\n */\n never?: McpToolApprovalFilter.Never;\n }\n\n export namespace McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Always {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Never {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n }\n}\n\n/**\n * Create a new Realtime response with these parameters\n */\nexport interface RealtimeResponseCreateParams {\n /**\n * Configuration for audio input and output.\n */\n audio?: RealtimeResponseCreateAudioOutput;\n\n /**\n * Controls which conversation the response is added to. Currently supports `auto`\n * and `none`, with `auto` as the default value. The `auto` value means that the\n * contents of the response will be added to the default conversation. Set this to\n * `none` to create an out-of-band response which will not add items to default\n * conversation.\n */\n conversation?: (string & {}) | 'auto' | 'none';\n\n /**\n * Input items to include in the prompt for the model. Using this field creates a\n * new context for this Response instead of using the default conversation. An\n * empty array `[]` will clear the context for this Response. Note that this can\n * include references to items that previously appeared in the session using their\n * id.\n */\n input?: Array<ConversationItem>;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior. Note that the server sets default\n * instructions which will be used if this field is not set and are visible in the\n * `session.created` event at the start of the session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_output_tokens?: number | 'inf';\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The set of modalities the model used to respond, currently the only possible\n * values are `[\\\"audio\\\"]`, `[\\\"text\\\"]`. Audio output always include a text\n * transcript. Setting the output to mode `text` will disable audio output from the\n * model.\n */\n output_modalities?: Array<'text' | 'audio'>;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsesAPI.ResponsePrompt | null;\n\n /**\n * How the model chooses tools. Provide one of the string modes or force a specific\n * function/MCP tool.\n */\n tool_choice?: ResponsesAPI.ToolChoiceOptions | ResponsesAPI.ToolChoiceFunction | ResponsesAPI.ToolChoiceMcp;\n\n /**\n * Tools available to the model.\n */\n tools?: Array<RealtimeFunctionTool | RealtimeResponseCreateMcpTool>;\n}\n\n/**\n * Additional details about the status.\n */\nexport interface RealtimeResponseStatus {\n /**\n * A description of the error that caused the response to fail, populated when the\n * `status` is `failed`.\n */\n error?: RealtimeResponseStatus.Error;\n\n /**\n * The reason the Response did not complete. For a `cancelled` Response, one of\n * `turn_detected` (the server VAD detected a new start of speech) or\n * `client_cancelled` (the client sent a cancel event). For an `incomplete`\n * Response, one of `max_output_tokens` or `content_filter` (the server-side safety\n * filter activated and cut off the response).\n */\n reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';\n\n /**\n * The type of error that caused the response to fail, corresponding with the\n * `status` field (`completed`, `cancelled`, `incomplete`, `failed`).\n */\n type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';\n}\n\nexport namespace RealtimeResponseStatus {\n /**\n * A description of the error that caused the response to fail, populated when the\n * `status` is `failed`.\n */\n export interface Error {\n /**\n * Error code, if any.\n */\n code?: string;\n\n /**\n * The type of error.\n */\n type?: string;\n }\n}\n\n/**\n * Usage statistics for the Response, this will correspond to billing. A Realtime\n * API session will maintain a conversation context and append new Items to the\n * Conversation, thus output from previous turns (text and audio tokens) will\n * become the input for later turns.\n */\nexport interface RealtimeResponseUsage {\n /**\n * Details about the input tokens used in the Response. Cached tokens are tokens\n * from previous turns in the conversation that are included as context for the\n * current response. Cached tokens here are counted as a subset of input tokens,\n * meaning input tokens will include cached and uncached tokens.\n */\n input_token_details?: RealtimeResponseUsageInputTokenDetails;\n\n /**\n * The number of input tokens used in the Response, including text and audio\n * tokens.\n */\n input_tokens?: number;\n\n /**\n * Details about the output tokens used in the Response.\n */\n output_token_details?: RealtimeResponseUsageOutputTokenDetails;\n\n /**\n * The number of output tokens sent in the Response, including text and audio\n * tokens.\n */\n output_tokens?: number;\n\n /**\n * The total number of tokens in the Response including input and output text and\n * audio tokens.\n */\n total_tokens?: number;\n}\n\n/**\n * Details about the input tokens used in the Response. Cached tokens are tokens\n * from previous turns in the conversation that are included as context for the\n * current response. Cached tokens here are counted as a subset of input tokens,\n * meaning input tokens will include cached and uncached tokens.\n */\nexport interface RealtimeResponseUsageInputTokenDetails {\n /**\n * The number of audio tokens used as input for the Response.\n */\n audio_tokens?: number;\n\n /**\n * The number of cached tokens used as input for the Response.\n */\n cached_tokens?: number;\n\n /**\n * Details about the cached tokens used as input for the Response.\n */\n cached_tokens_details?: RealtimeResponseUsageInputTokenDetails.CachedTokensDetails;\n\n /**\n * The number of image tokens used as input for the Response.\n */\n image_tokens?: number;\n\n /**\n * The number of text tokens used as input for the Response.\n */\n text_tokens?: number;\n}\n\nexport namespace RealtimeResponseUsageInputTokenDetails {\n /**\n * Details about the cached tokens used as input for the Response.\n */\n export interface CachedTokensDetails {\n /**\n * The number of cached audio tokens used as input for the Response.\n */\n audio_tokens?: number;\n\n /**\n * The number of cached image tokens used as input for the Response.\n */\n image_tokens?: number;\n\n /**\n * The number of cached text tokens used as input for the Response.\n */\n text_tokens?: number;\n }\n}\n\n/**\n * Details about the output tokens used in the Response.\n */\nexport interface RealtimeResponseUsageOutputTokenDetails {\n /**\n * The number of audio tokens used in the Response.\n */\n audio_tokens?: number;\n\n /**\n * The number of text tokens used in the Response.\n */\n text_tokens?: number;\n}\n\n/**\n * A realtime server event.\n */\nexport type RealtimeServerEvent =\n | ConversationCreatedEvent\n | ConversationItemCreatedEvent\n | ConversationItemDeletedEvent\n | ConversationItemInputAudioTranscriptionCompletedEvent\n | ConversationItemInputAudioTranscriptionDeltaEvent\n | ConversationItemInputAudioTranscriptionFailedEvent\n | RealtimeServerEvent.ConversationItemRetrieved\n | ConversationItemTruncatedEvent\n | RealtimeErrorEvent\n | InputAudioBufferClearedEvent\n | InputAudioBufferCommittedEvent\n | InputAudioBufferDtmfEventReceivedEvent\n | InputAudioBufferSpeechStartedEvent\n | InputAudioBufferSpeechStoppedEvent\n | RateLimitsUpdatedEvent\n | ResponseAudioDeltaEvent\n | ResponseAudioDoneEvent\n | ResponseAudioTranscriptDeltaEvent\n | ResponseAudioTranscriptDoneEvent\n | ResponseContentPartAddedEvent\n | ResponseContentPartDoneEvent\n | ResponseCreatedEvent\n | ResponseDoneEvent\n | ResponseFunctionCallArgumentsDeltaEvent\n | ResponseFunctionCallArgumentsDoneEvent\n | ResponseOutputItemAddedEvent\n | ResponseOutputItemDoneEvent\n | ResponseTextDeltaEvent\n | ResponseTextDoneEvent\n | SessionCreatedEvent\n | SessionUpdatedEvent\n | RealtimeServerEvent.OutputAudioBufferStarted\n | RealtimeServerEvent.OutputAudioBufferStopped\n | RealtimeServerEvent.OutputAudioBufferCleared\n | ConversationItemAdded\n | ConversationItemDone\n | InputAudioBufferTimeoutTriggered\n | ConversationItemInputAudioTranscriptionSegment\n | McpListToolsInProgress\n | McpListToolsCompleted\n | McpListToolsFailed\n | ResponseMcpCallArgumentsDelta\n | ResponseMcpCallArgumentsDone\n | ResponseMcpCallInProgress\n | ResponseMcpCallCompleted\n | ResponseMcpCallFailed;\n\nexport namespace RealtimeServerEvent {\n /**\n * Returned when a conversation item is retrieved with\n * `conversation.item.retrieve`. This is provided as a way to fetch the server's\n * representation of an item, for example to get access to the post-processed audio\n * data after noise cancellation and VAD. It includes the full content of the Item,\n * including audio data.\n */\n export interface ConversationItemRetrieved {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A single item within a Realtime conversation.\n */\n item: RealtimeAPI.ConversationItem;\n\n /**\n * The event type, must be `conversation.item.retrieved`.\n */\n type: 'conversation.item.retrieved';\n }\n\n /**\n * **WebRTC/SIP Only:** Emitted when the server begins streaming audio to the\n * client. This event is emitted after an audio content part has been added\n * (`response.content_part.added`) to the response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferStarted {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The unique ID of the response that produced the audio.\n */\n response_id: string;\n\n /**\n * The event type, must be `output_audio_buffer.started`.\n */\n type: 'output_audio_buffer.started';\n }\n\n /**\n * **WebRTC/SIP Only:** Emitted when the output audio buffer has been completely\n * drained on the server, and no more audio is forthcoming. This event is emitted\n * after the full response data has been sent to the client (`response.done`).\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferStopped {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The unique ID of the response that produced the audio.\n */\n response_id: string;\n\n /**\n * The event type, must be `output_audio_buffer.stopped`.\n */\n type: 'output_audio_buffer.stopped';\n }\n\n /**\n * **WebRTC/SIP Only:** Emitted when the output audio buffer is cleared. This\n * happens either in VAD mode when the user has interrupted\n * (`input_audio_buffer.speech_started`), or when the client has emitted the\n * `output_audio_buffer.clear` event to manually cut off the current audio\n * response.\n * [Learn more](https://platform.openai.com/docs/guides/realtime-conversations#client-and-server-events-for-audio-in-webrtc).\n */\n export interface OutputAudioBufferCleared {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The unique ID of the response that produced the audio.\n */\n response_id: string;\n\n /**\n * The event type, must be `output_audio_buffer.cleared`.\n */\n type: 'output_audio_buffer.cleared';\n }\n}\n\n/**\n * Realtime session object for the beta interface.\n */\nexport interface RealtimeSession {\n /**\n * Unique identifier for the session that looks like `sess_1234567890abcdef`.\n */\n id?: string;\n\n /**\n * Expiration timestamp for the session, in seconds since epoch.\n */\n expires_at?: number;\n\n /**\n * Additional fields to include in server outputs.\n *\n * - `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n * transcription.\n */\n include?: Array<'item.input_audio_transcription.logprobs'> | null;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: RealtimeSession.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n input_audio_transcription?: AudioTranscription | null;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_response_output_tokens?: number | 'inf';\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | (string & {})\n | 'gpt-realtime'\n | 'gpt-realtime-1.5'\n | 'gpt-realtime-2025-08-28'\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17'\n | 'gpt-realtime-mini'\n | 'gpt-realtime-mini-2025-10-06'\n | 'gpt-realtime-mini-2025-12-15'\n | 'gpt-audio-1.5'\n | 'gpt-audio-mini'\n | 'gpt-audio-mini-2025-10-06'\n | 'gpt-audio-mini-2025-12-15';\n\n /**\n * The object type. Always `realtime.session`.\n */\n object?: 'realtime.session';\n\n /**\n * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n * For `pcm16`, output audio is sampled at a rate of 24kHz.\n */\n output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsesAPI.ResponsePrompt | null;\n\n /**\n * The speed of the model's spoken response. 1.0 is the default speed. 0.25 is the\n * minimum speed. 1.5 is the maximum speed. This value can only be changed in\n * between model turns, not while a response is in progress.\n */\n speed?: number;\n\n /**\n * Sampling temperature for the model, limited to [0.6, 1.2]. For audio models a\n * temperature of 0.8 is highly recommended for best performance.\n */\n temperature?: number;\n\n /**\n * How the model chooses tools. Options are `auto`, `none`, `required`, or specify\n * a function.\n */\n tool_choice?: string;\n\n /**\n * Tools (functions) available to the model.\n */\n tools?: Array<RealtimeFunctionTool>;\n\n /**\n * Configuration options for tracing. Set to null to disable tracing. Once tracing\n * is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: 'auto' | RealtimeSession.TracingConfiguration | null;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\n turn_detection?: RealtimeSession.ServerVad | RealtimeSession.SemanticVad | null;\n\n /**\n * The voice the model uses to respond. Voice cannot be changed during the session\n * once the model has responded with audio at least once. Current voice options are\n * `alloy`, `ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n */\n voice?:\n | (string & {})\n | 'alloy'\n | 'ash'\n | 'ballad'\n | 'coral'\n | 'echo'\n | 'sage'\n | 'shimmer'\n | 'verse'\n | 'marin'\n | 'cedar';\n}\n\nexport namespace RealtimeSession {\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: RealtimeAPI.NoiseReductionType;\n }\n\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * traces dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the traces\n * dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the traces dashboard.\n */\n workflow_name?: string;\n }\n\n /**\n * Server-side voice activity detection (VAD) which flips on when user speech is\n * detected and off after a period of silence.\n */\n export interface ServerVad {\n /**\n * Type of turn detection, `server_vad` to turn on simple Server VAD.\n */\n type: 'server_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs. If `interrupt_response` is set to `false` this may fail to create a\n * response if the model is already responding.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n create_response?: boolean;\n\n /**\n * Optional timeout after which a model response will be triggered automatically.\n * This is useful for situations in which a long pause from the user is unexpected,\n * such as a phone call. The model will effectively prompt the user to continue the\n * conversation based on the current context.\n *\n * The timeout value will be applied after the last model response's audio has\n * finished playing, i.e. it's set to the `response.done` time plus audio playback\n * duration.\n *\n * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n * Response) will be emitted when the timeout is reached. Idle timeout is currently\n * only supported for `server_vad` mode.\n */\n idle_timeout_ms?: number | null;\n\n /**\n * Whether or not to automatically interrupt (cancel) any ongoing response with\n * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n * start event occurs. If `true` then the response will be cancelled, otherwise it\n * will continue until complete.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n }\n\n /**\n * Server-side semantic turn detection which uses a model to determine when the\n * user has finished speaking.\n */\n export interface SemanticVad {\n /**\n * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n */\n type: 'semantic_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n }\n}\n\n/**\n * Realtime session object configuration.\n */\nexport interface RealtimeSessionCreateRequest {\n /**\n * The type of session to create. Always `realtime` for the Realtime API.\n */\n type: 'realtime';\n\n /**\n * Configuration for input and output audio.\n */\n audio?: RealtimeAudioConfig;\n\n /**\n * Additional fields to include in server outputs.\n *\n * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n * transcription.\n */\n include?: Array<'item.input_audio_transcription.logprobs'>;\n\n /**\n * The default system instructions (i.e. system message) prepended to model calls.\n * This field allows the client to guide the model on desired responses. The model\n * can be instructed on response content and format, (e.g. \"be extremely succinct\",\n * \"act friendly\", \"here are examples of good responses\") and on audio behavior\n * (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The\n * instructions are not guaranteed to be followed by the model, but they provide\n * guidance to the model on the desired behavior.\n *\n * Note that the server sets default instructions which will be used if this field\n * is not set and are visible in the `session.created` event at the start of the\n * session.\n */\n instructions?: string;\n\n /**\n * Maximum number of output tokens for a single assistant response, inclusive of\n * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or\n * `inf` for the maximum available tokens for a given model. Defaults to `inf`.\n */\n max_output_tokens?: number | 'inf';\n\n /**\n * The Realtime model used for this session.\n */\n model?:\n | (string & {})\n | 'gpt-realtime'\n | 'gpt-realtime-1.5'\n | 'gpt-realtime-2025-08-28'\n | 'gpt-4o-realtime-preview'\n | 'gpt-4o-realtime-preview-2024-10-01'\n | 'gpt-4o-realtime-preview-2024-12-17'\n | 'gpt-4o-realtime-preview-2025-06-03'\n | 'gpt-4o-mini-realtime-preview'\n | 'gpt-4o-mini-realtime-preview-2024-12-17'\n | 'gpt-realtime-mini'\n | 'gpt-realtime-mini-2025-10-06'\n | 'gpt-realtime-mini-2025-12-15'\n | 'gpt-audio-1.5'\n | 'gpt-audio-mini'\n | 'gpt-audio-mini-2025-10-06'\n | 'gpt-audio-mini-2025-12-15';\n\n /**\n * The set of modalities the model can respond with. It defaults to `[\"audio\"]`,\n * indicating that the model will respond with audio plus a transcript. `[\"text\"]`\n * can be used to make the model respond with text only. It is not possible to\n * request both `text` and `audio` at the same time.\n */\n output_modalities?: Array<'text' | 'audio'>;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsesAPI.ResponsePrompt | null;\n\n /**\n * How the model chooses tools. Provide one of the string modes or force a specific\n * function/MCP tool.\n */\n tool_choice?: RealtimeToolChoiceConfig;\n\n /**\n * Tools available to the model.\n */\n tools?: RealtimeToolsConfig;\n\n /**\n * Realtime API can write session traces to the\n * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n * tracing is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\n tracing?: RealtimeTracingConfig | null;\n\n /**\n * When the number of tokens in a conversation exceeds the model's input token\n * limit, the conversation be truncated, meaning messages (starting from the\n * oldest) will not be included in the model's context. A 32k context model with\n * 4,096 max output tokens can only include 28,224 tokens in the context before\n * truncation occurs.\n *\n * Clients can configure truncation behavior to truncate with a lower max token\n * limit, which is an effective way to control token usage and cost.\n *\n * Truncation will reduce the number of cached tokens on the next turn (busting the\n * cache), since messages are dropped from the beginning of the context. However,\n * clients can also configure truncation to retain messages up to a fraction of the\n * maximum context size, which will reduce the need for future truncations and thus\n * improve the cache rate.\n *\n * Truncation can be disabled entirely, which means the server will never truncate\n * but would instead return an error if the conversation exceeds the model's input\n * token limit.\n */\n truncation?: RealtimeTruncation;\n}\n\n/**\n * How the model chooses tools. Provide one of the string modes or force a specific\n * function/MCP tool.\n */\nexport type RealtimeToolChoiceConfig =\n | ResponsesAPI.ToolChoiceOptions\n | ResponsesAPI.ToolChoiceFunction\n | ResponsesAPI.ToolChoiceMcp;\n\n/**\n * Tools available to the model.\n */\nexport type RealtimeToolsConfig = Array<RealtimeToolsConfigUnion>;\n\n/**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\nexport type RealtimeToolsConfigUnion = RealtimeFunctionTool | RealtimeToolsConfigUnion.Mcp;\n\nexport namespace RealtimeToolsConfigUnion {\n /**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\n export interface Mcp {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n server_label: string;\n\n /**\n * The type of the MCP tool. Always `mcp`.\n */\n type: 'mcp';\n\n /**\n * List of allowed tool names or a filter object.\n */\n allowed_tools?: Array<string> | Mcp.McpToolFilter | null;\n\n /**\n * An OAuth access token that can be used with a remote MCP server, either with a\n * custom MCP server URL or a service connector. Your application must handle the\n * OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n\n /**\n * Identifier for service connectors, like those available in ChatGPT. One of\n * `server_url` or `connector_id` must be provided. Learn more about service\n * connectors\n * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n *\n * Currently supported `connector_id` values are:\n *\n * - Dropbox: `connector_dropbox`\n * - Gmail: `connector_gmail`\n * - Google Calendar: `connector_googlecalendar`\n * - Google Drive: `connector_googledrive`\n * - Microsoft Teams: `connector_microsoftteams`\n * - Outlook Calendar: `connector_outlookcalendar`\n * - Outlook Email: `connector_outlookemail`\n * - SharePoint: `connector_sharepoint`\n */\n connector_id?:\n | 'connector_dropbox'\n | 'connector_gmail'\n | 'connector_googlecalendar'\n | 'connector_googledrive'\n | 'connector_microsoftteams'\n | 'connector_outlookcalendar'\n | 'connector_outlookemail'\n | 'connector_sharepoint';\n\n /**\n * Whether this MCP tool is deferred and discovered via tool search.\n */\n defer_loading?: boolean;\n\n /**\n * Optional HTTP headers to send to the MCP server. Use for authentication or other\n * purposes.\n */\n headers?: { [key: string]: string } | null;\n\n /**\n * Specify which of the MCP server's tools require approval.\n */\n require_approval?: Mcp.McpToolApprovalFilter | 'always' | 'never' | null;\n\n /**\n * Optional description of the MCP server, used to provide more context.\n */\n server_description?: string;\n\n /**\n * The URL for the MCP server. One of `server_url` or `connector_id` must be\n * provided.\n */\n server_url?: string;\n }\n\n export namespace Mcp {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface McpToolFilter {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * Specify which of the MCP server's tools require approval. Can be `always`,\n * `never`, or a filter object associated with tools that require approval.\n */\n export interface McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n always?: McpToolApprovalFilter.Always;\n\n /**\n * A filter object to specify which tools are allowed.\n */\n never?: McpToolApprovalFilter.Never;\n }\n\n export namespace McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Always {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Never {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n }\n }\n}\n\n/**\n * Realtime API can write session traces to the\n * [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once\n * tracing is enabled for a session, the configuration cannot be modified.\n *\n * `auto` will create a trace for the session with default values for the workflow\n * name, group id, and metadata.\n */\nexport type RealtimeTracingConfig = 'auto' | RealtimeTracingConfig.TracingConfiguration;\n\nexport namespace RealtimeTracingConfig {\n /**\n * Granular configuration for tracing.\n */\n export interface TracingConfiguration {\n /**\n * The group id to attach to this trace to enable filtering and grouping in the\n * Traces Dashboard.\n */\n group_id?: string;\n\n /**\n * The arbitrary metadata to attach to this trace to enable filtering in the Traces\n * Dashboard.\n */\n metadata?: unknown;\n\n /**\n * The name of the workflow to attach to this trace. This is used to name the trace\n * in the Traces Dashboard.\n */\n workflow_name?: string;\n }\n}\n\n/**\n * Configuration for input and output audio.\n */\nexport interface RealtimeTranscriptionSessionAudio {\n input?: RealtimeTranscriptionSessionAudioInput;\n}\n\nexport interface RealtimeTranscriptionSessionAudioInput {\n /**\n * The PCM audio format. Only a 24kHz sample rate is supported.\n */\n format?: RealtimeAudioFormats;\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n noise_reduction?: RealtimeTranscriptionSessionAudioInput.NoiseReduction;\n\n /**\n * Configuration for input audio transcription, defaults to off and can be set to\n * `null` to turn off once on. Input audio transcription is not native to the\n * model, since the model consumes audio directly. Transcription runs\n * asynchronously through\n * [the /audio/transcriptions endpoint](https://platform.openai.com/docs/api-reference/audio/createTranscription)\n * and should be treated as guidance of input audio content rather than precisely\n * what the model heard. The client can optionally set the language and prompt for\n * transcription, these offer additional guidance to the transcription service.\n */\n transcription?: AudioTranscription;\n\n /**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\n turn_detection?: RealtimeTranscriptionSessionAudioInputTurnDetection | null;\n}\n\nexport namespace RealtimeTranscriptionSessionAudioInput {\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface NoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: RealtimeAPI.NoiseReductionType;\n }\n}\n\n/**\n * Configuration for turn detection, ether Server VAD or Semantic VAD. This can be\n * set to `null` to turn off, in which case the client must manually trigger model\n * response.\n *\n * Server VAD means that the model will detect the start and end of speech based on\n * audio volume and respond at the end of user speech.\n *\n * Semantic VAD is more advanced and uses a turn detection model (in conjunction\n * with VAD) to semantically estimate whether the user has finished speaking, then\n * dynamically sets a timeout based on this probability. For example, if user audio\n * trails off with \"uhhm\", the model will score a low probability of turn end and\n * wait longer for the user to continue speaking. This can be useful for more\n * natural conversations, but may have a higher latency.\n */\nexport type RealtimeTranscriptionSessionAudioInputTurnDetection =\n | RealtimeTranscriptionSessionAudioInputTurnDetection.ServerVad\n | RealtimeTranscriptionSessionAudioInputTurnDetection.SemanticVad;\n\nexport namespace RealtimeTranscriptionSessionAudioInputTurnDetection {\n /**\n * Server-side voice activity detection (VAD) which flips on when user speech is\n * detected and off after a period of silence.\n */\n export interface ServerVad {\n /**\n * Type of turn detection, `server_vad` to turn on simple Server VAD.\n */\n type: 'server_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs. If `interrupt_response` is set to `false` this may fail to create a\n * response if the model is already responding.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n create_response?: boolean;\n\n /**\n * Optional timeout after which a model response will be triggered automatically.\n * This is useful for situations in which a long pause from the user is unexpected,\n * such as a phone call. The model will effectively prompt the user to continue the\n * conversation based on the current context.\n *\n * The timeout value will be applied after the last model response's audio has\n * finished playing, i.e. it's set to the `response.done` time plus audio playback\n * duration.\n *\n * An `input_audio_buffer.timeout_triggered` event (plus events associated with the\n * Response) will be emitted when the timeout is reached. Idle timeout is currently\n * only supported for `server_vad` mode.\n */\n idle_timeout_ms?: number | null;\n\n /**\n * Whether or not to automatically interrupt (cancel) any ongoing response with\n * output to the default conversation (i.e. `conversation` of `auto`) when a VAD\n * start event occurs. If `true` then the response will be cancelled, otherwise it\n * will continue until complete.\n *\n * If both `create_response` and `interrupt_response` are set to `false`, the model\n * will never respond automatically but VAD events will still be emitted.\n */\n interrupt_response?: boolean;\n\n /**\n * Used only for `server_vad` mode. Amount of audio to include before the VAD\n * detected speech (in milliseconds). Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Duration of silence to detect speech stop (in\n * milliseconds). Defaults to 500ms. With shorter values the model will respond\n * more quickly, but may jump in on short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Used only for `server_vad` mode. Activation threshold for VAD (0.0 to 1.0), this\n * defaults to 0.5. A higher threshold will require louder audio to activate the\n * model, and thus might perform better in noisy environments.\n */\n threshold?: number;\n }\n\n /**\n * Server-side semantic turn detection which uses a model to determine when the\n * user has finished speaking.\n */\n export interface SemanticVad {\n /**\n * Type of turn detection, `semantic_vad` to turn on Semantic VAD.\n */\n type: 'semantic_vad';\n\n /**\n * Whether or not to automatically generate a response when a VAD stop event\n * occurs.\n */\n create_response?: boolean;\n\n /**\n * Used only for `semantic_vad` mode. The eagerness of the model to respond. `low`\n * will wait longer for the user to continue speaking, `high` will respond more\n * quickly. `auto` is the default and is equivalent to `medium`. `low`, `medium`,\n * and `high` have max timeouts of 8s, 4s, and 2s respectively.\n */\n eagerness?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * Whether or not to automatically interrupt any ongoing response with output to\n * the default conversation (i.e. `conversation` of `auto`) when a VAD start event\n * occurs.\n */\n interrupt_response?: boolean;\n }\n}\n\n/**\n * Realtime transcription session object configuration.\n */\nexport interface RealtimeTranscriptionSessionCreateRequest {\n /**\n * The type of session to create. Always `transcription` for transcription\n * sessions.\n */\n type: 'transcription';\n\n /**\n * Configuration for input and output audio.\n */\n audio?: RealtimeTranscriptionSessionAudio;\n\n /**\n * Additional fields to include in server outputs.\n *\n * `item.input_audio_transcription.logprobs`: Include logprobs for input audio\n * transcription.\n */\n include?: Array<'item.input_audio_transcription.logprobs'>;\n}\n\n/**\n * When the number of tokens in a conversation exceeds the model's input token\n * limit, the conversation be truncated, meaning messages (starting from the\n * oldest) will not be included in the model's context. A 32k context model with\n * 4,096 max output tokens can only include 28,224 tokens in the context before\n * truncation occurs.\n *\n * Clients can configure truncation behavior to truncate with a lower max token\n * limit, which is an effective way to control token usage and cost.\n *\n * Truncation will reduce the number of cached tokens on the next turn (busting the\n * cache), since messages are dropped from the beginning of the context. However,\n * clients can also configure truncation to retain messages up to a fraction of the\n * maximum context size, which will reduce the need for future truncations and thus\n * improve the cache rate.\n *\n * Truncation can be disabled entirely, which means the server will never truncate\n * but would instead return an error if the conversation exceeds the model's input\n * token limit.\n */\nexport type RealtimeTruncation = 'auto' | 'disabled' | RealtimeTruncationRetentionRatio;\n\n/**\n * Retain a fraction of the conversation tokens when the conversation exceeds the\n * input token limit. This allows you to amortize truncations across multiple\n * turns, which can help improve cached token usage.\n */\nexport interface RealtimeTruncationRetentionRatio {\n /**\n * Fraction of post-instruction conversation tokens to retain (`0.0` - `1.0`) when\n * the conversation exceeds the input token limit. Setting this to `0.8` means that\n * messages will be dropped until 80% of the maximum allowed tokens are used. This\n * helps reduce the frequency of truncations and improve cache rates.\n */\n retention_ratio: number;\n\n /**\n * Use retention ratio truncation.\n */\n type: 'retention_ratio';\n\n /**\n * Optional custom token limits for this truncation strategy. If not provided, the\n * model's default token limits will be used.\n */\n token_limits?: RealtimeTruncationRetentionRatio.TokenLimits;\n}\n\nexport namespace RealtimeTruncationRetentionRatio {\n /**\n * Optional custom token limits for this truncation strategy. If not provided, the\n * model's default token limits will be used.\n */\n export interface TokenLimits {\n /**\n * Maximum tokens allowed in the conversation after instructions (which including\n * tool definitions). For example, setting this to 5,000 would mean that truncation\n * would occur when the conversation exceeds 5,000 tokens after instructions. This\n * cannot be higher than the model's context window size minus the maximum output\n * tokens.\n */\n post_instructions?: number;\n }\n}\n\n/**\n * Returned when the model-generated audio is updated.\n */\nexport interface ResponseAudioDeltaEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * Base64-encoded audio data delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_audio.delta`.\n */\n type: 'response.output_audio.delta';\n}\n\n/**\n * Returned when the model-generated audio is done. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseAudioDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_audio.done`.\n */\n type: 'response.output_audio.done';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is updated.\n */\nexport interface ResponseAudioTranscriptDeltaEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The transcript delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_audio_transcript.delta`.\n */\n type: 'response.output_audio_transcript.delta';\n}\n\n/**\n * Returned when the model-generated transcription of audio output is done\n * streaming. Also emitted when a Response is interrupted, incomplete, or\n * cancelled.\n */\nexport interface ResponseAudioTranscriptDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The final transcript of the audio.\n */\n transcript: string;\n\n /**\n * The event type, must be `response.output_audio_transcript.done`.\n */\n type: 'response.output_audio_transcript.done';\n}\n\n/**\n * Send this event to cancel an in-progress response. The server will respond with\n * a `response.done` event with a status of `response.status=cancelled`. If there\n * is no response to cancel, the server will respond with an error. It's safe to\n * call `response.cancel` even if no response is in progress, an error will be\n * returned the session will remain unaffected.\n */\nexport interface ResponseCancelEvent {\n /**\n * The event type, must be `response.cancel`.\n */\n type: 'response.cancel';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n\n /**\n * A specific response ID to cancel - if not provided, will cancel an in-progress\n * response in the default conversation.\n */\n response_id?: string;\n}\n\n/**\n * Returned when a new content part is added to an assistant message item during\n * response generation.\n */\nexport interface ResponseContentPartAddedEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item to which the content part was added.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The content part that was added.\n */\n part: ResponseContentPartAddedEvent.Part;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.content_part.added`.\n */\n type: 'response.content_part.added';\n}\n\nexport namespace ResponseContentPartAddedEvent {\n /**\n * The content part that was added.\n */\n export interface Part {\n /**\n * Base64-encoded audio data (if type is \"audio\").\n */\n audio?: string;\n\n /**\n * The text content (if type is \"text\").\n */\n text?: string;\n\n /**\n * The transcript of the audio (if type is \"audio\").\n */\n transcript?: string;\n\n /**\n * The content type (\"text\", \"audio\").\n */\n type?: 'text' | 'audio';\n }\n}\n\n/**\n * Returned when a content part is done streaming in an assistant message item.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseContentPartDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The content part that is done.\n */\n part: ResponseContentPartDoneEvent.Part;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.content_part.done`.\n */\n type: 'response.content_part.done';\n}\n\nexport namespace ResponseContentPartDoneEvent {\n /**\n * The content part that is done.\n */\n export interface Part {\n /**\n * Base64-encoded audio data (if type is \"audio\").\n */\n audio?: string;\n\n /**\n * The text content (if type is \"text\").\n */\n text?: string;\n\n /**\n * The transcript of the audio (if type is \"audio\").\n */\n transcript?: string;\n\n /**\n * The content type (\"text\", \"audio\").\n */\n type?: 'text' | 'audio';\n }\n}\n\n/**\n * This event instructs the server to create a Response, which means triggering\n * model inference. When in Server VAD mode, the server will create Responses\n * automatically.\n *\n * A Response will include at least one Item, and may have two, in which case the\n * second will be a function call. These Items will be appended to the conversation\n * history by default.\n *\n * The server will respond with a `response.created` event, events for Items and\n * content created, and finally a `response.done` event to indicate the Response is\n * complete.\n *\n * The `response.create` event includes inference configuration like `instructions`\n * and `tools`. If these are set, they will override the Session's configuration\n * for this Response only.\n *\n * Responses can be created out-of-band of the default Conversation, meaning that\n * they can have arbitrary input, and it's possible to disable writing the output\n * to the Conversation. Only one Response can write to the default Conversation at\n * a time, but otherwise multiple Responses can be created in parallel. The\n * `metadata` field is a good way to disambiguate multiple simultaneous Responses.\n *\n * Clients can set `conversation` to `none` to create a Response that does not\n * write to the default Conversation. Arbitrary input can be provided with the\n * `input` field, which is an array accepting raw Items and references to existing\n * Items.\n */\nexport interface ResponseCreateEvent {\n /**\n * The event type, must be `response.create`.\n */\n type: 'response.create';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n\n /**\n * Create a new Realtime response with these parameters\n */\n response?: RealtimeResponseCreateParams;\n}\n\n/**\n * Returned when a new Response is created. The first event of response creation,\n * where the response is in an initial state of `in_progress`.\n */\nexport interface ResponseCreatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The response resource.\n */\n response: RealtimeResponse;\n\n /**\n * The event type, must be `response.created`.\n */\n type: 'response.created';\n}\n\n/**\n * Returned when a Response is done streaming. Always emitted, no matter the final\n * state. The Response object included in the `response.done` event will include\n * all output Items in the Response but will omit the raw audio data.\n *\n * Clients should check the `status` field of the Response to determine if it was\n * successful (`completed`) or if there was another outcome: `cancelled`, `failed`,\n * or `incomplete`.\n *\n * A response will contain all output items that were generated during the\n * response, excluding any audio content.\n */\nexport interface ResponseDoneEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The response resource.\n */\n response: RealtimeResponse;\n\n /**\n * The event type, must be `response.done`.\n */\n type: 'response.done';\n}\n\n/**\n * Returned when the model-generated function call arguments are updated.\n */\nexport interface ResponseFunctionCallArgumentsDeltaEvent {\n /**\n * The ID of the function call.\n */\n call_id: string;\n\n /**\n * The arguments delta as a JSON string.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the function call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.function_call_arguments.delta`.\n */\n type: 'response.function_call_arguments.delta';\n}\n\n/**\n * Returned when the model-generated function call arguments are done streaming.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseFunctionCallArgumentsDoneEvent {\n /**\n * The final arguments as a JSON string.\n */\n arguments: string;\n\n /**\n * The ID of the function call.\n */\n call_id: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the function call item.\n */\n item_id: string;\n\n /**\n * The name of the function that was called.\n */\n name: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.function_call_arguments.done`.\n */\n type: 'response.function_call_arguments.done';\n}\n\n/**\n * Returned when MCP tool call arguments are updated during response generation.\n */\nexport interface ResponseMcpCallArgumentsDelta {\n /**\n * The JSON-encoded arguments delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.mcp_call_arguments.delta`.\n */\n type: 'response.mcp_call_arguments.delta';\n\n /**\n * If present, indicates the delta text was obfuscated.\n */\n obfuscation?: string | null;\n}\n\n/**\n * Returned when MCP tool call arguments are finalized during response generation.\n */\nexport interface ResponseMcpCallArgumentsDone {\n /**\n * The final JSON-encoded arguments string.\n */\n arguments: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.mcp_call_arguments.done`.\n */\n type: 'response.mcp_call_arguments.done';\n}\n\n/**\n * Returned when an MCP tool call has completed successfully.\n */\nexport interface ResponseMcpCallCompleted {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The event type, must be `response.mcp_call.completed`.\n */\n type: 'response.mcp_call.completed';\n}\n\n/**\n * Returned when an MCP tool call has failed.\n */\nexport interface ResponseMcpCallFailed {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The event type, must be `response.mcp_call.failed`.\n */\n type: 'response.mcp_call.failed';\n}\n\n/**\n * Returned when an MCP tool call has started and is in progress.\n */\nexport interface ResponseMcpCallInProgress {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the MCP tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The event type, must be `response.mcp_call.in_progress`.\n */\n type: 'response.mcp_call.in_progress';\n}\n\n/**\n * Returned when a new Item is created during Response generation.\n */\nexport interface ResponseOutputItemAddedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A single item within a Realtime conversation.\n */\n item: ConversationItem;\n\n /**\n * The index of the output item in the Response.\n */\n output_index: number;\n\n /**\n * The ID of the Response to which the item belongs.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_item.added`.\n */\n type: 'response.output_item.added';\n}\n\n/**\n * Returned when an Item is done streaming. Also emitted when a Response is\n * interrupted, incomplete, or cancelled.\n */\nexport interface ResponseOutputItemDoneEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A single item within a Realtime conversation.\n */\n item: ConversationItem;\n\n /**\n * The index of the output item in the Response.\n */\n output_index: number;\n\n /**\n * The ID of the Response to which the item belongs.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_item.done`.\n */\n type: 'response.output_item.done';\n}\n\n/**\n * Returned when the text value of an \"output_text\" content part is updated.\n */\nexport interface ResponseTextDeltaEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The text delta.\n */\n delta: string;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The event type, must be `response.output_text.delta`.\n */\n type: 'response.output_text.delta';\n}\n\n/**\n * Returned when the text value of an \"output_text\" content part is done streaming.\n * Also emitted when a Response is interrupted, incomplete, or cancelled.\n */\nexport interface ResponseTextDoneEvent {\n /**\n * The index of the content part in the item's content array.\n */\n content_index: number;\n\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response.\n */\n output_index: number;\n\n /**\n * The ID of the response.\n */\n response_id: string;\n\n /**\n * The final text content.\n */\n text: string;\n\n /**\n * The event type, must be `response.output_text.done`.\n */\n type: 'response.output_text.done';\n}\n\n/**\n * Returned when a Session is created. Emitted automatically when a new connection\n * is established as the first server event. This event will contain the default\n * Session configuration.\n */\nexport interface SessionCreatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The session configuration.\n */\n session: RealtimeSessionCreateRequest | RealtimeTranscriptionSessionCreateRequest;\n\n /**\n * The event type, must be `session.created`.\n */\n type: 'session.created';\n}\n\n/**\n * Send this event to update the session’s configuration. The client may send this\n * event at any time to update any field except for `voice` and `model`. `voice`\n * can be updated only if there have been no other audio outputs yet.\n *\n * When the server receives a `session.update`, it will respond with a\n * `session.updated` event showing the full, effective configuration. Only the\n * fields that are present in the `session.update` are updated. To clear a field\n * like `instructions`, pass an empty string. To clear a field like `tools`, pass\n * an empty array. To clear a field like `turn_detection`, pass `null`.\n */\nexport interface SessionUpdateEvent {\n /**\n * Update the Realtime session. Choose either a realtime session or a transcription\n * session.\n */\n session: RealtimeSessionCreateRequest | RealtimeTranscriptionSessionCreateRequest;\n\n /**\n * The event type, must be `session.update`.\n */\n type: 'session.update';\n\n /**\n * Optional client-generated ID used to identify this event. This is an arbitrary\n * string that a client may assign. It will be passed back if there is an error\n * with the event, but the corresponding `session.updated` event will not include\n * it.\n */\n event_id?: string;\n}\n\n/**\n * Returned when a session is updated with a `session.update` event, unless there\n * is an error.\n */\nexport interface SessionUpdatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * The session configuration.\n */\n session: RealtimeSessionCreateRequest | RealtimeTranscriptionSessionCreateRequest;\n\n /**\n * The event type, must be `session.updated`.\n */\n type: 'session.updated';\n}\n\n/**\n * Send this event to update a transcription session.\n */\nexport interface TranscriptionSessionUpdate {\n /**\n * Realtime transcription session object configuration.\n */\n session: TranscriptionSessionUpdate.Session;\n\n /**\n * The event type, must be `transcription_session.update`.\n */\n type: 'transcription_session.update';\n\n /**\n * Optional client-generated ID used to identify this event.\n */\n event_id?: string;\n}\n\nexport namespace TranscriptionSessionUpdate {\n /**\n * Realtime transcription session object configuration.\n */\n export interface Session {\n /**\n * The set of items to include in the transcription. Current available items are:\n * `item.input_audio_transcription.logprobs`\n */\n include?: Array<'item.input_audio_transcription.logprobs'>;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. For\n * `pcm16`, input audio must be 16-bit PCM at a 24kHz sample rate, single channel\n * (mono), and little-endian byte order.\n */\n input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';\n\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n input_audio_noise_reduction?: Session.InputAudioNoiseReduction;\n\n /**\n * Configuration for input audio transcription. The client can optionally set the\n * language and prompt for transcription, these offer additional guidance to the\n * transcription service.\n */\n input_audio_transcription?: RealtimeAPI.AudioTranscription;\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n turn_detection?: Session.TurnDetection;\n }\n\n export namespace Session {\n /**\n * Configuration for input audio noise reduction. This can be set to `null` to turn\n * off. Noise reduction filters audio added to the input audio buffer before it is\n * sent to VAD and the model. Filtering the audio can improve VAD and turn\n * detection accuracy (reducing false positives) and model performance by improving\n * perception of the input audio.\n */\n export interface InputAudioNoiseReduction {\n /**\n * Type of noise reduction. `near_field` is for close-talking microphones such as\n * headphones, `far_field` is for far-field microphones such as laptop or\n * conference room microphones.\n */\n type?: RealtimeAPI.NoiseReductionType;\n }\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n export interface TurnDetection {\n /**\n * Amount of audio to include before the VAD detected speech (in milliseconds).\n * Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n * With shorter values the model will respond more quickly, but may jump in on\n * short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n * threshold will require louder audio to activate the model, and thus might\n * perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection. Only `server_vad` is currently supported for\n * transcription sessions.\n */\n type?: 'server_vad';\n }\n }\n}\n\n/**\n * Returned when a transcription session is updated with a\n * `transcription_session.update` event, unless there is an error.\n */\nexport interface TranscriptionSessionUpdatedEvent {\n /**\n * The unique ID of the server event.\n */\n event_id: string;\n\n /**\n * A new Realtime transcription session configuration.\n *\n * When a session is created on the server via REST API, the session object also\n * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n * not present when a session is updated via the WebSocket API.\n */\n session: TranscriptionSessionUpdatedEvent.Session;\n\n /**\n * The event type, must be `transcription_session.updated`.\n */\n type: 'transcription_session.updated';\n}\n\nexport namespace TranscriptionSessionUpdatedEvent {\n /**\n * A new Realtime transcription session configuration.\n *\n * When a session is created on the server via REST API, the session object also\n * contains an ephemeral key. Default TTL for keys is 10 minutes. This property is\n * not present when a session is updated via the WebSocket API.\n */\n export interface Session {\n /**\n * Ephemeral key returned by the API. Only present when the session is created on\n * the server via REST API.\n */\n client_secret: Session.ClientSecret;\n\n /**\n * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.\n */\n input_audio_format?: string;\n\n /**\n * Configuration of the transcription model.\n */\n input_audio_transcription?: RealtimeAPI.AudioTranscription;\n\n /**\n * The set of modalities the model can respond with. To disable audio, set this to\n * [\"text\"].\n */\n modalities?: Array<'text' | 'audio'>;\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n turn_detection?: Session.TurnDetection;\n }\n\n export namespace Session {\n /**\n * Ephemeral key returned by the API. Only present when the session is created on\n * the server via REST API.\n */\n export interface ClientSecret {\n /**\n * Timestamp for when the token expires. Currently, all tokens expire after one\n * minute.\n */\n expires_at: number;\n\n /**\n * Ephemeral key usable in client environments to authenticate connections to the\n * Realtime API. Use this in client-side environments rather than a standard API\n * token, which should only be used server-side.\n */\n value: string;\n }\n\n /**\n * Configuration for turn detection. Can be set to `null` to turn off. Server VAD\n * means that the model will detect the start and end of speech based on audio\n * volume and respond at the end of user speech.\n */\n export interface TurnDetection {\n /**\n * Amount of audio to include before the VAD detected speech (in milliseconds).\n * Defaults to 300ms.\n */\n prefix_padding_ms?: number;\n\n /**\n * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.\n * With shorter values the model will respond more quickly, but may jump in on\n * short pauses from the user.\n */\n silence_duration_ms?: number;\n\n /**\n * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher\n * threshold will require louder audio to activate the model, and thus might\n * perform better in noisy environments.\n */\n threshold?: number;\n\n /**\n * Type of turn detection, only `server_vad` is currently supported.\n */\n type?: string;\n }\n }\n}\n\nRealtime.ClientSecrets = ClientSecrets;\nRealtime.Calls = Calls;\n\nexport declare namespace Realtime {\n export {\n type AudioTranscription as AudioTranscription,\n type ConversationCreatedEvent as ConversationCreatedEvent,\n type ConversationItem as ConversationItem,\n type ConversationItemAdded as ConversationItemAdded,\n type ConversationItemCreateEvent as ConversationItemCreateEvent,\n type ConversationItemCreatedEvent as ConversationItemCreatedEvent,\n type ConversationItemDeleteEvent as ConversationItemDeleteEvent,\n type ConversationItemDeletedEvent as ConversationItemDeletedEvent,\n type ConversationItemDone as ConversationItemDone,\n type ConversationItemInputAudioTranscriptionCompletedEvent as ConversationItemInputAudioTranscriptionCompletedEvent,\n type ConversationItemInputAudioTranscriptionDeltaEvent as ConversationItemInputAudioTranscriptionDeltaEvent,\n type ConversationItemInputAudioTranscriptionFailedEvent as ConversationItemInputAudioTranscriptionFailedEvent,\n type ConversationItemInputAudioTranscriptionSegment as ConversationItemInputAudioTranscriptionSegment,\n type ConversationItemRetrieveEvent as ConversationItemRetrieveEvent,\n type ConversationItemTruncateEvent as ConversationItemTruncateEvent,\n type ConversationItemTruncatedEvent as ConversationItemTruncatedEvent,\n type ConversationItemWithReference as ConversationItemWithReference,\n type InputAudioBufferAppendEvent as InputAudioBufferAppendEvent,\n type InputAudioBufferClearEvent as InputAudioBufferClearEvent,\n type InputAudioBufferClearedEvent as InputAudioBufferClearedEvent,\n type InputAudioBufferCommitEvent as InputAudioBufferCommitEvent,\n type InputAudioBufferCommittedEvent as InputAudioBufferCommittedEvent,\n type InputAudioBufferDtmfEventReceivedEvent as InputAudioBufferDtmfEventReceivedEvent,\n type InputAudioBufferSpeechStartedEvent as InputAudioBufferSpeechStartedEvent,\n type InputAudioBufferSpeechStoppedEvent as InputAudioBufferSpeechStoppedEvent,\n type InputAudioBufferTimeoutTriggered as InputAudioBufferTimeoutTriggered,\n type LogProbProperties as LogProbProperties,\n type McpListToolsCompleted as McpListToolsCompleted,\n type McpListToolsFailed as McpListToolsFailed,\n type McpListToolsInProgress as McpListToolsInProgress,\n type NoiseReductionType as NoiseReductionType,\n type OutputAudioBufferClearEvent as OutputAudioBufferClearEvent,\n type RateLimitsUpdatedEvent as RateLimitsUpdatedEvent,\n type RealtimeAudioConfig as RealtimeAudioConfig,\n type RealtimeAudioConfigInput as RealtimeAudioConfigInput,\n type RealtimeAudioConfigOutput as RealtimeAudioConfigOutput,\n type RealtimeAudioFormats as RealtimeAudioFormats,\n type RealtimeAudioInputTurnDetection as RealtimeAudioInputTurnDetection,\n type RealtimeClientEvent as RealtimeClientEvent,\n type RealtimeConversationItemAssistantMessage as RealtimeConversationItemAssistantMessage,\n type RealtimeConversationItemFunctionCall as RealtimeConversationItemFunctionCall,\n type RealtimeConversationItemFunctionCallOutput as RealtimeConversationItemFunctionCallOutput,\n type RealtimeConversationItemSystemMessage as RealtimeConversationItemSystemMessage,\n type RealtimeConversationItemUserMessage as RealtimeConversationItemUserMessage,\n type RealtimeError as RealtimeError,\n type RealtimeErrorEvent as RealtimeErrorEvent,\n type RealtimeFunctionTool as RealtimeFunctionTool,\n type RealtimeMcpApprovalRequest as RealtimeMcpApprovalRequest,\n type RealtimeMcpApprovalResponse as RealtimeMcpApprovalResponse,\n type RealtimeMcpListTools as RealtimeMcpListTools,\n type RealtimeMcpProtocolError as RealtimeMcpProtocolError,\n type RealtimeMcpToolCall as RealtimeMcpToolCall,\n type RealtimeMcpToolExecutionError as RealtimeMcpToolExecutionError,\n type RealtimeMcphttpError as RealtimeMcphttpError,\n type RealtimeResponse as RealtimeResponse,\n type RealtimeResponseCreateAudioOutput as RealtimeResponseCreateAudioOutput,\n type RealtimeResponseCreateMcpTool as RealtimeResponseCreateMcpTool,\n type RealtimeResponseCreateParams as RealtimeResponseCreateParams,\n type RealtimeResponseStatus as RealtimeResponseStatus,\n type RealtimeResponseUsage as RealtimeResponseUsage,\n type RealtimeResponseUsageInputTokenDetails as RealtimeResponseUsageInputTokenDetails,\n type RealtimeResponseUsageOutputTokenDetails as RealtimeResponseUsageOutputTokenDetails,\n type RealtimeServerEvent as RealtimeServerEvent,\n type RealtimeSession as RealtimeSession,\n type RealtimeSessionCreateRequest as RealtimeSessionCreateRequest,\n type RealtimeToolChoiceConfig as RealtimeToolChoiceConfig,\n type RealtimeToolsConfig as RealtimeToolsConfig,\n type RealtimeToolsConfigUnion as RealtimeToolsConfigUnion,\n type RealtimeTracingConfig as RealtimeTracingConfig,\n type RealtimeTranscriptionSessionAudio as RealtimeTranscriptionSessionAudio,\n type RealtimeTranscriptionSessionAudioInput as RealtimeTranscriptionSessionAudioInput,\n type RealtimeTranscriptionSessionAudioInputTurnDetection as RealtimeTranscriptionSessionAudioInputTurnDetection,\n type RealtimeTranscriptionSessionCreateRequest as RealtimeTranscriptionSessionCreateRequest,\n type RealtimeTruncation as RealtimeTruncation,\n type RealtimeTruncationRetentionRatio as RealtimeTruncationRetentionRatio,\n type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n type ResponseCancelEvent as ResponseCancelEvent,\n type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n type ResponseCreateEvent as ResponseCreateEvent,\n type ResponseCreatedEvent as ResponseCreatedEvent,\n type ResponseDoneEvent as ResponseDoneEvent,\n type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n type ResponseMcpCallArgumentsDelta as ResponseMcpCallArgumentsDelta,\n type ResponseMcpCallArgumentsDone as ResponseMcpCallArgumentsDone,\n type ResponseMcpCallCompleted as ResponseMcpCallCompleted,\n type ResponseMcpCallFailed as ResponseMcpCallFailed,\n type ResponseMcpCallInProgress as ResponseMcpCallInProgress,\n type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n type ResponseTextDoneEvent as ResponseTextDoneEvent,\n type SessionCreatedEvent as SessionCreatedEvent,\n type SessionUpdateEvent as SessionUpdateEvent,\n type SessionUpdatedEvent as SessionUpdatedEvent,\n type TranscriptionSessionUpdate as TranscriptionSessionUpdate,\n type TranscriptionSessionUpdatedEvent as TranscriptionSessionUpdatedEvent,\n };\n\n export {\n ClientSecrets as ClientSecrets,\n type RealtimeSessionClientSecret as RealtimeSessionClientSecret,\n type RealtimeSessionCreateResponse as RealtimeSessionCreateResponse,\n type RealtimeTranscriptionSessionCreateResponse as RealtimeTranscriptionSessionCreateResponse,\n type RealtimeTranscriptionSessionTurnDetection as RealtimeTranscriptionSessionTurnDetection,\n type ClientSecretCreateResponse as ClientSecretCreateResponse,\n type ClientSecretCreateParams as ClientSecretCreateParams,\n };\n\n export {\n Calls as Calls,\n type CallAcceptParams as CallAcceptParams,\n type CallReferParams as CallReferParams,\n type CallRejectParams as CallRejectParams,\n };\n}\n","import { OpenAIError } from '../error';\nimport type { ChatCompletionTool } from '../resources/chat/completions';\nimport {\n ResponseTextConfig,\n type FunctionTool,\n type ParsedContent,\n type ParsedResponse,\n type ParsedResponseFunctionToolCall,\n type ParsedResponseOutputItem,\n type Response,\n type ResponseCreateParamsBase,\n type ResponseCreateParamsNonStreaming,\n type ResponseFunctionToolCall,\n type Tool,\n} from '../resources/responses/responses';\nimport { type AutoParseableTextFormat, isAutoParsableResponseFormat } from '../lib/parser';\n\nexport type ParseableToolsParams = Array<Tool> | ChatCompletionTool | null;\n\nexport type ResponseCreateParamsWithTools = ResponseCreateParamsBase & {\n tools?: ParseableToolsParams;\n};\n\ntype TextConfigParams = { text?: ResponseTextConfig };\n\nexport type ExtractParsedContentFromParams<Params extends TextConfigParams> =\n NonNullable<Params['text']>['format'] extends AutoParseableTextFormat<infer P> ? P : null;\n\nexport function maybeParseResponse<\n Params extends ResponseCreateParamsBase | null,\n ParsedT = Params extends null ? null : ExtractParsedContentFromParams<NonNullable<Params>>,\n>(response: Response, params: Params): ParsedResponse<ParsedT> {\n if (!params || !hasAutoParseableInput(params)) {\n return {\n ...response,\n output_parsed: null,\n output: response.output.map((item) => {\n if (item.type === 'function_call') {\n return {\n ...item,\n parsed_arguments: null,\n };\n }\n\n if (item.type === 'message') {\n return {\n ...item,\n content: item.content.map((content) => ({\n ...content,\n parsed: null,\n })),\n };\n } else {\n return item;\n }\n }),\n };\n }\n\n return parseResponse(response, params);\n}\n\nexport function parseResponse<\n Params extends ResponseCreateParamsBase,\n ParsedT = ExtractParsedContentFromParams<Params>,\n>(response: Response, params: Params): ParsedResponse<ParsedT> {\n const output: Array<ParsedResponseOutputItem<ParsedT>> = response.output.map(\n (item): ParsedResponseOutputItem<ParsedT> => {\n if (item.type === 'function_call') {\n return {\n ...item,\n parsed_arguments: parseToolCall(params, item),\n };\n }\n if (item.type === 'message') {\n const content: Array<ParsedContent<ParsedT>> = item.content.map((content) => {\n if (content.type === 'output_text') {\n return {\n ...content,\n parsed: parseTextFormat(params, content.text),\n };\n }\n\n return content;\n });\n\n return {\n ...item,\n content,\n };\n }\n\n return item;\n },\n );\n\n const parsed: Omit<ParsedResponse<ParsedT>, 'output_parsed'> = Object.assign({}, response, { output });\n if (!Object.getOwnPropertyDescriptor(response, 'output_text')) {\n addOutputText(parsed);\n }\n\n Object.defineProperty(parsed, 'output_parsed', {\n enumerable: true,\n get() {\n for (const output of parsed.output) {\n if (output.type !== 'message') {\n continue;\n }\n\n for (const content of output.content) {\n if (content.type === 'output_text' && content.parsed !== null) {\n return content.parsed;\n }\n }\n }\n\n return null;\n },\n });\n\n return parsed as ParsedResponse<ParsedT>;\n}\n\nfunction parseTextFormat<\n Params extends ResponseCreateParamsBase,\n ParsedT = ExtractParsedContentFromParams<Params>,\n>(params: Params, content: string): ParsedT | null {\n if (params.text?.format?.type !== 'json_schema') {\n return null;\n }\n\n if ('$parseRaw' in params.text?.format) {\n const text_format = params.text?.format as unknown as AutoParseableTextFormat<ParsedT>;\n return text_format.$parseRaw(content);\n }\n\n return JSON.parse(content);\n}\n\nexport function hasAutoParseableInput(params: ResponseCreateParamsWithTools): boolean {\n if (isAutoParsableResponseFormat(params.text?.format)) {\n return true;\n }\n\n return false;\n}\n\ntype ToolOptions = {\n name: string;\n arguments: any;\n function?: ((args: any) => any) | undefined;\n};\n\nexport type AutoParseableResponseTool<\n OptionsT extends ToolOptions,\n HasFunction = OptionsT['function'] extends Function ? true : false,\n> = FunctionTool & {\n __arguments: OptionsT['arguments']; // type-level only\n __name: OptionsT['name']; // type-level only\n\n $brand: 'auto-parseable-tool';\n $callback: ((args: OptionsT['arguments']) => any) | undefined;\n $parseRaw(args: string): OptionsT['arguments'];\n};\n\nexport function makeParseableResponseTool<OptionsT extends ToolOptions>(\n tool: FunctionTool,\n {\n parser,\n callback,\n }: {\n parser: (content: string) => OptionsT['arguments'];\n callback: ((args: any) => any) | undefined;\n },\n): AutoParseableResponseTool<OptionsT['arguments']> {\n const obj = { ...tool };\n\n Object.defineProperties(obj, {\n $brand: {\n value: 'auto-parseable-tool',\n enumerable: false,\n },\n $parseRaw: {\n value: parser,\n enumerable: false,\n },\n $callback: {\n value: callback,\n enumerable: false,\n },\n });\n\n return obj as AutoParseableResponseTool<OptionsT['arguments']>;\n}\n\nexport function isAutoParsableTool(tool: any): tool is AutoParseableResponseTool<any> {\n return tool?.['$brand'] === 'auto-parseable-tool';\n}\n\nfunction getInputToolByName(input_tools: Array<Tool>, name: string): FunctionTool | undefined {\n return input_tools.find((tool) => tool.type === 'function' && tool.name === name) as\n | FunctionTool\n | undefined;\n}\n\nfunction parseToolCall<Params extends ResponseCreateParamsBase>(\n params: Params,\n toolCall: ResponseFunctionToolCall,\n): ParsedResponseFunctionToolCall {\n const inputTool = getInputToolByName(params.tools ?? [], toolCall.name);\n\n return {\n ...toolCall,\n ...toolCall,\n parsed_arguments:\n isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.arguments)\n : inputTool?.strict ? JSON.parse(toolCall.arguments)\n : null,\n };\n}\n\nexport function shouldParseToolCall(\n params: ResponseCreateParamsNonStreaming | null | undefined,\n toolCall: ResponseFunctionToolCall,\n): boolean {\n if (!params) {\n return false;\n }\n\n const inputTool = getInputToolByName(params.tools ?? [], toolCall.name);\n return isAutoParsableTool(inputTool) || inputTool?.strict || false;\n}\n\nexport function validateInputTools(tools: ChatCompletionTool[] | undefined) {\n for (const tool of tools ?? []) {\n if (tool.type !== 'function') {\n throw new OpenAIError(\n `Currently only \\`function\\` tool types support auto-parsing; Received \\`${tool.type}\\``,\n );\n }\n\n if (tool.function.strict !== true) {\n throw new OpenAIError(\n `The \\`${tool.function.name}\\` tool is not marked with \\`strict: true\\`. Only strict function tools can be auto-parsed`,\n );\n }\n }\n}\n\nexport function addOutputText(rsp: Response): void {\n const texts: string[] = [];\n for (const output of rsp.output) {\n if (output.type !== 'message') {\n continue;\n }\n\n for (const content of output.content) {\n if (content.type === 'output_text') {\n texts.push(content.text);\n }\n }\n }\n\n rsp.output_text = texts.join('');\n}\n","import {\n ResponseTextConfig,\n type ParsedResponse,\n type Response,\n type ResponseCreateParamsBase,\n type ResponseCreateParamsStreaming,\n type ResponseStreamEvent,\n} from '../../resources/responses/responses';\nimport { RequestOptions } from '../../internal/request-options';\nimport { APIUserAbortError, OpenAIError } from '../../error';\nimport OpenAI from '../../index';\nimport { type BaseEvents, EventStream } from '../EventStream';\nimport { type ResponseFunctionCallArgumentsDeltaEvent, type ResponseTextDeltaEvent } from './EventTypes';\nimport { maybeParseResponse, ParseableToolsParams } from '../ResponsesParser';\nimport { Stream } from '../../streaming';\n\nexport type ResponseStreamParams = ResponseCreateAndStreamParams | ResponseStreamByIdParams;\n\nexport type ResponseCreateAndStreamParams = Omit<ResponseCreateParamsBase, 'stream'> & {\n stream?: true;\n};\n\nexport type ResponseStreamByIdParams = {\n /**\n * The ID of the response to stream.\n */\n response_id: string;\n /**\n * If provided, the stream will start after the event with the given sequence number.\n */\n starting_after?: number;\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: ResponseTextConfig;\n\n /**\n * An array of tools the model may call while generating a response. When continuing a stream, provide\n * the same tools as the original request.\n */\n tools?: ParseableToolsParams;\n};\n\ntype ResponseEvents = BaseEvents &\n Omit<\n {\n [K in ResponseStreamEvent['type']]: (event: Extract<ResponseStreamEvent, { type: K }>) => void;\n },\n 'response.output_text.delta' | 'response.function_call_arguments.delta'\n > & {\n event: (event: ResponseStreamEvent) => void;\n 'response.output_text.delta': (event: ResponseTextDeltaEvent) => void;\n 'response.function_call_arguments.delta': (event: ResponseFunctionCallArgumentsDeltaEvent) => void;\n };\n\nexport type ResponseStreamingParams = Omit<ResponseCreateParamsBase, 'stream'> & {\n stream?: true;\n};\n\nexport class ResponseStream<ParsedT = null>\n extends EventStream<ResponseEvents>\n implements AsyncIterable<ResponseStreamEvent>\n{\n #params: ResponseStreamingParams | null;\n #currentResponseSnapshot: Response | undefined;\n #finalResponse: ParsedResponse<ParsedT> | undefined;\n\n constructor(params: ResponseStreamingParams | null) {\n super();\n this.#params = params;\n }\n\n static createResponse<ParsedT>(\n client: OpenAI,\n params: ResponseStreamParams,\n options?: RequestOptions,\n ): ResponseStream<ParsedT> {\n const runner = new ResponseStream<ParsedT>(params as ResponseCreateParamsStreaming);\n runner._run(() =>\n runner._createOrRetrieveResponse(client, params, {\n ...options,\n headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },\n }),\n );\n return runner;\n }\n\n #beginRequest() {\n if (this.ended) return;\n this.#currentResponseSnapshot = undefined;\n }\n\n #addEvent(this: ResponseStream<ParsedT>, event: ResponseStreamEvent, starting_after: number | null) {\n if (this.ended) return;\n\n const maybeEmit = (name: string, event: ResponseStreamEvent & { snapshot?: string }) => {\n if (starting_after == null || event.sequence_number > starting_after) {\n this._emit(name as any, event);\n }\n };\n\n const response = this.#accumulateResponse(event);\n maybeEmit('event', event);\n\n switch (event.type) {\n case 'response.output_text.delta': {\n const output = response.output[event.output_index];\n if (!output) {\n throw new OpenAIError(`missing output at index ${event.output_index}`);\n }\n if (output.type === 'message') {\n const content = output.content[event.content_index];\n if (!content) {\n throw new OpenAIError(`missing content at index ${event.content_index}`);\n }\n if (content.type !== 'output_text') {\n throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);\n }\n\n maybeEmit('response.output_text.delta', {\n ...event,\n snapshot: content.text,\n });\n }\n break;\n }\n case 'response.function_call_arguments.delta': {\n const output = response.output[event.output_index];\n if (!output) {\n throw new OpenAIError(`missing output at index ${event.output_index}`);\n }\n if (output.type === 'function_call') {\n maybeEmit('response.function_call_arguments.delta', {\n ...event,\n snapshot: output.arguments,\n });\n }\n break;\n }\n default:\n maybeEmit(event.type, event);\n break;\n }\n }\n\n #endRequest(): ParsedResponse<ParsedT> {\n if (this.ended) {\n throw new OpenAIError(`stream has ended, this shouldn't happen`);\n }\n const snapshot = this.#currentResponseSnapshot;\n if (!snapshot) {\n throw new OpenAIError(`request ended without sending any events`);\n }\n this.#currentResponseSnapshot = undefined;\n const parsedResponse = finalizeResponse<ParsedT>(snapshot, this.#params);\n this.#finalResponse = parsedResponse;\n\n return parsedResponse;\n }\n\n protected async _createOrRetrieveResponse(\n client: OpenAI,\n params: ResponseStreamParams,\n options?: RequestOptions,\n ): Promise<ParsedResponse<ParsedT>> {\n const signal = options?.signal;\n if (signal) {\n if (signal.aborted) this.controller.abort();\n signal.addEventListener('abort', () => this.controller.abort());\n }\n this.#beginRequest();\n\n let stream: Stream<ResponseStreamEvent> | undefined;\n let starting_after: number | null = null;\n if ('response_id' in params) {\n stream = await client.responses.retrieve(\n params.response_id,\n { stream: true },\n { ...options, signal: this.controller.signal, stream: true },\n );\n starting_after = params.starting_after ?? null;\n } else {\n stream = await client.responses.create(\n { ...params, stream: true },\n { ...options, signal: this.controller.signal },\n );\n }\n\n this._connected();\n for await (const event of stream) {\n this.#addEvent(event, starting_after);\n }\n if (stream.controller.signal?.aborted) {\n throw new APIUserAbortError();\n }\n return this.#endRequest();\n }\n\n #accumulateResponse(event: ResponseStreamEvent): Response {\n let snapshot = this.#currentResponseSnapshot;\n if (!snapshot) {\n if (event.type !== 'response.created') {\n throw new OpenAIError(\n `When snapshot hasn't been set yet, expected 'response.created' event, got ${event.type}`,\n );\n }\n snapshot = this.#currentResponseSnapshot = event.response;\n return snapshot;\n }\n\n switch (event.type) {\n case 'response.output_item.added': {\n snapshot.output.push(event.item);\n break;\n }\n case 'response.content_part.added': {\n const output = snapshot.output[event.output_index];\n if (!output) {\n throw new OpenAIError(`missing output at index ${event.output_index}`);\n }\n const type = output.type;\n const part = event.part;\n if (type === 'message' && part.type !== 'reasoning_text') {\n output.content.push(part);\n } else if (type === 'reasoning' && part.type === 'reasoning_text') {\n if (!output.content) {\n output.content = [];\n }\n output.content.push(part);\n }\n break;\n }\n case 'response.output_text.delta': {\n const output = snapshot.output[event.output_index];\n if (!output) {\n throw new OpenAIError(`missing output at index ${event.output_index}`);\n }\n if (output.type === 'message') {\n const content = output.content[event.content_index];\n if (!content) {\n throw new OpenAIError(`missing content at index ${event.content_index}`);\n }\n if (content.type !== 'output_text') {\n throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);\n }\n content.text += event.delta;\n }\n break;\n }\n case 'response.function_call_arguments.delta': {\n const output = snapshot.output[event.output_index];\n if (!output) {\n throw new OpenAIError(`missing output at index ${event.output_index}`);\n }\n if (output.type === 'function_call') {\n output.arguments += event.delta;\n }\n break;\n }\n case 'response.reasoning_text.delta': {\n const output = snapshot.output[event.output_index];\n if (!output) {\n throw new OpenAIError(`missing output at index ${event.output_index}`);\n }\n if (output.type === 'reasoning') {\n const content = output.content?.[event.content_index];\n if (!content) {\n throw new OpenAIError(`missing content at index ${event.content_index}`);\n }\n if (content.type !== 'reasoning_text') {\n throw new OpenAIError(`expected content to be 'reasoning_text', got ${content.type}`);\n }\n content.text += event.delta;\n }\n break;\n }\n case 'response.completed': {\n this.#currentResponseSnapshot = event.response;\n break;\n }\n }\n\n return snapshot;\n }\n\n [Symbol.asyncIterator](this: ResponseStream<ParsedT>): AsyncIterator<ResponseStreamEvent> {\n const pushQueue: ResponseStreamEvent[] = [];\n const readQueue: {\n resolve: (event: ResponseStreamEvent | undefined) => void;\n reject: (err: unknown) => void;\n }[] = [];\n let done = false;\n\n this.on('event', (event) => {\n const reader = readQueue.shift();\n if (reader) {\n reader.resolve(event);\n } else {\n pushQueue.push(event);\n }\n });\n\n this.on('end', () => {\n done = true;\n for (const reader of readQueue) {\n reader.resolve(undefined);\n }\n readQueue.length = 0;\n });\n\n this.on('abort', (err) => {\n done = true;\n for (const reader of readQueue) {\n reader.reject(err);\n }\n readQueue.length = 0;\n });\n\n this.on('error', (err) => {\n done = true;\n for (const reader of readQueue) {\n reader.reject(err);\n }\n readQueue.length = 0;\n });\n\n return {\n next: async (): Promise<IteratorResult<ResponseStreamEvent>> => {\n if (!pushQueue.length) {\n if (done) {\n return { value: undefined, done: true };\n }\n return new Promise<ResponseStreamEvent | undefined>((resolve, reject) =>\n readQueue.push({ resolve, reject }),\n ).then((event) => (event ? { value: event, done: false } : { value: undefined, done: true }));\n }\n const event = pushQueue.shift()!;\n return { value: event, done: false };\n },\n return: async () => {\n this.abort();\n return { value: undefined, done: true };\n },\n };\n }\n\n /**\n * @returns a promise that resolves with the final Response, or rejects\n * if an error occurred or the stream ended prematurely without producing a REsponse.\n */\n async finalResponse(): Promise<ParsedResponse<ParsedT>> {\n await this.done();\n const response = this.#finalResponse;\n if (!response) throw new OpenAIError('stream ended without producing a ChatCompletion');\n return response;\n }\n}\n\nfunction finalizeResponse<ParsedT>(\n snapshot: Response,\n params: ResponseStreamingParams | null,\n): ParsedResponse<ParsedT> {\n return maybeParseResponse(snapshot, params);\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ResponsesAPI from './responses';\nimport { ResponseItemsPage } from './responses';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class InputItems extends APIResource {\n /**\n * Returns a list of input items for a given response.\n *\n * @example\n * ```ts\n * // Automatically fetches more pages as needed.\n * for await (const responseItem of client.responses.inputItems.list(\n * 'response_id',\n * )) {\n * // ...\n * }\n * ```\n */\n list(\n responseID: string,\n query: InputItemListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<ResponseItemsPage, ResponsesAPI.ResponseItem> {\n return this._client.getAPIList(\n path`/responses/${responseID}/input_items`,\n CursorPage<ResponsesAPI.ResponseItem>,\n { query, ...options },\n );\n }\n}\n\n/**\n * A list of Response items.\n */\nexport interface ResponseItemList {\n /**\n * A list of items used to generate this response.\n */\n data: Array<ResponsesAPI.ResponseItem>;\n\n /**\n * The ID of the first item in the list.\n */\n first_id: string;\n\n /**\n * Whether there are more items available.\n */\n has_more: boolean;\n\n /**\n * The ID of the last item in the list.\n */\n last_id: string;\n\n /**\n * The type of object returned, must be `list`.\n */\n object: 'list';\n}\n\nexport interface InputItemListParams extends CursorPageParams {\n /**\n * Additional fields to include in the response. See the `include` parameter for\n * Response creation above for more information.\n */\n include?: Array<ResponsesAPI.ResponseIncludable>;\n\n /**\n * The order to return the input items in. Default is `desc`.\n *\n * - `asc`: Return the input items in ascending order.\n * - `desc`: Return the input items in descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport declare namespace InputItems {\n export { type ResponseItemList as ResponseItemList, type InputItemListParams as InputItemListParams };\n}\n\nexport { type ResponseItemsPage };\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as ResponsesAPI from './responses';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\n\nexport class InputTokens extends APIResource {\n /**\n * Returns input token counts of the request.\n *\n * Returns an object with `object` set to `response.input_tokens` and an\n * `input_tokens` count.\n *\n * @example\n * ```ts\n * const response = await client.responses.inputTokens.count();\n * ```\n */\n count(\n body: InputTokenCountParams | null | undefined = {},\n options?: RequestOptions,\n ): APIPromise<InputTokenCountResponse> {\n return this._client.post('/responses/input_tokens', { body, ...options });\n }\n}\n\nexport interface InputTokenCountResponse {\n input_tokens: number;\n\n object: 'response.input_tokens';\n}\n\nexport interface InputTokenCountParams {\n /**\n * The conversation that this response belongs to. Items from this conversation are\n * prepended to `input_items` for this response request. Input items and output\n * items from this response are automatically added to this conversation after this\n * response completes.\n */\n conversation?: string | ResponsesAPI.ResponseConversationParam | null;\n\n /**\n * Text, image, or file inputs to the model, used to generate a response\n */\n input?: string | Array<ResponsesAPI.ResponseInputItem> | null;\n\n /**\n * A system (or developer) message inserted into the model's context. When used\n * along with `previous_response_id`, the instructions from a previous response\n * will not be carried over to the next response. This makes it simple to swap out\n * system (or developer) messages in new responses.\n */\n instructions?: string | null;\n\n /**\n * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model?: string | null;\n\n /**\n * Whether to allow the model to run tool calls in parallel.\n */\n parallel_tool_calls?: boolean | null;\n\n /**\n * The unique ID of the previous response to the model. Use this to create\n * multi-turn conversations. Learn more about\n * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n * Cannot be used in conjunction with `conversation`.\n */\n previous_response_id?: string | null;\n\n /**\n * **gpt-5 and o-series models only** Configuration options for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n */\n reasoning?: Shared.Reasoning | null;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: InputTokenCountParams.Text | null;\n\n /**\n * Controls which tool the model should use, if any.\n */\n tool_choice?:\n | ResponsesAPI.ToolChoiceOptions\n | ResponsesAPI.ToolChoiceAllowed\n | ResponsesAPI.ToolChoiceTypes\n | ResponsesAPI.ToolChoiceFunction\n | ResponsesAPI.ToolChoiceMcp\n | ResponsesAPI.ToolChoiceCustom\n | ResponsesAPI.ToolChoiceApplyPatch\n | ResponsesAPI.ToolChoiceShell\n | null;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n */\n tools?: Array<ResponsesAPI.Tool> | null;\n\n /**\n * The truncation strategy to use for the model response. - `auto`: If the input to\n * this Response exceeds the model's context window size, the model will truncate\n * the response to fit the context window by dropping items from the beginning of\n * the conversation. - `disabled` (default): If the input size will exceed the\n * context window size for a model, the request will fail with a 400 error.\n */\n truncation?: 'auto' | 'disabled';\n}\n\nexport namespace InputTokenCountParams {\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n export interface Text {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponsesAPI.ResponseFormatTextConfig;\n\n /**\n * Constrains the verbosity of the model's response. Lower values will result in\n * more concise responses, while higher values will result in more verbose\n * responses. Currently supported values are `low`, `medium`, and `high`.\n */\n verbosity?: 'low' | 'medium' | 'high' | null;\n }\n}\n\nexport declare namespace InputTokens {\n export {\n type InputTokenCountResponse as InputTokenCountResponse,\n type InputTokenCountParams as InputTokenCountParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport {\n type ExtractParsedContentFromParams,\n parseResponse,\n type ResponseCreateParamsWithTools,\n addOutputText,\n} from '../../lib/ResponsesParser';\nimport { ResponseStream, ResponseStreamParams } from '../../lib/responses/ResponseStream';\nimport { APIResource } from '../../core/resource';\nimport * as ResponsesAPI from './responses';\nimport * as Shared from '../shared';\nimport * as InputItemsAPI from './input-items';\nimport { InputItemListParams, InputItems, ResponseItemList } from './input-items';\nimport * as InputTokensAPI from './input-tokens';\nimport { InputTokenCountParams, InputTokenCountResponse, InputTokens } from './input-tokens';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage } from '../../core/pagination';\nimport { Stream } from '../../core/streaming';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport interface ParsedResponseOutputText<ParsedT> extends ResponseOutputText {\n parsed: ParsedT | null;\n}\n\nexport type ParsedContent<ParsedT> = ParsedResponseOutputText<ParsedT> | ResponseOutputRefusal;\n\nexport interface ParsedResponseOutputMessage<ParsedT> extends ResponseOutputMessage {\n content: ParsedContent<ParsedT>[];\n}\n\nexport interface ParsedResponseFunctionToolCall extends ResponseFunctionToolCall {\n parsed_arguments: any;\n}\n\nexport type ParsedResponseOutputItem<ParsedT> =\n | ParsedResponseOutputMessage<ParsedT>\n | ParsedResponseFunctionToolCall\n | ResponseFileSearchToolCall\n | ResponseFunctionWebSearch\n | ResponseComputerToolCall\n | ResponseToolSearchCall\n | ResponseToolSearchOutputItem\n | ResponseReasoningItem\n | ResponseCompactionItem\n | ResponseOutputItem.ImageGenerationCall\n | ResponseCodeInterpreterToolCall\n | ResponseOutputItem.LocalShellCall\n | ResponseFunctionShellToolCall\n | ResponseFunctionShellToolCallOutput\n | ResponseApplyPatchToolCall\n | ResponseApplyPatchToolCallOutput\n | ResponseOutputItem.McpCall\n | ResponseOutputItem.McpListTools\n | ResponseOutputItem.McpApprovalRequest\n | ResponseCustomToolCall;\n\nexport interface ParsedResponse<ParsedT> extends Response {\n output: Array<ParsedResponseOutputItem<ParsedT>>;\n\n output_parsed: ParsedT | null;\n}\n\nexport type ResponseParseParams = ResponseCreateParamsNonStreaming;\n\nexport class Responses extends APIResource {\n inputItems: InputItemsAPI.InputItems = new InputItemsAPI.InputItems(this._client);\n inputTokens: InputTokensAPI.InputTokens = new InputTokensAPI.InputTokens(this._client);\n\n /**\n * Creates a model response. Provide\n * [text](https://platform.openai.com/docs/guides/text) or\n * [image](https://platform.openai.com/docs/guides/images) inputs to generate\n * [text](https://platform.openai.com/docs/guides/text) or\n * [JSON](https://platform.openai.com/docs/guides/structured-outputs) outputs. Have\n * the model call your own\n * [custom code](https://platform.openai.com/docs/guides/function-calling) or use\n * built-in [tools](https://platform.openai.com/docs/guides/tools) like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search) to use\n * your own data as input for the model's response.\n *\n * @example\n * ```ts\n * const response = await client.responses.create();\n * ```\n */\n create(body: ResponseCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Response>;\n create(\n body: ResponseCreateParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<ResponseStreamEvent>>;\n create(\n body: ResponseCreateParamsBase,\n options?: RequestOptions,\n ): APIPromise<Stream<ResponseStreamEvent> | Response>;\n create(\n body: ResponseCreateParams,\n options?: RequestOptions,\n ): APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>> {\n return (\n this._client.post('/responses', { body, ...options, stream: body.stream ?? false }) as\n | APIPromise<Response>\n | APIPromise<Stream<ResponseStreamEvent>>\n )._thenUnwrap((rsp) => {\n if ('object' in rsp && rsp.object === 'response') {\n addOutputText(rsp as Response);\n }\n\n return rsp;\n }) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>;\n }\n\n /**\n * Retrieves a model response with the given ID.\n *\n * @example\n * ```ts\n * const response = await client.responses.retrieve(\n * 'resp_677efb5139a88190b512bc3fef8e535d',\n * );\n * ```\n */\n retrieve(\n responseID: string,\n query?: ResponseRetrieveParamsNonStreaming,\n options?: RequestOptions,\n ): APIPromise<Response>;\n retrieve(\n responseID: string,\n query: ResponseRetrieveParamsStreaming,\n options?: RequestOptions,\n ): APIPromise<Stream<ResponseStreamEvent>>;\n retrieve(\n responseID: string,\n query?: ResponseRetrieveParamsBase | undefined,\n options?: RequestOptions,\n ): APIPromise<Stream<ResponseStreamEvent> | Response>;\n retrieve(\n responseID: string,\n query: ResponseRetrieveParams | undefined = {},\n options?: RequestOptions,\n ): APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>> {\n return (\n this._client.get(path`/responses/${responseID}`, {\n query,\n ...options,\n stream: query?.stream ?? false,\n }) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>\n )._thenUnwrap((rsp) => {\n if ('object' in rsp && rsp.object === 'response') {\n addOutputText(rsp as Response);\n }\n\n return rsp;\n }) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>;\n }\n\n /**\n * Deletes a model response with the given ID.\n *\n * @example\n * ```ts\n * await client.responses.delete(\n * 'resp_677efb5139a88190b512bc3fef8e535d',\n * );\n * ```\n */\n delete(responseID: string, options?: RequestOptions): APIPromise<void> {\n return this._client.delete(path`/responses/${responseID}`, {\n ...options,\n headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),\n });\n }\n\n parse<Params extends ResponseCreateParamsWithTools, ParsedT = ExtractParsedContentFromParams<Params>>(\n body: Params,\n options?: RequestOptions,\n ): APIPromise<ParsedResponse<ParsedT>> {\n return this._client.responses\n .create(body, options)\n ._thenUnwrap((response) => parseResponse(response as Response, body));\n }\n\n /**\n * Creates a model response stream\n */\n stream<Params extends ResponseStreamParams, ParsedT = ExtractParsedContentFromParams<Params>>(\n body: Params,\n options?: RequestOptions,\n ): ResponseStream<ParsedT> {\n return ResponseStream.createResponse<ParsedT>(this._client, body, options);\n }\n\n /**\n * Cancels a model response with the given ID. Only responses created with the\n * `background` parameter set to `true` can be cancelled.\n * [Learn more](https://platform.openai.com/docs/guides/background).\n *\n * @example\n * ```ts\n * const response = await client.responses.cancel(\n * 'resp_677efb5139a88190b512bc3fef8e535d',\n * );\n * ```\n */\n cancel(responseID: string, options?: RequestOptions): APIPromise<Response> {\n return this._client.post(path`/responses/${responseID}/cancel`, options);\n }\n\n /**\n * Compact a conversation. Returns a compacted response object.\n *\n * Learn when and how to compact long-running conversations in the\n * [conversation state guide](https://platform.openai.com/docs/guides/conversation-state#managing-the-context-window).\n * For ZDR-compatible compaction details, see\n * [Compaction (advanced)](https://platform.openai.com/docs/guides/conversation-state#compaction-advanced).\n *\n * @example\n * ```ts\n * const compactedResponse = await client.responses.compact({\n * model: 'gpt-5.4',\n * });\n * ```\n */\n compact(body: ResponseCompactParams, options?: RequestOptions): APIPromise<CompactedResponse> {\n return this._client.post('/responses/compact', { body, ...options });\n }\n}\n\nexport type ResponseItemsPage = CursorPage<ResponseItem>;\n\n/**\n * Allows the assistant to create, delete, or update files using unified diffs.\n */\nexport interface ApplyPatchTool {\n /**\n * The type of the tool. Always `apply_patch`.\n */\n type: 'apply_patch';\n}\n\nexport interface CompactedResponse {\n /**\n * The unique identifier for the compacted response.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) when the compacted conversation was created.\n */\n created_at: number;\n\n /**\n * The object type. Always `response.compaction`.\n */\n object: 'response.compaction';\n\n /**\n * The compacted list of output items. This is a list of all user messages,\n * followed by a single compaction item.\n */\n output: Array<ResponseOutputItem>;\n\n /**\n * Token accounting for the compaction pass, including cached, reasoning, and total\n * tokens.\n */\n usage: ResponseUsage;\n}\n\n/**\n * A click action.\n */\nexport type ComputerAction =\n | ComputerAction.Click\n | ComputerAction.DoubleClick\n | ComputerAction.Drag\n | ComputerAction.Keypress\n | ComputerAction.Move\n | ComputerAction.Screenshot\n | ComputerAction.Scroll\n | ComputerAction.Type\n | ComputerAction.Wait;\n\nexport namespace ComputerAction {\n /**\n * A click action.\n */\n export interface Click {\n /**\n * Indicates which mouse button was pressed during the click. One of `left`,\n * `right`, `wheel`, `back`, or `forward`.\n */\n button: 'left' | 'right' | 'wheel' | 'back' | 'forward';\n\n /**\n * Specifies the event type. For a click action, this property is always `click`.\n */\n type: 'click';\n\n /**\n * The x-coordinate where the click occurred.\n */\n x: number;\n\n /**\n * The y-coordinate where the click occurred.\n */\n y: number;\n }\n\n /**\n * A double click action.\n */\n export interface DoubleClick {\n /**\n * Specifies the event type. For a double click action, this property is always set\n * to `double_click`.\n */\n type: 'double_click';\n\n /**\n * The x-coordinate where the double click occurred.\n */\n x: number;\n\n /**\n * The y-coordinate where the double click occurred.\n */\n y: number;\n }\n\n /**\n * A drag action.\n */\n export interface Drag {\n /**\n * An array of coordinates representing the path of the drag action. Coordinates\n * will appear as an array of objects, eg\n *\n * ```\n * [\n * { x: 100, y: 200 },\n * { x: 200, y: 300 }\n * ]\n * ```\n */\n path: Array<Drag.Path>;\n\n /**\n * Specifies the event type. For a drag action, this property is always set to\n * `drag`.\n */\n type: 'drag';\n }\n\n export namespace Drag {\n /**\n * An x/y coordinate pair, e.g. `{ x: 100, y: 200 }`.\n */\n export interface Path {\n /**\n * The x-coordinate.\n */\n x: number;\n\n /**\n * The y-coordinate.\n */\n y: number;\n }\n }\n\n /**\n * A collection of keypresses the model would like to perform.\n */\n export interface Keypress {\n /**\n * The combination of keys the model is requesting to be pressed. This is an array\n * of strings, each representing a key.\n */\n keys: Array<string>;\n\n /**\n * Specifies the event type. For a keypress action, this property is always set to\n * `keypress`.\n */\n type: 'keypress';\n }\n\n /**\n * A mouse move action.\n */\n export interface Move {\n /**\n * Specifies the event type. For a move action, this property is always set to\n * `move`.\n */\n type: 'move';\n\n /**\n * The x-coordinate to move to.\n */\n x: number;\n\n /**\n * The y-coordinate to move to.\n */\n y: number;\n }\n\n /**\n * A screenshot action.\n */\n export interface Screenshot {\n /**\n * Specifies the event type. For a screenshot action, this property is always set\n * to `screenshot`.\n */\n type: 'screenshot';\n }\n\n /**\n * A scroll action.\n */\n export interface Scroll {\n /**\n * The horizontal scroll distance.\n */\n scroll_x: number;\n\n /**\n * The vertical scroll distance.\n */\n scroll_y: number;\n\n /**\n * Specifies the event type. For a scroll action, this property is always set to\n * `scroll`.\n */\n type: 'scroll';\n\n /**\n * The x-coordinate where the scroll occurred.\n */\n x: number;\n\n /**\n * The y-coordinate where the scroll occurred.\n */\n y: number;\n }\n\n /**\n * An action to type in text.\n */\n export interface Type {\n /**\n * The text to type.\n */\n text: string;\n\n /**\n * Specifies the event type. For a type action, this property is always set to\n * `type`.\n */\n type: 'type';\n }\n\n /**\n * A wait action.\n */\n export interface Wait {\n /**\n * Specifies the event type. For a wait action, this property is always set to\n * `wait`.\n */\n type: 'wait';\n }\n}\n\n/**\n * Flattened batched actions for `computer_use`. Each action includes an `type`\n * discriminator and action-specific fields.\n */\nexport type ComputerActionList = Array<ComputerAction>;\n\n/**\n * A tool that controls a virtual computer. Learn more about the\n * [computer tool](https://platform.openai.com/docs/guides/tools-computer-use).\n */\nexport interface ComputerTool {\n /**\n * The type of the computer tool. Always `computer`.\n */\n type: 'computer';\n}\n\n/**\n * A tool that controls a virtual computer. Learn more about the\n * [computer tool](https://platform.openai.com/docs/guides/tools-computer-use).\n */\nexport interface ComputerUsePreviewTool {\n /**\n * The height of the computer display.\n */\n display_height: number;\n\n /**\n * The width of the computer display.\n */\n display_width: number;\n\n /**\n * The type of computer environment to control.\n */\n environment: 'windows' | 'mac' | 'linux' | 'ubuntu' | 'browser';\n\n /**\n * The type of the computer use tool. Always `computer_use_preview`.\n */\n type: 'computer_use_preview';\n}\n\nexport interface ContainerAuto {\n /**\n * Automatically creates a container for this request\n */\n type: 'container_auto';\n\n /**\n * An optional list of uploaded files to make available to your code.\n */\n file_ids?: Array<string>;\n\n /**\n * The memory limit for the container.\n */\n memory_limit?: '1g' | '4g' | '16g' | '64g' | null;\n\n /**\n * Network access policy for the container.\n */\n network_policy?: ContainerNetworkPolicyDisabled | ContainerNetworkPolicyAllowlist;\n\n /**\n * An optional list of skills referenced by id or inline data.\n */\n skills?: Array<SkillReference | InlineSkill>;\n}\n\nexport interface ContainerNetworkPolicyAllowlist {\n /**\n * A list of allowed domains when type is `allowlist`.\n */\n allowed_domains: Array<string>;\n\n /**\n * Allow outbound network access only to specified domains. Always `allowlist`.\n */\n type: 'allowlist';\n\n /**\n * Optional domain-scoped secrets for allowlisted domains.\n */\n domain_secrets?: Array<ContainerNetworkPolicyDomainSecret>;\n}\n\nexport interface ContainerNetworkPolicyDisabled {\n /**\n * Disable outbound network access. Always `disabled`.\n */\n type: 'disabled';\n}\n\nexport interface ContainerNetworkPolicyDomainSecret {\n /**\n * The domain associated with the secret.\n */\n domain: string;\n\n /**\n * The name of the secret to inject for the domain.\n */\n name: string;\n\n /**\n * The secret value to inject for the domain.\n */\n value: string;\n}\n\nexport interface ContainerReference {\n /**\n * The ID of the referenced container.\n */\n container_id: string;\n\n /**\n * References a container created with the /v1/containers endpoint\n */\n type: 'container_reference';\n}\n\n/**\n * A custom tool that processes input using a specified format. Learn more about\n * [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)\n */\nexport interface CustomTool {\n /**\n * The name of the custom tool, used to identify it in tool calls.\n */\n name: string;\n\n /**\n * The type of the custom tool. Always `custom`.\n */\n type: 'custom';\n\n /**\n * Whether this tool should be deferred and discovered via tool search.\n */\n defer_loading?: boolean;\n\n /**\n * Optional description of the custom tool, used to provide more context.\n */\n description?: string;\n\n /**\n * The input format for the custom tool. Default is unconstrained text.\n */\n format?: Shared.CustomToolInputFormat;\n}\n\n/**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\nexport interface EasyInputMessage {\n /**\n * Text, image, or audio input to the model, used to generate a response. Can also\n * contain previous assistant responses.\n */\n content: string | ResponseInputMessageContentList;\n\n /**\n * The role of the message input. One of `user`, `assistant`, `system`, or\n * `developer`.\n */\n role: 'user' | 'assistant' | 'system' | 'developer';\n\n /**\n * Labels an `assistant` message as intermediate commentary (`commentary`) or the\n * final answer (`final_answer`). For models like `gpt-5.3-codex` and beyond, when\n * sending follow-up requests, preserve and resend phase on all assistant messages\n * — dropping it can degrade performance. Not used for user messages.\n */\n phase?: 'commentary' | 'final_answer' | null;\n\n /**\n * The type of the message input. Always `message`.\n */\n type?: 'message';\n}\n\n/**\n * A tool that searches for relevant content from uploaded files. Learn more about\n * the\n * [file search tool](https://platform.openai.com/docs/guides/tools-file-search).\n */\nexport interface FileSearchTool {\n /**\n * The type of the file search tool. Always `file_search`.\n */\n type: 'file_search';\n\n /**\n * The IDs of the vector stores to search.\n */\n vector_store_ids: Array<string>;\n\n /**\n * A filter to apply.\n */\n filters?: Shared.ComparisonFilter | Shared.CompoundFilter | null;\n\n /**\n * The maximum number of results to return. This number should be between 1 and 50\n * inclusive.\n */\n max_num_results?: number;\n\n /**\n * Ranking options for search.\n */\n ranking_options?: FileSearchTool.RankingOptions;\n}\n\nexport namespace FileSearchTool {\n /**\n * Ranking options for search.\n */\n export interface RankingOptions {\n /**\n * Weights that control how reciprocal rank fusion balances semantic embedding\n * matches versus sparse keyword matches when hybrid search is enabled.\n */\n hybrid_search?: RankingOptions.HybridSearch;\n\n /**\n * The ranker to use for the file search.\n */\n ranker?: 'auto' | 'default-2024-11-15';\n\n /**\n * The score threshold for the file search, a number between 0 and 1. Numbers\n * closer to 1 will attempt to return only the most relevant results, but may\n * return fewer results.\n */\n score_threshold?: number;\n }\n\n export namespace RankingOptions {\n /**\n * Weights that control how reciprocal rank fusion balances semantic embedding\n * matches versus sparse keyword matches when hybrid search is enabled.\n */\n export interface HybridSearch {\n /**\n * The weight of the embedding in the reciprocal ranking fusion.\n */\n embedding_weight: number;\n\n /**\n * The weight of the text in the reciprocal ranking fusion.\n */\n text_weight: number;\n }\n }\n}\n\n/**\n * A tool that allows the model to execute shell commands.\n */\nexport interface FunctionShellTool {\n /**\n * The type of the shell tool. Always `shell`.\n */\n type: 'shell';\n\n environment?: ContainerAuto | LocalEnvironment | ContainerReference | null;\n}\n\n/**\n * Defines a function in your own code the model can choose to call. Learn more\n * about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n */\nexport interface FunctionTool {\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * A JSON schema object describing the parameters of the function.\n */\n parameters: { [key: string]: unknown } | null;\n\n /**\n * Whether to enforce strict parameter validation. Default `true`.\n */\n strict: boolean | null;\n\n /**\n * The type of the function tool. Always `function`.\n */\n type: 'function';\n\n /**\n * Whether this function is deferred and loaded via tool search.\n */\n defer_loading?: boolean;\n\n /**\n * A description of the function. Used by the model to determine whether or not to\n * call the function.\n */\n description?: string | null;\n}\n\nexport interface InlineSkill {\n /**\n * The description of the skill.\n */\n description: string;\n\n /**\n * The name of the skill.\n */\n name: string;\n\n /**\n * Inline skill payload\n */\n source: InlineSkillSource;\n\n /**\n * Defines an inline skill for this request.\n */\n type: 'inline';\n}\n\n/**\n * Inline skill payload\n */\nexport interface InlineSkillSource {\n /**\n * Base64-encoded skill zip bundle.\n */\n data: string;\n\n /**\n * The media type of the inline skill payload. Must be `application/zip`.\n */\n media_type: 'application/zip';\n\n /**\n * The type of the inline skill source. Must be `base64`.\n */\n type: 'base64';\n}\n\nexport interface LocalEnvironment {\n /**\n * Use a local computer environment.\n */\n type: 'local';\n\n /**\n * An optional list of skills.\n */\n skills?: Array<LocalSkill>;\n}\n\nexport interface LocalSkill {\n /**\n * The description of the skill.\n */\n description: string;\n\n /**\n * The name of the skill.\n */\n name: string;\n\n /**\n * The path to the directory containing the skill.\n */\n path: string;\n}\n\n/**\n * Groups function/custom tools under a shared namespace.\n */\nexport interface NamespaceTool {\n /**\n * A description of the namespace shown to the model.\n */\n description: string;\n\n /**\n * The namespace name used in tool calls (for example, `crm`).\n */\n name: string;\n\n /**\n * The function/custom tools available inside this namespace.\n */\n tools: Array<NamespaceTool.Function | CustomTool>;\n\n /**\n * The type of the tool. Always `namespace`.\n */\n type: 'namespace';\n}\n\nexport namespace NamespaceTool {\n export interface Function {\n name: string;\n\n type: 'function';\n\n description?: string | null;\n\n parameters?: unknown | null;\n\n strict?: boolean | null;\n }\n}\n\nexport interface Response {\n /**\n * Unique identifier for this Response.\n */\n id: string;\n\n /**\n * Unix timestamp (in seconds) of when this Response was created.\n */\n created_at: number;\n\n output_text: string;\n\n /**\n * An error object returned when the model fails to generate a Response.\n */\n error: ResponseError | null;\n\n /**\n * Details about why the response is incomplete.\n */\n incomplete_details: Response.IncompleteDetails | null;\n\n /**\n * A system (or developer) message inserted into the model's context.\n *\n * When using along with `previous_response_id`, the instructions from a previous\n * response will not be carried over to the next response. This makes it simple to\n * swap out system (or developer) messages in new responses.\n */\n instructions: string | Array<ResponseInputItem> | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model: Shared.ResponsesModel;\n\n /**\n * The object type of this resource - always set to `response`.\n */\n object: 'response';\n\n /**\n * An array of content items generated by the model.\n *\n * - The length and order of items in the `output` array is dependent on the\n * model's response.\n * - Rather than accessing the first item in the `output` array and assuming it's\n * an `assistant` message with the content generated by the model, you might\n * consider using the `output_text` property where supported in SDKs.\n */\n output: Array<ResponseOutputItem>;\n\n /**\n * Whether to allow the model to run tool calls in parallel.\n */\n parallel_tool_calls: boolean;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic. We generally recommend altering this or `top_p` but\n * not both.\n */\n temperature: number | null;\n\n /**\n * How the model should select which tool (or tools) to use when generating a\n * response. See the `tools` parameter to see how to specify which tools the model\n * can call.\n */\n tool_choice:\n | ToolChoiceOptions\n | ToolChoiceAllowed\n | ToolChoiceTypes\n | ToolChoiceFunction\n | ToolChoiceMcp\n | ToolChoiceCustom\n | ToolChoiceApplyPatch\n | ToolChoiceShell;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * We support the following categories of tools:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or\n * predefined connectors such as Google Drive and SharePoint. Learn more about\n * [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code with strongly typed arguments and outputs.\n * Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n * You can also use custom tools to call your own code.\n */\n tools: Array<Tool>;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or `temperature` but not both.\n */\n top_p: number | null;\n\n /**\n * Whether to run the model response in the background.\n * [Learn more](https://platform.openai.com/docs/guides/background).\n */\n background?: boolean | null;\n\n /**\n * Unix timestamp (in seconds) of when this Response was completed. Only present\n * when the status is `completed`.\n */\n completed_at?: number | null;\n\n /**\n * The conversation that this response belonged to. Input items and output items\n * from this response were automatically added to this conversation.\n */\n conversation?: Response.Conversation | null;\n\n /**\n * An upper bound for the number of tokens that can be generated for a response,\n * including visible output tokens and\n * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n */\n max_output_tokens?: number | null;\n\n /**\n * The unique ID of the previous response to the model. Use this to create\n * multi-turn conversations. Learn more about\n * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n * Cannot be used in conjunction with `conversation`.\n */\n previous_response_id?: string | null;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsePrompt | null;\n\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n prompt_cache_key?: string;\n\n /**\n * The retention policy for the prompt cache. Set to `24h` to enable extended\n * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n * of 24 hours.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n */\n prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n /**\n * **gpt-5 and o-series models only**\n *\n * Configuration options for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n */\n reasoning?: Shared.Reasoning | null;\n\n /**\n * A stable identifier used to help detect users of your application that may be\n * violating OpenAI's usage policies. The IDs should be a string that uniquely\n * identifies each user, with a maximum length of 64 characters. We recommend\n * hashing their username or email address, in order to avoid sending us any\n * identifying information.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n safety_identifier?: string;\n\n /**\n * Specifies the latency tier to use for processing the request. This parameter is\n * relevant for customers subscribed to the scale tier service:\n *\n * - If set to 'auto', then the request will be processed with the service tier\n * configured in the Project settings. Unless otherwise configured, the Project\n * will use 'default'.\n * - If set to 'default', then the request will be processed with the standard\n * pricing and performance for the selected model.\n * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n * '[priority](https://openai.com/api-priority-processing/)', then the request\n * will be processed with the corresponding service tier.\n * - When not set, the default behavior is 'auto'.\n *\n * When this parameter is set, the response body will include the `service_tier`\n * utilized.\n */\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n /**\n * The status of the response generation. One of `completed`, `failed`,\n * `in_progress`, `cancelled`, `queued`, or `incomplete`.\n */\n status?: ResponseStatus;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: ResponseTextConfig;\n\n /**\n * The truncation strategy to use for the model response.\n *\n * - `auto`: If the input to this Response exceeds the model's context window size,\n * the model will truncate the response to fit the context window by dropping\n * items from the beginning of the conversation.\n * - `disabled` (default): If the input size will exceed the context window size\n * for a model, the request will fail with a 400 error.\n */\n truncation?: 'auto' | 'disabled' | null;\n\n /**\n * Represents token usage details including input tokens, output tokens, a\n * breakdown of output tokens, and the total tokens used.\n */\n usage?: ResponseUsage;\n\n /**\n * @deprecated This field is being replaced by `safety_identifier` and\n * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n * optimizations. A stable identifier for your end-users. Used to boost cache hit\n * rates by better bucketing similar requests and to help OpenAI detect and prevent\n * abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n user?: string;\n}\n\nexport namespace Response {\n /**\n * Details about why the response is incomplete.\n */\n export interface IncompleteDetails {\n /**\n * The reason why the response is incomplete.\n */\n reason?: 'max_output_tokens' | 'content_filter';\n }\n\n /**\n * The conversation that this response belonged to. Input items and output items\n * from this response were automatically added to this conversation.\n */\n export interface Conversation {\n /**\n * The unique ID of the conversation that this response was associated with.\n */\n id: string;\n }\n}\n\n/**\n * A tool call that applies file diffs by creating, deleting, or updating files.\n */\nexport interface ResponseApplyPatchToolCall {\n /**\n * The unique ID of the apply patch tool call. Populated when this item is returned\n * via API.\n */\n id: string;\n\n /**\n * The unique ID of the apply patch tool call generated by the model.\n */\n call_id: string;\n\n /**\n * One of the create_file, delete_file, or update_file operations applied via\n * apply_patch.\n */\n operation:\n | ResponseApplyPatchToolCall.CreateFile\n | ResponseApplyPatchToolCall.DeleteFile\n | ResponseApplyPatchToolCall.UpdateFile;\n\n /**\n * The status of the apply patch tool call. One of `in_progress` or `completed`.\n */\n status: 'in_progress' | 'completed';\n\n /**\n * The type of the item. Always `apply_patch_call`.\n */\n type: 'apply_patch_call';\n\n /**\n * The ID of the entity that created this tool call.\n */\n created_by?: string;\n}\n\nexport namespace ResponseApplyPatchToolCall {\n /**\n * Instruction describing how to create a file via the apply_patch tool.\n */\n export interface CreateFile {\n /**\n * Diff to apply.\n */\n diff: string;\n\n /**\n * Path of the file to create.\n */\n path: string;\n\n /**\n * Create a new file with the provided diff.\n */\n type: 'create_file';\n }\n\n /**\n * Instruction describing how to delete a file via the apply_patch tool.\n */\n export interface DeleteFile {\n /**\n * Path of the file to delete.\n */\n path: string;\n\n /**\n * Delete the specified file.\n */\n type: 'delete_file';\n }\n\n /**\n * Instruction describing how to update a file via the apply_patch tool.\n */\n export interface UpdateFile {\n /**\n * Diff to apply.\n */\n diff: string;\n\n /**\n * Path of the file to update.\n */\n path: string;\n\n /**\n * Update an existing file with the provided diff.\n */\n type: 'update_file';\n }\n}\n\n/**\n * The output emitted by an apply patch tool call.\n */\nexport interface ResponseApplyPatchToolCallOutput {\n /**\n * The unique ID of the apply patch tool call output. Populated when this item is\n * returned via API.\n */\n id: string;\n\n /**\n * The unique ID of the apply patch tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The status of the apply patch tool call output. One of `completed` or `failed`.\n */\n status: 'completed' | 'failed';\n\n /**\n * The type of the item. Always `apply_patch_call_output`.\n */\n type: 'apply_patch_call_output';\n\n /**\n * The ID of the entity that created this tool call output.\n */\n created_by?: string;\n\n /**\n * Optional textual output returned by the apply patch tool.\n */\n output?: string | null;\n}\n\n/**\n * Emitted when there is a partial audio response.\n */\nexport interface ResponseAudioDeltaEvent {\n /**\n * A chunk of Base64 encoded response audio bytes.\n */\n delta: string;\n\n /**\n * A sequence number for this chunk of the stream response.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.audio.delta`.\n */\n type: 'response.audio.delta';\n}\n\n/**\n * Emitted when the audio response is complete.\n */\nexport interface ResponseAudioDoneEvent {\n /**\n * The sequence number of the delta.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.audio.done`.\n */\n type: 'response.audio.done';\n}\n\n/**\n * Emitted when there is a partial transcript of audio.\n */\nexport interface ResponseAudioTranscriptDeltaEvent {\n /**\n * The partial transcript of the audio response.\n */\n delta: string;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.audio.transcript.delta`.\n */\n type: 'response.audio.transcript.delta';\n}\n\n/**\n * Emitted when the full audio transcript is completed.\n */\nexport interface ResponseAudioTranscriptDoneEvent {\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.audio.transcript.done`.\n */\n type: 'response.audio.transcript.done';\n}\n\n/**\n * Emitted when a partial code snippet is streamed by the code interpreter.\n */\nexport interface ResponseCodeInterpreterCallCodeDeltaEvent {\n /**\n * The partial code snippet being streamed by the code interpreter.\n */\n delta: string;\n\n /**\n * The unique identifier of the code interpreter tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response for which the code is being\n * streamed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event, used to order streaming events.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.code_interpreter_call_code.delta`.\n */\n type: 'response.code_interpreter_call_code.delta';\n}\n\n/**\n * Emitted when the code snippet is finalized by the code interpreter.\n */\nexport interface ResponseCodeInterpreterCallCodeDoneEvent {\n /**\n * The final code snippet output by the code interpreter.\n */\n code: string;\n\n /**\n * The unique identifier of the code interpreter tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response for which the code is finalized.\n */\n output_index: number;\n\n /**\n * The sequence number of this event, used to order streaming events.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.code_interpreter_call_code.done`.\n */\n type: 'response.code_interpreter_call_code.done';\n}\n\n/**\n * Emitted when the code interpreter call is completed.\n */\nexport interface ResponseCodeInterpreterCallCompletedEvent {\n /**\n * The unique identifier of the code interpreter tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response for which the code interpreter call\n * is completed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event, used to order streaming events.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.code_interpreter_call.completed`.\n */\n type: 'response.code_interpreter_call.completed';\n}\n\n/**\n * Emitted when a code interpreter call is in progress.\n */\nexport interface ResponseCodeInterpreterCallInProgressEvent {\n /**\n * The unique identifier of the code interpreter tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response for which the code interpreter call\n * is in progress.\n */\n output_index: number;\n\n /**\n * The sequence number of this event, used to order streaming events.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.code_interpreter_call.in_progress`.\n */\n type: 'response.code_interpreter_call.in_progress';\n}\n\n/**\n * Emitted when the code interpreter is actively interpreting the code snippet.\n */\nexport interface ResponseCodeInterpreterCallInterpretingEvent {\n /**\n * The unique identifier of the code interpreter tool call item.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response for which the code interpreter is\n * interpreting code.\n */\n output_index: number;\n\n /**\n * The sequence number of this event, used to order streaming events.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.code_interpreter_call.interpreting`.\n */\n type: 'response.code_interpreter_call.interpreting';\n}\n\n/**\n * A tool call to run code.\n */\nexport interface ResponseCodeInterpreterToolCall {\n /**\n * The unique ID of the code interpreter tool call.\n */\n id: string;\n\n /**\n * The code to run, or null if not available.\n */\n code: string | null;\n\n /**\n * The ID of the container used to run the code.\n */\n container_id: string;\n\n /**\n * The outputs generated by the code interpreter, such as logs or images. Can be\n * null if no outputs are available.\n */\n outputs: Array<ResponseCodeInterpreterToolCall.Logs | ResponseCodeInterpreterToolCall.Image> | null;\n\n /**\n * The status of the code interpreter tool call. Valid values are `in_progress`,\n * `completed`, `incomplete`, `interpreting`, and `failed`.\n */\n status: 'in_progress' | 'completed' | 'incomplete' | 'interpreting' | 'failed';\n\n /**\n * The type of the code interpreter tool call. Always `code_interpreter_call`.\n */\n type: 'code_interpreter_call';\n}\n\nexport namespace ResponseCodeInterpreterToolCall {\n /**\n * The logs output from the code interpreter.\n */\n export interface Logs {\n /**\n * The logs output from the code interpreter.\n */\n logs: string;\n\n /**\n * The type of the output. Always `logs`.\n */\n type: 'logs';\n }\n\n /**\n * The image output from the code interpreter.\n */\n export interface Image {\n /**\n * The type of the output. Always `image`.\n */\n type: 'image';\n\n /**\n * The URL of the image output from the code interpreter.\n */\n url: string;\n }\n}\n\n/**\n * A compaction item generated by the\n * [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).\n */\nexport interface ResponseCompactionItem {\n /**\n * The unique ID of the compaction item.\n */\n id: string;\n\n /**\n * The encrypted content that was produced by compaction.\n */\n encrypted_content: string;\n\n /**\n * The type of the item. Always `compaction`.\n */\n type: 'compaction';\n\n /**\n * The identifier of the actor that created the item.\n */\n created_by?: string;\n}\n\n/**\n * A compaction item generated by the\n * [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).\n */\nexport interface ResponseCompactionItemParam {\n /**\n * The encrypted content of the compaction summary.\n */\n encrypted_content: string;\n\n /**\n * The type of the item. Always `compaction`.\n */\n type: 'compaction';\n\n /**\n * The ID of the compaction item.\n */\n id?: string | null;\n}\n\n/**\n * Emitted when the model response is complete.\n */\nexport interface ResponseCompletedEvent {\n /**\n * Properties of the completed response.\n */\n response: Response;\n\n /**\n * The sequence number for this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.completed`.\n */\n type: 'response.completed';\n}\n\n/**\n * A tool call to a computer use tool. See the\n * [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use)\n * for more information.\n */\nexport interface ResponseComputerToolCall {\n /**\n * The unique ID of the computer call.\n */\n id: string;\n\n /**\n * An identifier used when responding to the tool call with output.\n */\n call_id: string;\n\n /**\n * The pending safety checks for the computer call.\n */\n pending_safety_checks: Array<ResponseComputerToolCall.PendingSafetyCheck>;\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the computer call. Always `computer_call`.\n */\n type: 'computer_call';\n\n /**\n * A click action.\n */\n action?:\n | ResponseComputerToolCall.Click\n | ResponseComputerToolCall.DoubleClick\n | ResponseComputerToolCall.Drag\n | ResponseComputerToolCall.Keypress\n | ResponseComputerToolCall.Move\n | ResponseComputerToolCall.Screenshot\n | ResponseComputerToolCall.Scroll\n | ResponseComputerToolCall.Type\n | ResponseComputerToolCall.Wait;\n\n /**\n * Flattened batched actions for `computer_use`. Each action includes an `type`\n * discriminator and action-specific fields.\n */\n actions?: ComputerActionList;\n}\n\nexport namespace ResponseComputerToolCall {\n /**\n * A pending safety check for the computer call.\n */\n export interface PendingSafetyCheck {\n /**\n * The ID of the pending safety check.\n */\n id: string;\n\n /**\n * The type of the pending safety check.\n */\n code?: string | null;\n\n /**\n * Details about the pending safety check.\n */\n message?: string | null;\n }\n\n /**\n * A click action.\n */\n export interface Click {\n /**\n * Indicates which mouse button was pressed during the click. One of `left`,\n * `right`, `wheel`, `back`, or `forward`.\n */\n button: 'left' | 'right' | 'wheel' | 'back' | 'forward';\n\n /**\n * Specifies the event type. For a click action, this property is always `click`.\n */\n type: 'click';\n\n /**\n * The x-coordinate where the click occurred.\n */\n x: number;\n\n /**\n * The y-coordinate where the click occurred.\n */\n y: number;\n }\n\n /**\n * A double click action.\n */\n export interface DoubleClick {\n /**\n * Specifies the event type. For a double click action, this property is always set\n * to `double_click`.\n */\n type: 'double_click';\n\n /**\n * The x-coordinate where the double click occurred.\n */\n x: number;\n\n /**\n * The y-coordinate where the double click occurred.\n */\n y: number;\n }\n\n /**\n * A drag action.\n */\n export interface Drag {\n /**\n * An array of coordinates representing the path of the drag action. Coordinates\n * will appear as an array of objects, eg\n *\n * ```\n * [\n * { x: 100, y: 200 },\n * { x: 200, y: 300 }\n * ]\n * ```\n */\n path: Array<Drag.Path>;\n\n /**\n * Specifies the event type. For a drag action, this property is always set to\n * `drag`.\n */\n type: 'drag';\n }\n\n export namespace Drag {\n /**\n * An x/y coordinate pair, e.g. `{ x: 100, y: 200 }`.\n */\n export interface Path {\n /**\n * The x-coordinate.\n */\n x: number;\n\n /**\n * The y-coordinate.\n */\n y: number;\n }\n }\n\n /**\n * A collection of keypresses the model would like to perform.\n */\n export interface Keypress {\n /**\n * The combination of keys the model is requesting to be pressed. This is an array\n * of strings, each representing a key.\n */\n keys: Array<string>;\n\n /**\n * Specifies the event type. For a keypress action, this property is always set to\n * `keypress`.\n */\n type: 'keypress';\n }\n\n /**\n * A mouse move action.\n */\n export interface Move {\n /**\n * Specifies the event type. For a move action, this property is always set to\n * `move`.\n */\n type: 'move';\n\n /**\n * The x-coordinate to move to.\n */\n x: number;\n\n /**\n * The y-coordinate to move to.\n */\n y: number;\n }\n\n /**\n * A screenshot action.\n */\n export interface Screenshot {\n /**\n * Specifies the event type. For a screenshot action, this property is always set\n * to `screenshot`.\n */\n type: 'screenshot';\n }\n\n /**\n * A scroll action.\n */\n export interface Scroll {\n /**\n * The horizontal scroll distance.\n */\n scroll_x: number;\n\n /**\n * The vertical scroll distance.\n */\n scroll_y: number;\n\n /**\n * Specifies the event type. For a scroll action, this property is always set to\n * `scroll`.\n */\n type: 'scroll';\n\n /**\n * The x-coordinate where the scroll occurred.\n */\n x: number;\n\n /**\n * The y-coordinate where the scroll occurred.\n */\n y: number;\n }\n\n /**\n * An action to type in text.\n */\n export interface Type {\n /**\n * The text to type.\n */\n text: string;\n\n /**\n * Specifies the event type. For a type action, this property is always set to\n * `type`.\n */\n type: 'type';\n }\n\n /**\n * A wait action.\n */\n export interface Wait {\n /**\n * Specifies the event type. For a wait action, this property is always set to\n * `wait`.\n */\n type: 'wait';\n }\n}\n\nexport interface ResponseComputerToolCallOutputItem {\n /**\n * The unique ID of the computer call tool output.\n */\n id: string;\n\n /**\n * The ID of the computer tool call that produced the output.\n */\n call_id: string;\n\n /**\n * A computer screenshot image used with the computer use tool.\n */\n output: ResponseComputerToolCallOutputScreenshot;\n\n /**\n * The type of the computer tool call output. Always `computer_call_output`.\n */\n type: 'computer_call_output';\n\n /**\n * The safety checks reported by the API that have been acknowledged by the\n * developer.\n */\n acknowledged_safety_checks?: Array<ResponseComputerToolCallOutputItem.AcknowledgedSafetyCheck>;\n\n /**\n * The status of the message input. One of `in_progress`, `completed`, or\n * `incomplete`. Populated when input items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\nexport namespace ResponseComputerToolCallOutputItem {\n /**\n * A pending safety check for the computer call.\n */\n export interface AcknowledgedSafetyCheck {\n /**\n * The ID of the pending safety check.\n */\n id: string;\n\n /**\n * The type of the pending safety check.\n */\n code?: string | null;\n\n /**\n * Details about the pending safety check.\n */\n message?: string | null;\n }\n}\n\n/**\n * A computer screenshot image used with the computer use tool.\n */\nexport interface ResponseComputerToolCallOutputScreenshot {\n /**\n * Specifies the event type. For a computer screenshot, this property is always set\n * to `computer_screenshot`.\n */\n type: 'computer_screenshot';\n\n /**\n * The identifier of an uploaded file that contains the screenshot.\n */\n file_id?: string;\n\n /**\n * The URL of the screenshot image.\n */\n image_url?: string;\n}\n\n/**\n * Represents a container created with /v1/containers.\n */\nexport interface ResponseContainerReference {\n container_id: string;\n\n /**\n * The environment type. Always `container_reference`.\n */\n type: 'container_reference';\n}\n\n/**\n * Multi-modal input and output contents.\n */\nexport type ResponseContent =\n | ResponseInputText\n | ResponseInputImage\n | ResponseInputFile\n | ResponseOutputText\n | ResponseOutputRefusal\n | ResponseContent.ReasoningTextContent;\n\nexport namespace ResponseContent {\n /**\n * Reasoning text from the model.\n */\n export interface ReasoningTextContent {\n /**\n * The reasoning text from the model.\n */\n text: string;\n\n /**\n * The type of the reasoning text. Always `reasoning_text`.\n */\n type: 'reasoning_text';\n }\n}\n\n/**\n * Emitted when a new content part is added.\n */\nexport interface ResponseContentPartAddedEvent {\n /**\n * The index of the content part that was added.\n */\n content_index: number;\n\n /**\n * The ID of the output item that the content part was added to.\n */\n item_id: string;\n\n /**\n * The index of the output item that the content part was added to.\n */\n output_index: number;\n\n /**\n * The content part that was added.\n */\n part: ResponseOutputText | ResponseOutputRefusal | ResponseContentPartAddedEvent.ReasoningText;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.content_part.added`.\n */\n type: 'response.content_part.added';\n}\n\nexport namespace ResponseContentPartAddedEvent {\n /**\n * Reasoning text from the model.\n */\n export interface ReasoningText {\n /**\n * The reasoning text from the model.\n */\n text: string;\n\n /**\n * The type of the reasoning text. Always `reasoning_text`.\n */\n type: 'reasoning_text';\n }\n}\n\n/**\n * Emitted when a content part is done.\n */\nexport interface ResponseContentPartDoneEvent {\n /**\n * The index of the content part that is done.\n */\n content_index: number;\n\n /**\n * The ID of the output item that the content part was added to.\n */\n item_id: string;\n\n /**\n * The index of the output item that the content part was added to.\n */\n output_index: number;\n\n /**\n * The content part that is done.\n */\n part: ResponseOutputText | ResponseOutputRefusal | ResponseContentPartDoneEvent.ReasoningText;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.content_part.done`.\n */\n type: 'response.content_part.done';\n}\n\nexport namespace ResponseContentPartDoneEvent {\n /**\n * Reasoning text from the model.\n */\n export interface ReasoningText {\n /**\n * The reasoning text from the model.\n */\n text: string;\n\n /**\n * The type of the reasoning text. Always `reasoning_text`.\n */\n type: 'reasoning_text';\n }\n}\n\n/**\n * The conversation that this response belongs to.\n */\nexport interface ResponseConversationParam {\n /**\n * The unique ID of the conversation.\n */\n id: string;\n}\n\n/**\n * An event that is emitted when a response is created.\n */\nexport interface ResponseCreatedEvent {\n /**\n * The response that was created.\n */\n response: Response;\n\n /**\n * The sequence number for this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.created`.\n */\n type: 'response.created';\n}\n\n/**\n * A call to a custom tool created by the model.\n */\nexport interface ResponseCustomToolCall {\n /**\n * An identifier used to map this custom tool call to a tool call output.\n */\n call_id: string;\n\n /**\n * The input for the custom tool call generated by the model.\n */\n input: string;\n\n /**\n * The name of the custom tool being called.\n */\n name: string;\n\n /**\n * The type of the custom tool call. Always `custom_tool_call`.\n */\n type: 'custom_tool_call';\n\n /**\n * The unique ID of the custom tool call in the OpenAI platform.\n */\n id?: string;\n\n /**\n * The namespace of the custom tool being called.\n */\n namespace?: string;\n}\n\n/**\n * Event representing a delta (partial update) to the input of a custom tool call.\n */\nexport interface ResponseCustomToolCallInputDeltaEvent {\n /**\n * The incremental input data (delta) for the custom tool call.\n */\n delta: string;\n\n /**\n * Unique identifier for the API item associated with this event.\n */\n item_id: string;\n\n /**\n * The index of the output this delta applies to.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The event type identifier.\n */\n type: 'response.custom_tool_call_input.delta';\n}\n\n/**\n * Event indicating that input for a custom tool call is complete.\n */\nexport interface ResponseCustomToolCallInputDoneEvent {\n /**\n * The complete input data for the custom tool call.\n */\n input: string;\n\n /**\n * Unique identifier for the API item associated with this event.\n */\n item_id: string;\n\n /**\n * The index of the output this event applies to.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The event type identifier.\n */\n type: 'response.custom_tool_call_input.done';\n}\n\n/**\n * The output of a custom tool call from your code, being sent back to the model.\n */\nexport interface ResponseCustomToolCallOutput {\n /**\n * The call ID, used to map this custom tool call output to a custom tool call.\n */\n call_id: string;\n\n /**\n * The output from the custom tool call generated by your code. Can be a string or\n * an list of output content.\n */\n output: string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile>;\n\n /**\n * The type of the custom tool call output. Always `custom_tool_call_output`.\n */\n type: 'custom_tool_call_output';\n\n /**\n * The unique ID of the custom tool call output in the OpenAI platform.\n */\n id?: string;\n}\n\n/**\n * An error object returned when the model fails to generate a Response.\n */\nexport interface ResponseError {\n /**\n * The error code for the response.\n */\n code:\n | 'server_error'\n | 'rate_limit_exceeded'\n | 'invalid_prompt'\n | 'vector_store_timeout'\n | 'invalid_image'\n | 'invalid_image_format'\n | 'invalid_base64_image'\n | 'invalid_image_url'\n | 'image_too_large'\n | 'image_too_small'\n | 'image_parse_error'\n | 'image_content_policy_violation'\n | 'invalid_image_mode'\n | 'image_file_too_large'\n | 'unsupported_image_media_type'\n | 'empty_image_file'\n | 'failed_to_download_image'\n | 'image_file_not_found';\n\n /**\n * A human-readable description of the error.\n */\n message: string;\n}\n\n/**\n * Emitted when an error occurs.\n */\nexport interface ResponseErrorEvent {\n /**\n * The error code.\n */\n code: string | null;\n\n /**\n * The error message.\n */\n message: string;\n\n /**\n * The error parameter.\n */\n param: string | null;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `error`.\n */\n type: 'error';\n}\n\n/**\n * An event that is emitted when a response fails.\n */\nexport interface ResponseFailedEvent {\n /**\n * The response that failed.\n */\n response: Response;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.failed`.\n */\n type: 'response.failed';\n}\n\n/**\n * Emitted when a file search call is completed (results found).\n */\nexport interface ResponseFileSearchCallCompletedEvent {\n /**\n * The ID of the output item that the file search call is initiated.\n */\n item_id: string;\n\n /**\n * The index of the output item that the file search call is initiated.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.file_search_call.completed`.\n */\n type: 'response.file_search_call.completed';\n}\n\n/**\n * Emitted when a file search call is initiated.\n */\nexport interface ResponseFileSearchCallInProgressEvent {\n /**\n * The ID of the output item that the file search call is initiated.\n */\n item_id: string;\n\n /**\n * The index of the output item that the file search call is initiated.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.file_search_call.in_progress`.\n */\n type: 'response.file_search_call.in_progress';\n}\n\n/**\n * Emitted when a file search is currently searching.\n */\nexport interface ResponseFileSearchCallSearchingEvent {\n /**\n * The ID of the output item that the file search call is initiated.\n */\n item_id: string;\n\n /**\n * The index of the output item that the file search call is searching.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.file_search_call.searching`.\n */\n type: 'response.file_search_call.searching';\n}\n\n/**\n * The results of a file search tool call. See the\n * [file search guide](https://platform.openai.com/docs/guides/tools-file-search)\n * for more information.\n */\nexport interface ResponseFileSearchToolCall {\n /**\n * The unique ID of the file search tool call.\n */\n id: string;\n\n /**\n * The queries used to search for files.\n */\n queries: Array<string>;\n\n /**\n * The status of the file search tool call. One of `in_progress`, `searching`,\n * `incomplete` or `failed`,\n */\n status: 'in_progress' | 'searching' | 'completed' | 'incomplete' | 'failed';\n\n /**\n * The type of the file search tool call. Always `file_search_call`.\n */\n type: 'file_search_call';\n\n /**\n * The results of the file search tool call.\n */\n results?: Array<ResponseFileSearchToolCall.Result> | null;\n}\n\nexport namespace ResponseFileSearchToolCall {\n export interface Result {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters, booleans, or numbers.\n */\n attributes?: { [key: string]: string | number | boolean } | null;\n\n /**\n * The unique ID of the file.\n */\n file_id?: string;\n\n /**\n * The name of the file.\n */\n filename?: string;\n\n /**\n * The relevance score of the file - a value between 0 and 1.\n */\n score?: number;\n\n /**\n * The text that was retrieved from the file.\n */\n text?: string;\n }\n}\n\n/**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\nexport type ResponseFormatTextConfig =\n | Shared.ResponseFormatText\n | ResponseFormatTextJSONSchemaConfig\n | Shared.ResponseFormatJSONObject;\n\n/**\n * JSON Schema response format. Used to generate structured JSON responses. Learn\n * more about\n * [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).\n */\nexport interface ResponseFormatTextJSONSchemaConfig {\n /**\n * The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores\n * and dashes, with a maximum length of 64.\n */\n name: string;\n\n /**\n * The schema for the response format, described as a JSON Schema object. Learn how\n * to build JSON schemas [here](https://json-schema.org/).\n */\n schema: { [key: string]: unknown };\n\n /**\n * The type of response format being defined. Always `json_schema`.\n */\n type: 'json_schema';\n\n /**\n * A description of what the response format is for, used by the model to determine\n * how to respond in the format.\n */\n description?: string;\n\n /**\n * Whether to enable strict schema adherence when generating the output. If set to\n * true, the model will always follow the exact schema defined in the `schema`\n * field. Only a subset of JSON Schema is supported when `strict` is `true`. To\n * learn more, read the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n */\n strict?: boolean | null;\n}\n\n/**\n * Emitted when there is a partial function-call arguments delta.\n */\nexport interface ResponseFunctionCallArgumentsDeltaEvent {\n /**\n * The function-call arguments delta that is added.\n */\n delta: string;\n\n /**\n * The ID of the output item that the function-call arguments delta is added to.\n */\n item_id: string;\n\n /**\n * The index of the output item that the function-call arguments delta is added to.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.function_call_arguments.delta`.\n */\n type: 'response.function_call_arguments.delta';\n}\n\n/**\n * Emitted when function-call arguments are finalized.\n */\nexport interface ResponseFunctionCallArgumentsDoneEvent {\n /**\n * The function-call arguments.\n */\n arguments: string;\n\n /**\n * The ID of the item.\n */\n item_id: string;\n\n /**\n * The name of the function that was called.\n */\n name: string;\n\n /**\n * The index of the output item.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n type: 'response.function_call_arguments.done';\n}\n\n/**\n * A piece of message content, such as text, an image, or a file.\n */\nexport type ResponseFunctionCallOutputItem =\n | ResponseInputTextContent\n | ResponseInputImageContent\n | ResponseInputFileContent;\n\n/**\n * An array of content outputs (text, image, file) for the function tool call.\n */\nexport type ResponseFunctionCallOutputItemList = Array<ResponseFunctionCallOutputItem>;\n\n/**\n * Captured stdout and stderr for a portion of a shell tool call output.\n */\nexport interface ResponseFunctionShellCallOutputContent {\n /**\n * The exit or timeout outcome associated with this shell call.\n */\n outcome: ResponseFunctionShellCallOutputContent.Timeout | ResponseFunctionShellCallOutputContent.Exit;\n\n /**\n * Captured stderr output for the shell call.\n */\n stderr: string;\n\n /**\n * Captured stdout output for the shell call.\n */\n stdout: string;\n}\n\nexport namespace ResponseFunctionShellCallOutputContent {\n /**\n * Indicates that the shell call exceeded its configured time limit.\n */\n export interface Timeout {\n /**\n * The outcome type. Always `timeout`.\n */\n type: 'timeout';\n }\n\n /**\n * Indicates that the shell commands finished and returned an exit code.\n */\n export interface Exit {\n /**\n * The exit code returned by the shell process.\n */\n exit_code: number;\n\n /**\n * The outcome type. Always `exit`.\n */\n type: 'exit';\n }\n}\n\n/**\n * A tool call that executes one or more shell commands in a managed environment.\n */\nexport interface ResponseFunctionShellToolCall {\n /**\n * The unique ID of the shell tool call. Populated when this item is returned via\n * API.\n */\n id: string;\n\n /**\n * The shell commands and limits that describe how to run the tool call.\n */\n action: ResponseFunctionShellToolCall.Action;\n\n /**\n * The unique ID of the shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * Represents the use of a local environment to perform shell actions.\n */\n environment: ResponseLocalEnvironment | ResponseContainerReference | null;\n\n /**\n * The status of the shell call. One of `in_progress`, `completed`, or\n * `incomplete`.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the item. Always `shell_call`.\n */\n type: 'shell_call';\n\n /**\n * The ID of the entity that created this tool call.\n */\n created_by?: string;\n}\n\nexport namespace ResponseFunctionShellToolCall {\n /**\n * The shell commands and limits that describe how to run the tool call.\n */\n export interface Action {\n commands: Array<string>;\n\n /**\n * Optional maximum number of characters to return from each command.\n */\n max_output_length: number | null;\n\n /**\n * Optional timeout in milliseconds for the commands.\n */\n timeout_ms: number | null;\n }\n}\n\n/**\n * The output of a shell tool call that was emitted.\n */\nexport interface ResponseFunctionShellToolCallOutput {\n /**\n * The unique ID of the shell call output. Populated when this item is returned via\n * API.\n */\n id: string;\n\n /**\n * The unique ID of the shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The maximum length of the shell command output. This is generated by the model\n * and should be passed back with the raw output.\n */\n max_output_length: number | null;\n\n /**\n * An array of shell call output contents\n */\n output: Array<ResponseFunctionShellToolCallOutput.Output>;\n\n /**\n * The status of the shell call output. One of `in_progress`, `completed`, or\n * `incomplete`.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the shell call output. Always `shell_call_output`.\n */\n type: 'shell_call_output';\n\n /**\n * The identifier of the actor that created the item.\n */\n created_by?: string;\n}\n\nexport namespace ResponseFunctionShellToolCallOutput {\n /**\n * The content of a shell tool call output that was emitted.\n */\n export interface Output {\n /**\n * Represents either an exit outcome (with an exit code) or a timeout outcome for a\n * shell call output chunk.\n */\n outcome: Output.Timeout | Output.Exit;\n\n /**\n * The standard error output that was captured.\n */\n stderr: string;\n\n /**\n * The standard output that was captured.\n */\n stdout: string;\n\n /**\n * The identifier of the actor that created the item.\n */\n created_by?: string;\n }\n\n export namespace Output {\n /**\n * Indicates that the shell call exceeded its configured time limit.\n */\n export interface Timeout {\n /**\n * The outcome type. Always `timeout`.\n */\n type: 'timeout';\n }\n\n /**\n * Indicates that the shell commands finished and returned an exit code.\n */\n export interface Exit {\n /**\n * Exit code from the shell process.\n */\n exit_code: number;\n\n /**\n * The outcome type. Always `exit`.\n */\n type: 'exit';\n }\n }\n}\n\n/**\n * A tool call to run a function. See the\n * [function calling guide](https://platform.openai.com/docs/guides/function-calling)\n * for more information.\n */\nexport interface ResponseFunctionToolCall {\n /**\n * A JSON string of the arguments to pass to the function.\n */\n arguments: string;\n\n /**\n * The unique ID of the function tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The name of the function to run.\n */\n name: string;\n\n /**\n * The type of the function tool call. Always `function_call`.\n */\n type: 'function_call';\n\n /**\n * The unique ID of the function tool call.\n */\n id?: string;\n\n /**\n * The namespace of the function to run.\n */\n namespace?: string;\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\n/**\n * A tool call to run a function. See the\n * [function calling guide](https://platform.openai.com/docs/guides/function-calling)\n * for more information.\n */\nexport interface ResponseFunctionToolCallItem extends ResponseFunctionToolCall {\n /**\n * The unique ID of the function tool call.\n */\n id: string;\n}\n\nexport interface ResponseFunctionToolCallOutputItem {\n /**\n * The unique ID of the function call tool output.\n */\n id: string;\n\n /**\n * The unique ID of the function tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The output from the function call generated by your code. Can be a string or an\n * list of output content.\n */\n output: string | Array<ResponseInputText | ResponseInputImage | ResponseInputFile>;\n\n /**\n * The type of the function tool call output. Always `function_call_output`.\n */\n type: 'function_call_output';\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\n/**\n * The results of a web search tool call. See the\n * [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for\n * more information.\n */\nexport interface ResponseFunctionWebSearch {\n /**\n * The unique ID of the web search tool call.\n */\n id: string;\n\n /**\n * An object describing the specific action taken in this web search call. Includes\n * details on how the model used the web (search, open_page, find_in_page).\n */\n action:\n | ResponseFunctionWebSearch.Search\n | ResponseFunctionWebSearch.OpenPage\n | ResponseFunctionWebSearch.Find;\n\n /**\n * The status of the web search tool call.\n */\n status: 'in_progress' | 'searching' | 'completed' | 'failed';\n\n /**\n * The type of the web search tool call. Always `web_search_call`.\n */\n type: 'web_search_call';\n}\n\nexport namespace ResponseFunctionWebSearch {\n /**\n * Action type \"search\" - Performs a web search query.\n */\n export interface Search {\n /**\n * [DEPRECATED] The search query.\n */\n query: string;\n\n /**\n * The action type.\n */\n type: 'search';\n\n /**\n * The search queries.\n */\n queries?: Array<string>;\n\n /**\n * The sources used in the search.\n */\n sources?: Array<Search.Source>;\n }\n\n export namespace Search {\n /**\n * A source used in the search.\n */\n export interface Source {\n /**\n * The type of source. Always `url`.\n */\n type: 'url';\n\n /**\n * The URL of the source.\n */\n url: string;\n }\n }\n\n /**\n * Action type \"open_page\" - Opens a specific URL from search results.\n */\n export interface OpenPage {\n /**\n * The action type.\n */\n type: 'open_page';\n\n /**\n * The URL opened by the model.\n */\n url?: string | null;\n }\n\n /**\n * Action type \"find_in_page\": Searches for a pattern within a loaded page.\n */\n export interface Find {\n /**\n * The pattern or text to search for within the page.\n */\n pattern: string;\n\n /**\n * The action type.\n */\n type: 'find_in_page';\n\n /**\n * The URL of the page searched for the pattern.\n */\n url: string;\n }\n}\n\n/**\n * Emitted when an image generation tool call has completed and the final image is\n * available.\n */\nexport interface ResponseImageGenCallCompletedEvent {\n /**\n * The unique identifier of the image generation item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.image_generation_call.completed'.\n */\n type: 'response.image_generation_call.completed';\n}\n\n/**\n * Emitted when an image generation tool call is actively generating an image\n * (intermediate state).\n */\nexport interface ResponseImageGenCallGeneratingEvent {\n /**\n * The unique identifier of the image generation item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of the image generation item being processed.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.image_generation_call.generating'.\n */\n type: 'response.image_generation_call.generating';\n}\n\n/**\n * Emitted when an image generation tool call is in progress.\n */\nexport interface ResponseImageGenCallInProgressEvent {\n /**\n * The unique identifier of the image generation item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of the image generation item being processed.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.image_generation_call.in_progress'.\n */\n type: 'response.image_generation_call.in_progress';\n}\n\n/**\n * Emitted when a partial image is available during image generation streaming.\n */\nexport interface ResponseImageGenCallPartialImageEvent {\n /**\n * The unique identifier of the image generation item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * Base64-encoded partial image data, suitable for rendering as an image.\n */\n partial_image_b64: string;\n\n /**\n * 0-based index for the partial image (backend is 1-based, but this is 0-based for\n * the user).\n */\n partial_image_index: number;\n\n /**\n * The sequence number of the image generation item being processed.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.image_generation_call.partial_image'.\n */\n type: 'response.image_generation_call.partial_image';\n}\n\n/**\n * Emitted when the response is in progress.\n */\nexport interface ResponseInProgressEvent {\n /**\n * The response that is in progress.\n */\n response: Response;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.in_progress`.\n */\n type: 'response.in_progress';\n}\n\n/**\n * Specify additional output data to include in the model response. Currently\n * supported values are:\n *\n * - `web_search_call.action.sources`: Include the sources of the web search tool\n * call.\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n * in code interpreter tool call items.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n * call output.\n * - `file_search_call.results`: Include the search results of the file search tool\n * call.\n * - `message.input_image.image_url`: Include image urls from the input message.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n * call output.\n * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n * tokens in reasoning item outputs. This enables reasoning items to be used in\n * multi-turn conversations when using the Responses API statelessly (like when\n * the `store` parameter is set to `false`, or when an organization is enrolled\n * in the zero data retention program).\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n * in code interpreter tool call items.\n */\nexport type ResponseIncludable =\n | 'file_search_call.results'\n | 'web_search_call.results'\n | 'web_search_call.action.sources'\n | 'message.input_image.image_url'\n | 'computer_call_output.output.image_url'\n | 'code_interpreter_call.outputs'\n | 'reasoning.encrypted_content'\n | 'message.output_text.logprobs';\n\n/**\n * An event that is emitted when a response finishes as incomplete.\n */\nexport interface ResponseIncompleteEvent {\n /**\n * The response that was incomplete.\n */\n response: Response;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.incomplete`.\n */\n type: 'response.incomplete';\n}\n\n/**\n * A list of one or many input items to the model, containing different content\n * types.\n */\nexport type ResponseInput = Array<ResponseInputItem>;\n\n/**\n * An audio input to the model.\n */\nexport interface ResponseInputAudio {\n input_audio: ResponseInputAudio.InputAudio;\n\n /**\n * The type of the input item. Always `input_audio`.\n */\n type: 'input_audio';\n}\n\nexport namespace ResponseInputAudio {\n export interface InputAudio {\n /**\n * Base64-encoded audio data.\n */\n data: string;\n\n /**\n * The format of the audio data. Currently supported formats are `mp3` and `wav`.\n */\n format: 'mp3' | 'wav';\n }\n}\n\n/**\n * A text input to the model.\n */\nexport type ResponseInputContent = ResponseInputText | ResponseInputImage | ResponseInputFile;\n\n/**\n * A file input to the model.\n */\nexport interface ResponseInputFile {\n /**\n * The type of the input item. Always `input_file`.\n */\n type: 'input_file';\n\n /**\n * The detail level of the file to be sent to the model. One of `high` or `low`.\n * Defaults to `high`.\n */\n detail?: 'low' | 'high';\n\n /**\n * The content of the file to be sent to the model.\n */\n file_data?: string;\n\n /**\n * The ID of the file to be sent to the model.\n */\n file_id?: string | null;\n\n /**\n * The URL of the file to be sent to the model.\n */\n file_url?: string;\n\n /**\n * The name of the file to be sent to the model.\n */\n filename?: string;\n}\n\n/**\n * A file input to the model.\n */\nexport interface ResponseInputFileContent {\n /**\n * The type of the input item. Always `input_file`.\n */\n type: 'input_file';\n\n /**\n * The detail level of the file to be sent to the model. One of `high` or `low`.\n * Defaults to `high`.\n */\n detail?: 'high' | 'low';\n\n /**\n * The base64-encoded data of the file to be sent to the model.\n */\n file_data?: string | null;\n\n /**\n * The ID of the file to be sent to the model.\n */\n file_id?: string | null;\n\n /**\n * The URL of the file to be sent to the model.\n */\n file_url?: string | null;\n\n /**\n * The name of the file to be sent to the model.\n */\n filename?: string | null;\n}\n\n/**\n * An image input to the model. Learn about\n * [image inputs](https://platform.openai.com/docs/guides/vision).\n */\nexport interface ResponseInputImage {\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`,\n * `auto`, or `original`. Defaults to `auto`.\n */\n detail: 'low' | 'high' | 'auto' | 'original';\n\n /**\n * The type of the input item. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The ID of the file to be sent to the model.\n */\n file_id?: string | null;\n\n /**\n * The URL of the image to be sent to the model. A fully qualified URL or base64\n * encoded image in a data URL.\n */\n image_url?: string | null;\n}\n\n/**\n * An image input to the model. Learn about\n * [image inputs](https://platform.openai.com/docs/guides/vision)\n */\nexport interface ResponseInputImageContent {\n /**\n * The type of the input item. Always `input_image`.\n */\n type: 'input_image';\n\n /**\n * The detail level of the image to be sent to the model. One of `high`, `low`,\n * `auto`, or `original`. Defaults to `auto`.\n */\n detail?: 'low' | 'high' | 'auto' | 'original' | null;\n\n /**\n * The ID of the file to be sent to the model.\n */\n file_id?: string | null;\n\n /**\n * The URL of the image to be sent to the model. A fully qualified URL or base64\n * encoded image in a data URL.\n */\n image_url?: string | null;\n}\n\n/**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role. Messages with the\n * `assistant` role are presumed to have been generated by the model in previous\n * interactions.\n */\nexport type ResponseInputItem =\n | EasyInputMessage\n | ResponseInputItem.Message\n | ResponseOutputMessage\n | ResponseFileSearchToolCall\n | ResponseComputerToolCall\n | ResponseInputItem.ComputerCallOutput\n | ResponseFunctionWebSearch\n | ResponseFunctionToolCall\n | ResponseInputItem.FunctionCallOutput\n | ResponseInputItem.ToolSearchCall\n | ResponseToolSearchOutputItemParam\n | ResponseReasoningItem\n | ResponseCompactionItemParam\n | ResponseInputItem.ImageGenerationCall\n | ResponseCodeInterpreterToolCall\n | ResponseInputItem.LocalShellCall\n | ResponseInputItem.LocalShellCallOutput\n | ResponseInputItem.ShellCall\n | ResponseInputItem.ShellCallOutput\n | ResponseInputItem.ApplyPatchCall\n | ResponseInputItem.ApplyPatchCallOutput\n | ResponseInputItem.McpListTools\n | ResponseInputItem.McpApprovalRequest\n | ResponseInputItem.McpApprovalResponse\n | ResponseInputItem.McpCall\n | ResponseCustomToolCallOutput\n | ResponseCustomToolCall\n | ResponseInputItem.ItemReference;\n\nexport namespace ResponseInputItem {\n /**\n * A message input to the model with a role indicating instruction following\n * hierarchy. Instructions given with the `developer` or `system` role take\n * precedence over instructions given with the `user` role.\n */\n export interface Message {\n /**\n * A list of one or many input items to the model, containing different content\n * types.\n */\n content: ResponsesAPI.ResponseInputMessageContentList;\n\n /**\n * The role of the message input. One of `user`, `system`, or `developer`.\n */\n role: 'user' | 'system' | 'developer';\n\n /**\n * The status of item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the message input. Always set to `message`.\n */\n type?: 'message';\n }\n\n /**\n * The output of a computer tool call.\n */\n export interface ComputerCallOutput {\n /**\n * The ID of the computer tool call that produced the output.\n */\n call_id: string;\n\n /**\n * A computer screenshot image used with the computer use tool.\n */\n output: ResponsesAPI.ResponseComputerToolCallOutputScreenshot;\n\n /**\n * The type of the computer tool call output. Always `computer_call_output`.\n */\n type: 'computer_call_output';\n\n /**\n * The ID of the computer tool call output.\n */\n id?: string | null;\n\n /**\n * The safety checks reported by the API that have been acknowledged by the\n * developer.\n */\n acknowledged_safety_checks?: Array<ComputerCallOutput.AcknowledgedSafetyCheck> | null;\n\n /**\n * The status of the message input. One of `in_progress`, `completed`, or\n * `incomplete`. Populated when input items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n export namespace ComputerCallOutput {\n /**\n * A pending safety check for the computer call.\n */\n export interface AcknowledgedSafetyCheck {\n /**\n * The ID of the pending safety check.\n */\n id: string;\n\n /**\n * The type of the pending safety check.\n */\n code?: string | null;\n\n /**\n * Details about the pending safety check.\n */\n message?: string | null;\n }\n }\n\n /**\n * The output of a function tool call.\n */\n export interface FunctionCallOutput {\n /**\n * The unique ID of the function tool call generated by the model.\n */\n call_id: string;\n\n /**\n * Text, image, or file output of the function tool call.\n */\n output: string | ResponsesAPI.ResponseFunctionCallOutputItemList;\n\n /**\n * The type of the function tool call output. Always `function_call_output`.\n */\n type: 'function_call_output';\n\n /**\n * The unique ID of the function tool call output. Populated when this item is\n * returned via API.\n */\n id?: string | null;\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n export interface ToolSearchCall {\n /**\n * The arguments supplied to the tool search call.\n */\n arguments: unknown;\n\n /**\n * The item type. Always `tool_search_call`.\n */\n type: 'tool_search_call';\n\n /**\n * The unique ID of this tool search call.\n */\n id?: string | null;\n\n /**\n * The unique ID of the tool search call generated by the model.\n */\n call_id?: string | null;\n\n /**\n * Whether tool search was executed by the server or by the client.\n */\n execution?: 'server' | 'client';\n\n /**\n * The status of the tool search call.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n /**\n * An image generation request made by the model.\n */\n export interface ImageGenerationCall {\n /**\n * The unique ID of the image generation call.\n */\n id: string;\n\n /**\n * The generated image encoded in base64.\n */\n result: string | null;\n\n /**\n * The status of the image generation call.\n */\n status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n /**\n * The type of the image generation call. Always `image_generation_call`.\n */\n type: 'image_generation_call';\n }\n\n /**\n * A tool call to run a command on the local shell.\n */\n export interface LocalShellCall {\n /**\n * The unique ID of the local shell call.\n */\n id: string;\n\n /**\n * Execute a shell command on the server.\n */\n action: LocalShellCall.Action;\n\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The status of the local shell call.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the local shell call. Always `local_shell_call`.\n */\n type: 'local_shell_call';\n }\n\n export namespace LocalShellCall {\n /**\n * Execute a shell command on the server.\n */\n export interface Action {\n /**\n * The command to run.\n */\n command: Array<string>;\n\n /**\n * Environment variables to set for the command.\n */\n env: { [key: string]: string };\n\n /**\n * The type of the local shell action. Always `exec`.\n */\n type: 'exec';\n\n /**\n * Optional timeout in milliseconds for the command.\n */\n timeout_ms?: number | null;\n\n /**\n * Optional user to run the command as.\n */\n user?: string | null;\n\n /**\n * Optional working directory to run the command in.\n */\n working_directory?: string | null;\n }\n }\n\n /**\n * The output of a local shell tool call.\n */\n export interface LocalShellCallOutput {\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n id: string;\n\n /**\n * A JSON string of the output of the local shell tool call.\n */\n output: string;\n\n /**\n * The type of the local shell tool call output. Always `local_shell_call_output`.\n */\n type: 'local_shell_call_output';\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n /**\n * A tool representing a request to execute one or more shell commands.\n */\n export interface ShellCall {\n /**\n * The shell commands and limits that describe how to run the tool call.\n */\n action: ShellCall.Action;\n\n /**\n * The unique ID of the shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The type of the item. Always `shell_call`.\n */\n type: 'shell_call';\n\n /**\n * The unique ID of the shell tool call. Populated when this item is returned via\n * API.\n */\n id?: string | null;\n\n /**\n * The environment to execute the shell commands in.\n */\n environment?: ResponsesAPI.LocalEnvironment | ResponsesAPI.ContainerReference | null;\n\n /**\n * The status of the shell call. One of `in_progress`, `completed`, or\n * `incomplete`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n export namespace ShellCall {\n /**\n * The shell commands and limits that describe how to run the tool call.\n */\n export interface Action {\n /**\n * Ordered shell commands for the execution environment to run.\n */\n commands: Array<string>;\n\n /**\n * Maximum number of UTF-8 characters to capture from combined stdout and stderr\n * output.\n */\n max_output_length?: number | null;\n\n /**\n * Maximum wall-clock time in milliseconds to allow the shell commands to run.\n */\n timeout_ms?: number | null;\n }\n }\n\n /**\n * The streamed output items emitted by a shell tool call.\n */\n export interface ShellCallOutput {\n /**\n * The unique ID of the shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * Captured chunks of stdout and stderr output, along with their associated\n * outcomes.\n */\n output: Array<ResponsesAPI.ResponseFunctionShellCallOutputContent>;\n\n /**\n * The type of the item. Always `shell_call_output`.\n */\n type: 'shell_call_output';\n\n /**\n * The unique ID of the shell tool call output. Populated when this item is\n * returned via API.\n */\n id?: string | null;\n\n /**\n * The maximum number of UTF-8 characters captured for this shell call's combined\n * output.\n */\n max_output_length?: number | null;\n\n /**\n * The status of the shell call output.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n /**\n * A tool call representing a request to create, delete, or update files using diff\n * patches.\n */\n export interface ApplyPatchCall {\n /**\n * The unique ID of the apply patch tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The specific create, delete, or update instruction for the apply_patch tool\n * call.\n */\n operation: ApplyPatchCall.CreateFile | ApplyPatchCall.DeleteFile | ApplyPatchCall.UpdateFile;\n\n /**\n * The status of the apply patch tool call. One of `in_progress` or `completed`.\n */\n status: 'in_progress' | 'completed';\n\n /**\n * The type of the item. Always `apply_patch_call`.\n */\n type: 'apply_patch_call';\n\n /**\n * The unique ID of the apply patch tool call. Populated when this item is returned\n * via API.\n */\n id?: string | null;\n }\n\n export namespace ApplyPatchCall {\n /**\n * Instruction for creating a new file via the apply_patch tool.\n */\n export interface CreateFile {\n /**\n * Unified diff content to apply when creating the file.\n */\n diff: string;\n\n /**\n * Path of the file to create relative to the workspace root.\n */\n path: string;\n\n /**\n * The operation type. Always `create_file`.\n */\n type: 'create_file';\n }\n\n /**\n * Instruction for deleting an existing file via the apply_patch tool.\n */\n export interface DeleteFile {\n /**\n * Path of the file to delete relative to the workspace root.\n */\n path: string;\n\n /**\n * The operation type. Always `delete_file`.\n */\n type: 'delete_file';\n }\n\n /**\n * Instruction for updating an existing file via the apply_patch tool.\n */\n export interface UpdateFile {\n /**\n * Unified diff content to apply to the existing file.\n */\n diff: string;\n\n /**\n * Path of the file to update relative to the workspace root.\n */\n path: string;\n\n /**\n * The operation type. Always `update_file`.\n */\n type: 'update_file';\n }\n }\n\n /**\n * The streamed output emitted by an apply patch tool call.\n */\n export interface ApplyPatchCallOutput {\n /**\n * The unique ID of the apply patch tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The status of the apply patch tool call output. One of `completed` or `failed`.\n */\n status: 'completed' | 'failed';\n\n /**\n * The type of the item. Always `apply_patch_call_output`.\n */\n type: 'apply_patch_call_output';\n\n /**\n * The unique ID of the apply patch tool call output. Populated when this item is\n * returned via API.\n */\n id?: string | null;\n\n /**\n * Optional human-readable log text from the apply patch tool (e.g., patch results\n * or errors).\n */\n output?: string | null;\n }\n\n /**\n * A list of tools available on an MCP server.\n */\n export interface McpListTools {\n /**\n * The unique ID of the list.\n */\n id: string;\n\n /**\n * The label of the MCP server.\n */\n server_label: string;\n\n /**\n * The tools available on the server.\n */\n tools: Array<McpListTools.Tool>;\n\n /**\n * The type of the item. Always `mcp_list_tools`.\n */\n type: 'mcp_list_tools';\n\n /**\n * Error message if the server could not list tools.\n */\n error?: string | null;\n }\n\n export namespace McpListTools {\n /**\n * A tool available on an MCP server.\n */\n export interface Tool {\n /**\n * The JSON schema describing the tool's input.\n */\n input_schema: unknown;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * Additional annotations about the tool.\n */\n annotations?: unknown | null;\n\n /**\n * The description of the tool.\n */\n description?: string | null;\n }\n }\n\n /**\n * A request for human approval of a tool invocation.\n */\n export interface McpApprovalRequest {\n /**\n * The unique ID of the approval request.\n */\n id: string;\n\n /**\n * A JSON string of arguments for the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool to run.\n */\n name: string;\n\n /**\n * The label of the MCP server making the request.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_approval_request`.\n */\n type: 'mcp_approval_request';\n }\n\n /**\n * A response to an MCP approval request.\n */\n export interface McpApprovalResponse {\n /**\n * The ID of the approval request being answered.\n */\n approval_request_id: string;\n\n /**\n * Whether the request was approved.\n */\n approve: boolean;\n\n /**\n * The type of the item. Always `mcp_approval_response`.\n */\n type: 'mcp_approval_response';\n\n /**\n * The unique ID of the approval response\n */\n id?: string | null;\n\n /**\n * Optional reason for the decision.\n */\n reason?: string | null;\n }\n\n /**\n * An invocation of a tool on an MCP server.\n */\n export interface McpCall {\n /**\n * The unique ID of the tool call.\n */\n id: string;\n\n /**\n * A JSON string of the arguments passed to the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool that was run.\n */\n name: string;\n\n /**\n * The label of the MCP server running the tool.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_call`.\n */\n type: 'mcp_call';\n\n /**\n * Unique identifier for the MCP tool call approval request. Include this value in\n * a subsequent `mcp_approval_response` input to approve or reject the\n * corresponding tool call.\n */\n approval_request_id?: string | null;\n\n /**\n * The error from the tool call, if any.\n */\n error?: string | null;\n\n /**\n * The output from the tool call.\n */\n output?: string | null;\n\n /**\n * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n * `calling`, or `failed`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n }\n\n /**\n * An internal identifier for an item to reference.\n */\n export interface ItemReference {\n /**\n * The ID of the item to reference.\n */\n id: string;\n\n /**\n * The type of item to reference. Always `item_reference`.\n */\n type?: 'item_reference' | null;\n }\n}\n\n/**\n * A list of one or many input items to the model, containing different content\n * types.\n */\nexport type ResponseInputMessageContentList = Array<ResponseInputContent>;\n\nexport interface ResponseInputMessageItem {\n /**\n * The unique ID of the message input.\n */\n id: string;\n\n /**\n * A list of one or many input items to the model, containing different content\n * types.\n */\n content: ResponseInputMessageContentList;\n\n /**\n * The role of the message input. One of `user`, `system`, or `developer`.\n */\n role: 'user' | 'system' | 'developer';\n\n /**\n * The status of item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the message input. Always set to `message`.\n */\n type?: 'message';\n}\n\n/**\n * A text input to the model.\n */\nexport interface ResponseInputText {\n /**\n * The text input to the model.\n */\n text: string;\n\n /**\n * The type of the input item. Always `input_text`.\n */\n type: 'input_text';\n}\n\n/**\n * A text input to the model.\n */\nexport interface ResponseInputTextContent {\n /**\n * The text input to the model.\n */\n text: string;\n\n /**\n * The type of the input item. Always `input_text`.\n */\n type: 'input_text';\n}\n\n/**\n * Content item used to generate a response.\n */\nexport type ResponseItem =\n | ResponseInputMessageItem\n | ResponseOutputMessage\n | ResponseFileSearchToolCall\n | ResponseComputerToolCall\n | ResponseComputerToolCallOutputItem\n | ResponseFunctionWebSearch\n | ResponseFunctionToolCallItem\n | ResponseFunctionToolCallOutputItem\n | ResponseToolSearchCall\n | ResponseToolSearchOutputItem\n | ResponseItem.ImageGenerationCall\n | ResponseCodeInterpreterToolCall\n | ResponseItem.LocalShellCall\n | ResponseItem.LocalShellCallOutput\n | ResponseFunctionShellToolCall\n | ResponseFunctionShellToolCallOutput\n | ResponseApplyPatchToolCall\n | ResponseApplyPatchToolCallOutput\n | ResponseItem.McpListTools\n | ResponseItem.McpApprovalRequest\n | ResponseItem.McpApprovalResponse\n | ResponseItem.McpCall;\n\nexport namespace ResponseItem {\n /**\n * An image generation request made by the model.\n */\n export interface ImageGenerationCall {\n /**\n * The unique ID of the image generation call.\n */\n id: string;\n\n /**\n * The generated image encoded in base64.\n */\n result: string | null;\n\n /**\n * The status of the image generation call.\n */\n status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n /**\n * The type of the image generation call. Always `image_generation_call`.\n */\n type: 'image_generation_call';\n }\n\n /**\n * A tool call to run a command on the local shell.\n */\n export interface LocalShellCall {\n /**\n * The unique ID of the local shell call.\n */\n id: string;\n\n /**\n * Execute a shell command on the server.\n */\n action: LocalShellCall.Action;\n\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The status of the local shell call.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the local shell call. Always `local_shell_call`.\n */\n type: 'local_shell_call';\n }\n\n export namespace LocalShellCall {\n /**\n * Execute a shell command on the server.\n */\n export interface Action {\n /**\n * The command to run.\n */\n command: Array<string>;\n\n /**\n * Environment variables to set for the command.\n */\n env: { [key: string]: string };\n\n /**\n * The type of the local shell action. Always `exec`.\n */\n type: 'exec';\n\n /**\n * Optional timeout in milliseconds for the command.\n */\n timeout_ms?: number | null;\n\n /**\n * Optional user to run the command as.\n */\n user?: string | null;\n\n /**\n * Optional working directory to run the command in.\n */\n working_directory?: string | null;\n }\n }\n\n /**\n * The output of a local shell tool call.\n */\n export interface LocalShellCallOutput {\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n id: string;\n\n /**\n * A JSON string of the output of the local shell tool call.\n */\n output: string;\n\n /**\n * The type of the local shell tool call output. Always `local_shell_call_output`.\n */\n type: 'local_shell_call_output';\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n }\n\n /**\n * A list of tools available on an MCP server.\n */\n export interface McpListTools {\n /**\n * The unique ID of the list.\n */\n id: string;\n\n /**\n * The label of the MCP server.\n */\n server_label: string;\n\n /**\n * The tools available on the server.\n */\n tools: Array<McpListTools.Tool>;\n\n /**\n * The type of the item. Always `mcp_list_tools`.\n */\n type: 'mcp_list_tools';\n\n /**\n * Error message if the server could not list tools.\n */\n error?: string | null;\n }\n\n export namespace McpListTools {\n /**\n * A tool available on an MCP server.\n */\n export interface Tool {\n /**\n * The JSON schema describing the tool's input.\n */\n input_schema: unknown;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * Additional annotations about the tool.\n */\n annotations?: unknown | null;\n\n /**\n * The description of the tool.\n */\n description?: string | null;\n }\n }\n\n /**\n * A request for human approval of a tool invocation.\n */\n export interface McpApprovalRequest {\n /**\n * The unique ID of the approval request.\n */\n id: string;\n\n /**\n * A JSON string of arguments for the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool to run.\n */\n name: string;\n\n /**\n * The label of the MCP server making the request.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_approval_request`.\n */\n type: 'mcp_approval_request';\n }\n\n /**\n * A response to an MCP approval request.\n */\n export interface McpApprovalResponse {\n /**\n * The unique ID of the approval response\n */\n id: string;\n\n /**\n * The ID of the approval request being answered.\n */\n approval_request_id: string;\n\n /**\n * Whether the request was approved.\n */\n approve: boolean;\n\n /**\n * The type of the item. Always `mcp_approval_response`.\n */\n type: 'mcp_approval_response';\n\n /**\n * Optional reason for the decision.\n */\n reason?: string | null;\n }\n\n /**\n * An invocation of a tool on an MCP server.\n */\n export interface McpCall {\n /**\n * The unique ID of the tool call.\n */\n id: string;\n\n /**\n * A JSON string of the arguments passed to the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool that was run.\n */\n name: string;\n\n /**\n * The label of the MCP server running the tool.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_call`.\n */\n type: 'mcp_call';\n\n /**\n * Unique identifier for the MCP tool call approval request. Include this value in\n * a subsequent `mcp_approval_response` input to approve or reject the\n * corresponding tool call.\n */\n approval_request_id?: string | null;\n\n /**\n * The error from the tool call, if any.\n */\n error?: string | null;\n\n /**\n * The output from the tool call.\n */\n output?: string | null;\n\n /**\n * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n * `calling`, or `failed`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n }\n}\n\n/**\n * Represents the use of a local environment to perform shell actions.\n */\nexport interface ResponseLocalEnvironment {\n /**\n * The environment type. Always `local`.\n */\n type: 'local';\n}\n\n/**\n * Emitted when there is a delta (partial update) to the arguments of an MCP tool\n * call.\n */\nexport interface ResponseMcpCallArgumentsDeltaEvent {\n /**\n * A JSON string containing the partial update to the arguments for the MCP tool\n * call.\n */\n delta: string;\n\n /**\n * The unique identifier of the MCP tool call item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_call_arguments.delta'.\n */\n type: 'response.mcp_call_arguments.delta';\n}\n\n/**\n * Emitted when the arguments for an MCP tool call are finalized.\n */\nexport interface ResponseMcpCallArgumentsDoneEvent {\n /**\n * A JSON string containing the finalized arguments for the MCP tool call.\n */\n arguments: string;\n\n /**\n * The unique identifier of the MCP tool call item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_call_arguments.done'.\n */\n type: 'response.mcp_call_arguments.done';\n}\n\n/**\n * Emitted when an MCP tool call has completed successfully.\n */\nexport interface ResponseMcpCallCompletedEvent {\n /**\n * The ID of the MCP tool call item that completed.\n */\n item_id: string;\n\n /**\n * The index of the output item that completed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_call.completed'.\n */\n type: 'response.mcp_call.completed';\n}\n\n/**\n * Emitted when an MCP tool call has failed.\n */\nexport interface ResponseMcpCallFailedEvent {\n /**\n * The ID of the MCP tool call item that failed.\n */\n item_id: string;\n\n /**\n * The index of the output item that failed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_call.failed'.\n */\n type: 'response.mcp_call.failed';\n}\n\n/**\n * Emitted when an MCP tool call is in progress.\n */\nexport interface ResponseMcpCallInProgressEvent {\n /**\n * The unique identifier of the MCP tool call item being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_call.in_progress'.\n */\n type: 'response.mcp_call.in_progress';\n}\n\n/**\n * Emitted when the list of available MCP tools has been successfully retrieved.\n */\nexport interface ResponseMcpListToolsCompletedEvent {\n /**\n * The ID of the MCP tool call item that produced this output.\n */\n item_id: string;\n\n /**\n * The index of the output item that was processed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_list_tools.completed'.\n */\n type: 'response.mcp_list_tools.completed';\n}\n\n/**\n * Emitted when the attempt to list available MCP tools has failed.\n */\nexport interface ResponseMcpListToolsFailedEvent {\n /**\n * The ID of the MCP tool call item that failed.\n */\n item_id: string;\n\n /**\n * The index of the output item that failed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_list_tools.failed'.\n */\n type: 'response.mcp_list_tools.failed';\n}\n\n/**\n * Emitted when the system is in the process of retrieving the list of available\n * MCP tools.\n */\nexport interface ResponseMcpListToolsInProgressEvent {\n /**\n * The ID of the MCP tool call item that is being processed.\n */\n item_id: string;\n\n /**\n * The index of the output item that is being processed.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.mcp_list_tools.in_progress'.\n */\n type: 'response.mcp_list_tools.in_progress';\n}\n\n/**\n * An audio output from the model.\n */\nexport interface ResponseOutputAudio {\n /**\n * Base64-encoded audio data from the model.\n */\n data: string;\n\n /**\n * The transcript of the audio data from the model.\n */\n transcript: string;\n\n /**\n * The type of the output audio. Always `output_audio`.\n */\n type: 'output_audio';\n}\n\n/**\n * An output message from the model.\n */\nexport type ResponseOutputItem =\n | ResponseOutputMessage\n | ResponseFileSearchToolCall\n | ResponseFunctionToolCall\n | ResponseFunctionWebSearch\n | ResponseComputerToolCall\n | ResponseReasoningItem\n | ResponseToolSearchCall\n | ResponseToolSearchOutputItem\n | ResponseCompactionItem\n | ResponseOutputItem.ImageGenerationCall\n | ResponseCodeInterpreterToolCall\n | ResponseOutputItem.LocalShellCall\n | ResponseFunctionShellToolCall\n | ResponseFunctionShellToolCallOutput\n | ResponseApplyPatchToolCall\n | ResponseApplyPatchToolCallOutput\n | ResponseOutputItem.McpCall\n | ResponseOutputItem.McpListTools\n | ResponseOutputItem.McpApprovalRequest\n | ResponseCustomToolCall;\n\nexport namespace ResponseOutputItem {\n /**\n * An image generation request made by the model.\n */\n export interface ImageGenerationCall {\n /**\n * The unique ID of the image generation call.\n */\n id: string;\n\n /**\n * The generated image encoded in base64.\n */\n result: string | null;\n\n /**\n * The status of the image generation call.\n */\n status: 'in_progress' | 'completed' | 'generating' | 'failed';\n\n /**\n * The type of the image generation call. Always `image_generation_call`.\n */\n type: 'image_generation_call';\n }\n\n /**\n * A tool call to run a command on the local shell.\n */\n export interface LocalShellCall {\n /**\n * The unique ID of the local shell call.\n */\n id: string;\n\n /**\n * Execute a shell command on the server.\n */\n action: LocalShellCall.Action;\n\n /**\n * The unique ID of the local shell tool call generated by the model.\n */\n call_id: string;\n\n /**\n * The status of the local shell call.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the local shell call. Always `local_shell_call`.\n */\n type: 'local_shell_call';\n }\n\n export namespace LocalShellCall {\n /**\n * Execute a shell command on the server.\n */\n export interface Action {\n /**\n * The command to run.\n */\n command: Array<string>;\n\n /**\n * Environment variables to set for the command.\n */\n env: { [key: string]: string };\n\n /**\n * The type of the local shell action. Always `exec`.\n */\n type: 'exec';\n\n /**\n * Optional timeout in milliseconds for the command.\n */\n timeout_ms?: number | null;\n\n /**\n * Optional user to run the command as.\n */\n user?: string | null;\n\n /**\n * Optional working directory to run the command in.\n */\n working_directory?: string | null;\n }\n }\n\n /**\n * An invocation of a tool on an MCP server.\n */\n export interface McpCall {\n /**\n * The unique ID of the tool call.\n */\n id: string;\n\n /**\n * A JSON string of the arguments passed to the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool that was run.\n */\n name: string;\n\n /**\n * The label of the MCP server running the tool.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_call`.\n */\n type: 'mcp_call';\n\n /**\n * Unique identifier for the MCP tool call approval request. Include this value in\n * a subsequent `mcp_approval_response` input to approve or reject the\n * corresponding tool call.\n */\n approval_request_id?: string | null;\n\n /**\n * The error from the tool call, if any.\n */\n error?: string | null;\n\n /**\n * The output from the tool call.\n */\n output?: string | null;\n\n /**\n * The status of the tool call. One of `in_progress`, `completed`, `incomplete`,\n * `calling`, or `failed`.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | 'calling' | 'failed';\n }\n\n /**\n * A list of tools available on an MCP server.\n */\n export interface McpListTools {\n /**\n * The unique ID of the list.\n */\n id: string;\n\n /**\n * The label of the MCP server.\n */\n server_label: string;\n\n /**\n * The tools available on the server.\n */\n tools: Array<McpListTools.Tool>;\n\n /**\n * The type of the item. Always `mcp_list_tools`.\n */\n type: 'mcp_list_tools';\n\n /**\n * Error message if the server could not list tools.\n */\n error?: string | null;\n }\n\n export namespace McpListTools {\n /**\n * A tool available on an MCP server.\n */\n export interface Tool {\n /**\n * The JSON schema describing the tool's input.\n */\n input_schema: unknown;\n\n /**\n * The name of the tool.\n */\n name: string;\n\n /**\n * Additional annotations about the tool.\n */\n annotations?: unknown | null;\n\n /**\n * The description of the tool.\n */\n description?: string | null;\n }\n }\n\n /**\n * A request for human approval of a tool invocation.\n */\n export interface McpApprovalRequest {\n /**\n * The unique ID of the approval request.\n */\n id: string;\n\n /**\n * A JSON string of arguments for the tool.\n */\n arguments: string;\n\n /**\n * The name of the tool to run.\n */\n name: string;\n\n /**\n * The label of the MCP server making the request.\n */\n server_label: string;\n\n /**\n * The type of the item. Always `mcp_approval_request`.\n */\n type: 'mcp_approval_request';\n }\n}\n\n/**\n * Emitted when a new output item is added.\n */\nexport interface ResponseOutputItemAddedEvent {\n /**\n * The output item that was added.\n */\n item: ResponseOutputItem;\n\n /**\n * The index of the output item that was added.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.output_item.added`.\n */\n type: 'response.output_item.added';\n}\n\n/**\n * Emitted when an output item is marked done.\n */\nexport interface ResponseOutputItemDoneEvent {\n /**\n * The output item that was marked done.\n */\n item: ResponseOutputItem;\n\n /**\n * The index of the output item that was marked done.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.output_item.done`.\n */\n type: 'response.output_item.done';\n}\n\n/**\n * An output message from the model.\n */\nexport interface ResponseOutputMessage {\n /**\n * The unique ID of the output message.\n */\n id: string;\n\n /**\n * The content of the output message.\n */\n content: Array<ResponseOutputText | ResponseOutputRefusal>;\n\n /**\n * The role of the output message. Always `assistant`.\n */\n role: 'assistant';\n\n /**\n * The status of the message input. One of `in_progress`, `completed`, or\n * `incomplete`. Populated when input items are returned via API.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the output message. Always `message`.\n */\n type: 'message';\n\n /**\n * Labels an `assistant` message as intermediate commentary (`commentary`) or the\n * final answer (`final_answer`). For models like `gpt-5.3-codex` and beyond, when\n * sending follow-up requests, preserve and resend phase on all assistant messages\n * — dropping it can degrade performance. Not used for user messages.\n */\n phase?: 'commentary' | 'final_answer' | null;\n}\n\n/**\n * A refusal from the model.\n */\nexport interface ResponseOutputRefusal {\n /**\n * The refusal explanation from the model.\n */\n refusal: string;\n\n /**\n * The type of the refusal. Always `refusal`.\n */\n type: 'refusal';\n}\n\n/**\n * A text output from the model.\n */\nexport interface ResponseOutputText {\n /**\n * The annotations of the text output.\n */\n annotations: Array<\n | ResponseOutputText.FileCitation\n | ResponseOutputText.URLCitation\n | ResponseOutputText.ContainerFileCitation\n | ResponseOutputText.FilePath\n >;\n\n /**\n * The text output from the model.\n */\n text: string;\n\n /**\n * The type of the output text. Always `output_text`.\n */\n type: 'output_text';\n\n logprobs?: Array<ResponseOutputText.Logprob>;\n}\n\nexport namespace ResponseOutputText {\n /**\n * A citation to a file.\n */\n export interface FileCitation {\n /**\n * The ID of the file.\n */\n file_id: string;\n\n /**\n * The filename of the file cited.\n */\n filename: string;\n\n /**\n * The index of the file in the list of files.\n */\n index: number;\n\n /**\n * The type of the file citation. Always `file_citation`.\n */\n type: 'file_citation';\n }\n\n /**\n * A citation for a web resource used to generate a model response.\n */\n export interface URLCitation {\n /**\n * The index of the last character of the URL citation in the message.\n */\n end_index: number;\n\n /**\n * The index of the first character of the URL citation in the message.\n */\n start_index: number;\n\n /**\n * The title of the web resource.\n */\n title: string;\n\n /**\n * The type of the URL citation. Always `url_citation`.\n */\n type: 'url_citation';\n\n /**\n * The URL of the web resource.\n */\n url: string;\n }\n\n /**\n * A citation for a container file used to generate a model response.\n */\n export interface ContainerFileCitation {\n /**\n * The ID of the container file.\n */\n container_id: string;\n\n /**\n * The index of the last character of the container file citation in the message.\n */\n end_index: number;\n\n /**\n * The ID of the file.\n */\n file_id: string;\n\n /**\n * The filename of the container file cited.\n */\n filename: string;\n\n /**\n * The index of the first character of the container file citation in the message.\n */\n start_index: number;\n\n /**\n * The type of the container file citation. Always `container_file_citation`.\n */\n type: 'container_file_citation';\n }\n\n /**\n * A path to a file.\n */\n export interface FilePath {\n /**\n * The ID of the file.\n */\n file_id: string;\n\n /**\n * The index of the file in the list of files.\n */\n index: number;\n\n /**\n * The type of the file path. Always `file_path`.\n */\n type: 'file_path';\n }\n\n /**\n * The log probability of a token.\n */\n export interface Logprob {\n token: string;\n\n bytes: Array<number>;\n\n logprob: number;\n\n top_logprobs: Array<Logprob.TopLogprob>;\n }\n\n export namespace Logprob {\n /**\n * The top log probability of a token.\n */\n export interface TopLogprob {\n token: string;\n\n bytes: Array<number>;\n\n logprob: number;\n }\n }\n}\n\n/**\n * Emitted when an annotation is added to output text content.\n */\nexport interface ResponseOutputTextAnnotationAddedEvent {\n /**\n * The annotation object being added. (See annotation schema for details.)\n */\n annotation: unknown;\n\n /**\n * The index of the annotation within the content part.\n */\n annotation_index: number;\n\n /**\n * The index of the content part within the output item.\n */\n content_index: number;\n\n /**\n * The unique identifier of the item to which the annotation is being added.\n */\n item_id: string;\n\n /**\n * The index of the output item in the response's output array.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.output_text.annotation.added'.\n */\n type: 'response.output_text.annotation.added';\n}\n\n/**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\nexport interface ResponsePrompt {\n /**\n * The unique identifier of the prompt template to use.\n */\n id: string;\n\n /**\n * Optional map of values to substitute in for variables in your prompt. The\n * substitution values can either be strings, or other Response input types like\n * images or files.\n */\n variables?: { [key: string]: string | ResponseInputText | ResponseInputImage | ResponseInputFile } | null;\n\n /**\n * Optional version of the prompt template.\n */\n version?: string | null;\n}\n\n/**\n * Emitted when a response is queued and waiting to be processed.\n */\nexport interface ResponseQueuedEvent {\n /**\n * The full response object that is queued.\n */\n response: Response;\n\n /**\n * The sequence number for this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always 'response.queued'.\n */\n type: 'response.queued';\n}\n\n/**\n * A description of the chain of thought used by a reasoning model while generating\n * a response. Be sure to include these items in your `input` to the Responses API\n * for subsequent turns of a conversation if you are manually\n * [managing context](https://platform.openai.com/docs/guides/conversation-state).\n */\nexport interface ResponseReasoningItem {\n /**\n * The unique identifier of the reasoning content.\n */\n id: string;\n\n /**\n * Reasoning summary content.\n */\n summary: Array<ResponseReasoningItem.Summary>;\n\n /**\n * The type of the object. Always `reasoning`.\n */\n type: 'reasoning';\n\n /**\n * Reasoning text content.\n */\n content?: Array<ResponseReasoningItem.Content>;\n\n /**\n * The encrypted content of the reasoning item - populated when a response is\n * generated with `reasoning.encrypted_content` in the `include` parameter.\n */\n encrypted_content?: string | null;\n\n /**\n * The status of the item. One of `in_progress`, `completed`, or `incomplete`.\n * Populated when items are returned via API.\n */\n status?: 'in_progress' | 'completed' | 'incomplete';\n}\n\nexport namespace ResponseReasoningItem {\n /**\n * A summary text from the model.\n */\n export interface Summary {\n /**\n * A summary of the reasoning output from the model so far.\n */\n text: string;\n\n /**\n * The type of the object. Always `summary_text`.\n */\n type: 'summary_text';\n }\n\n /**\n * Reasoning text from the model.\n */\n export interface Content {\n /**\n * The reasoning text from the model.\n */\n text: string;\n\n /**\n * The type of the reasoning text. Always `reasoning_text`.\n */\n type: 'reasoning_text';\n }\n}\n\n/**\n * Emitted when a new reasoning summary part is added.\n */\nexport interface ResponseReasoningSummaryPartAddedEvent {\n /**\n * The ID of the item this summary part is associated with.\n */\n item_id: string;\n\n /**\n * The index of the output item this summary part is associated with.\n */\n output_index: number;\n\n /**\n * The summary part that was added.\n */\n part: ResponseReasoningSummaryPartAddedEvent.Part;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The index of the summary part within the reasoning summary.\n */\n summary_index: number;\n\n /**\n * The type of the event. Always `response.reasoning_summary_part.added`.\n */\n type: 'response.reasoning_summary_part.added';\n}\n\nexport namespace ResponseReasoningSummaryPartAddedEvent {\n /**\n * The summary part that was added.\n */\n export interface Part {\n /**\n * The text of the summary part.\n */\n text: string;\n\n /**\n * The type of the summary part. Always `summary_text`.\n */\n type: 'summary_text';\n }\n}\n\n/**\n * Emitted when a reasoning summary part is completed.\n */\nexport interface ResponseReasoningSummaryPartDoneEvent {\n /**\n * The ID of the item this summary part is associated with.\n */\n item_id: string;\n\n /**\n * The index of the output item this summary part is associated with.\n */\n output_index: number;\n\n /**\n * The completed summary part.\n */\n part: ResponseReasoningSummaryPartDoneEvent.Part;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The index of the summary part within the reasoning summary.\n */\n summary_index: number;\n\n /**\n * The type of the event. Always `response.reasoning_summary_part.done`.\n */\n type: 'response.reasoning_summary_part.done';\n}\n\nexport namespace ResponseReasoningSummaryPartDoneEvent {\n /**\n * The completed summary part.\n */\n export interface Part {\n /**\n * The text of the summary part.\n */\n text: string;\n\n /**\n * The type of the summary part. Always `summary_text`.\n */\n type: 'summary_text';\n }\n}\n\n/**\n * Emitted when a delta is added to a reasoning summary text.\n */\nexport interface ResponseReasoningSummaryTextDeltaEvent {\n /**\n * The text delta that was added to the summary.\n */\n delta: string;\n\n /**\n * The ID of the item this summary text delta is associated with.\n */\n item_id: string;\n\n /**\n * The index of the output item this summary text delta is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The index of the summary part within the reasoning summary.\n */\n summary_index: number;\n\n /**\n * The type of the event. Always `response.reasoning_summary_text.delta`.\n */\n type: 'response.reasoning_summary_text.delta';\n}\n\n/**\n * Emitted when a reasoning summary text is completed.\n */\nexport interface ResponseReasoningSummaryTextDoneEvent {\n /**\n * The ID of the item this summary text is associated with.\n */\n item_id: string;\n\n /**\n * The index of the output item this summary text is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The index of the summary part within the reasoning summary.\n */\n summary_index: number;\n\n /**\n * The full text of the completed reasoning summary.\n */\n text: string;\n\n /**\n * The type of the event. Always `response.reasoning_summary_text.done`.\n */\n type: 'response.reasoning_summary_text.done';\n}\n\n/**\n * Emitted when a delta is added to a reasoning text.\n */\nexport interface ResponseReasoningTextDeltaEvent {\n /**\n * The index of the reasoning content part this delta is associated with.\n */\n content_index: number;\n\n /**\n * The text delta that was added to the reasoning content.\n */\n delta: string;\n\n /**\n * The ID of the item this reasoning text delta is associated with.\n */\n item_id: string;\n\n /**\n * The index of the output item this reasoning text delta is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.reasoning_text.delta`.\n */\n type: 'response.reasoning_text.delta';\n}\n\n/**\n * Emitted when a reasoning text is completed.\n */\nexport interface ResponseReasoningTextDoneEvent {\n /**\n * The index of the reasoning content part.\n */\n content_index: number;\n\n /**\n * The ID of the item this reasoning text is associated with.\n */\n item_id: string;\n\n /**\n * The index of the output item this reasoning text is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The full text of the completed reasoning content.\n */\n text: string;\n\n /**\n * The type of the event. Always `response.reasoning_text.done`.\n */\n type: 'response.reasoning_text.done';\n}\n\n/**\n * Emitted when there is a partial refusal text.\n */\nexport interface ResponseRefusalDeltaEvent {\n /**\n * The index of the content part that the refusal text is added to.\n */\n content_index: number;\n\n /**\n * The refusal text that is added.\n */\n delta: string;\n\n /**\n * The ID of the output item that the refusal text is added to.\n */\n item_id: string;\n\n /**\n * The index of the output item that the refusal text is added to.\n */\n output_index: number;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.refusal.delta`.\n */\n type: 'response.refusal.delta';\n}\n\n/**\n * Emitted when refusal text is finalized.\n */\nexport interface ResponseRefusalDoneEvent {\n /**\n * The index of the content part that the refusal text is finalized.\n */\n content_index: number;\n\n /**\n * The ID of the output item that the refusal text is finalized.\n */\n item_id: string;\n\n /**\n * The index of the output item that the refusal text is finalized.\n */\n output_index: number;\n\n /**\n * The refusal text that is finalized.\n */\n refusal: string;\n\n /**\n * The sequence number of this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.refusal.done`.\n */\n type: 'response.refusal.done';\n}\n\n/**\n * The status of the response generation. One of `completed`, `failed`,\n * `in_progress`, `cancelled`, `queued`, or `incomplete`.\n */\nexport type ResponseStatus = 'completed' | 'failed' | 'in_progress' | 'cancelled' | 'queued' | 'incomplete';\n\n/**\n * Emitted when there is a partial audio response.\n */\nexport type ResponseStreamEvent =\n | ResponseAudioDeltaEvent\n | ResponseAudioDoneEvent\n | ResponseAudioTranscriptDeltaEvent\n | ResponseAudioTranscriptDoneEvent\n | ResponseCodeInterpreterCallCodeDeltaEvent\n | ResponseCodeInterpreterCallCodeDoneEvent\n | ResponseCodeInterpreterCallCompletedEvent\n | ResponseCodeInterpreterCallInProgressEvent\n | ResponseCodeInterpreterCallInterpretingEvent\n | ResponseCompletedEvent\n | ResponseContentPartAddedEvent\n | ResponseContentPartDoneEvent\n | ResponseCreatedEvent\n | ResponseErrorEvent\n | ResponseFileSearchCallCompletedEvent\n | ResponseFileSearchCallInProgressEvent\n | ResponseFileSearchCallSearchingEvent\n | ResponseFunctionCallArgumentsDeltaEvent\n | ResponseFunctionCallArgumentsDoneEvent\n | ResponseInProgressEvent\n | ResponseFailedEvent\n | ResponseIncompleteEvent\n | ResponseOutputItemAddedEvent\n | ResponseOutputItemDoneEvent\n | ResponseReasoningSummaryPartAddedEvent\n | ResponseReasoningSummaryPartDoneEvent\n | ResponseReasoningSummaryTextDeltaEvent\n | ResponseReasoningSummaryTextDoneEvent\n | ResponseReasoningTextDeltaEvent\n | ResponseReasoningTextDoneEvent\n | ResponseRefusalDeltaEvent\n | ResponseRefusalDoneEvent\n | ResponseTextDeltaEvent\n | ResponseTextDoneEvent\n | ResponseWebSearchCallCompletedEvent\n | ResponseWebSearchCallInProgressEvent\n | ResponseWebSearchCallSearchingEvent\n | ResponseImageGenCallCompletedEvent\n | ResponseImageGenCallGeneratingEvent\n | ResponseImageGenCallInProgressEvent\n | ResponseImageGenCallPartialImageEvent\n | ResponseMcpCallArgumentsDeltaEvent\n | ResponseMcpCallArgumentsDoneEvent\n | ResponseMcpCallCompletedEvent\n | ResponseMcpCallFailedEvent\n | ResponseMcpCallInProgressEvent\n | ResponseMcpListToolsCompletedEvent\n | ResponseMcpListToolsFailedEvent\n | ResponseMcpListToolsInProgressEvent\n | ResponseOutputTextAnnotationAddedEvent\n | ResponseQueuedEvent\n | ResponseCustomToolCallInputDeltaEvent\n | ResponseCustomToolCallInputDoneEvent;\n\n/**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\nexport interface ResponseTextConfig {\n /**\n * An object specifying the format that the model must output.\n *\n * Configuring `{ \"type\": \"json_schema\" }` enables Structured Outputs, which\n * ensures the model will match your supplied JSON schema. Learn more in the\n * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).\n *\n * The default format is `{ \"type\": \"text\" }` with no additional options.\n *\n * **Not recommended for gpt-4o and newer models:**\n *\n * Setting to `{ \"type\": \"json_object\" }` enables the older JSON mode, which\n * ensures the message the model generates is valid JSON. Using `json_schema` is\n * preferred for models that support it.\n */\n format?: ResponseFormatTextConfig;\n\n /**\n * Constrains the verbosity of the model's response. Lower values will result in\n * more concise responses, while higher values will result in more verbose\n * responses. Currently supported values are `low`, `medium`, and `high`.\n */\n verbosity?: 'low' | 'medium' | 'high' | null;\n}\n\n/**\n * Emitted when there is an additional text delta.\n */\nexport interface ResponseTextDeltaEvent {\n /**\n * The index of the content part that the text delta was added to.\n */\n content_index: number;\n\n /**\n * The text delta that was added.\n */\n delta: string;\n\n /**\n * The ID of the output item that the text delta was added to.\n */\n item_id: string;\n\n /**\n * The log probabilities of the tokens in the delta.\n */\n logprobs: Array<ResponseTextDeltaEvent.Logprob>;\n\n /**\n * The index of the output item that the text delta was added to.\n */\n output_index: number;\n\n /**\n * The sequence number for this event.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.output_text.delta`.\n */\n type: 'response.output_text.delta';\n}\n\nexport namespace ResponseTextDeltaEvent {\n /**\n * A logprob is the logarithmic probability that the model assigns to producing a\n * particular token at a given position in the sequence. Less-negative (higher)\n * logprob values indicate greater model confidence in that token choice.\n */\n export interface Logprob {\n /**\n * A possible text token.\n */\n token: string;\n\n /**\n * The log probability of this token.\n */\n logprob: number;\n\n /**\n * The log probability of the top 20 most likely tokens.\n */\n top_logprobs?: Array<Logprob.TopLogprob>;\n }\n\n export namespace Logprob {\n export interface TopLogprob {\n /**\n * A possible text token.\n */\n token?: string;\n\n /**\n * The log probability of this token.\n */\n logprob?: number;\n }\n }\n}\n\n/**\n * Emitted when text content is finalized.\n */\nexport interface ResponseTextDoneEvent {\n /**\n * The index of the content part that the text content is finalized.\n */\n content_index: number;\n\n /**\n * The ID of the output item that the text content is finalized.\n */\n item_id: string;\n\n /**\n * The log probabilities of the tokens in the delta.\n */\n logprobs: Array<ResponseTextDoneEvent.Logprob>;\n\n /**\n * The index of the output item that the text content is finalized.\n */\n output_index: number;\n\n /**\n * The sequence number for this event.\n */\n sequence_number: number;\n\n /**\n * The text content that is finalized.\n */\n text: string;\n\n /**\n * The type of the event. Always `response.output_text.done`.\n */\n type: 'response.output_text.done';\n}\n\nexport namespace ResponseTextDoneEvent {\n /**\n * A logprob is the logarithmic probability that the model assigns to producing a\n * particular token at a given position in the sequence. Less-negative (higher)\n * logprob values indicate greater model confidence in that token choice.\n */\n export interface Logprob {\n /**\n * A possible text token.\n */\n token: string;\n\n /**\n * The log probability of this token.\n */\n logprob: number;\n\n /**\n * The log probability of the top 20 most likely tokens.\n */\n top_logprobs?: Array<Logprob.TopLogprob>;\n }\n\n export namespace Logprob {\n export interface TopLogprob {\n /**\n * A possible text token.\n */\n token?: string;\n\n /**\n * The log probability of this token.\n */\n logprob?: number;\n }\n }\n}\n\nexport interface ResponseToolSearchCall {\n /**\n * The unique ID of the tool search call item.\n */\n id: string;\n\n /**\n * Arguments used for the tool search call.\n */\n arguments: unknown;\n\n /**\n * The unique ID of the tool search call generated by the model.\n */\n call_id: string | null;\n\n /**\n * Whether tool search was executed by the server or by the client.\n */\n execution: 'server' | 'client';\n\n /**\n * The status of the tool search call item that was recorded.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The type of the item. Always `tool_search_call`.\n */\n type: 'tool_search_call';\n\n /**\n * The identifier of the actor that created the item.\n */\n created_by?: string;\n}\n\nexport interface ResponseToolSearchOutputItem {\n /**\n * The unique ID of the tool search output item.\n */\n id: string;\n\n /**\n * The unique ID of the tool search call generated by the model.\n */\n call_id: string | null;\n\n /**\n * Whether tool search was executed by the server or by the client.\n */\n execution: 'server' | 'client';\n\n /**\n * The status of the tool search output item that was recorded.\n */\n status: 'in_progress' | 'completed' | 'incomplete';\n\n /**\n * The loaded tool definitions returned by tool search.\n */\n tools: Array<Tool>;\n\n /**\n * The type of the item. Always `tool_search_output`.\n */\n type: 'tool_search_output';\n\n /**\n * The identifier of the actor that created the item.\n */\n created_by?: string;\n}\n\nexport interface ResponseToolSearchOutputItemParam {\n /**\n * The loaded tool definitions returned by the tool search output.\n */\n tools: Array<Tool>;\n\n /**\n * The item type. Always `tool_search_output`.\n */\n type: 'tool_search_output';\n\n /**\n * The unique ID of this tool search output.\n */\n id?: string | null;\n\n /**\n * The unique ID of the tool search call generated by the model.\n */\n call_id?: string | null;\n\n /**\n * Whether tool search was executed by the server or by the client.\n */\n execution?: 'server' | 'client';\n\n /**\n * The status of the tool search output.\n */\n status?: 'in_progress' | 'completed' | 'incomplete' | null;\n}\n\n/**\n * Represents token usage details including input tokens, output tokens, a\n * breakdown of output tokens, and the total tokens used.\n */\nexport interface ResponseUsage {\n /**\n * The number of input tokens.\n */\n input_tokens: number;\n\n /**\n * A detailed breakdown of the input tokens.\n */\n input_tokens_details: ResponseUsage.InputTokensDetails;\n\n /**\n * The number of output tokens.\n */\n output_tokens: number;\n\n /**\n * A detailed breakdown of the output tokens.\n */\n output_tokens_details: ResponseUsage.OutputTokensDetails;\n\n /**\n * The total number of tokens used.\n */\n total_tokens: number;\n}\n\nexport namespace ResponseUsage {\n /**\n * A detailed breakdown of the input tokens.\n */\n export interface InputTokensDetails {\n /**\n * The number of tokens that were retrieved from the cache.\n * [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).\n */\n cached_tokens: number;\n }\n\n /**\n * A detailed breakdown of the output tokens.\n */\n export interface OutputTokensDetails {\n /**\n * The number of reasoning tokens.\n */\n reasoning_tokens: number;\n }\n}\n\n/**\n * Emitted when a web search call is completed.\n */\nexport interface ResponseWebSearchCallCompletedEvent {\n /**\n * Unique ID for the output item associated with the web search call.\n */\n item_id: string;\n\n /**\n * The index of the output item that the web search call is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of the web search call being processed.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.web_search_call.completed`.\n */\n type: 'response.web_search_call.completed';\n}\n\n/**\n * Emitted when a web search call is initiated.\n */\nexport interface ResponseWebSearchCallInProgressEvent {\n /**\n * Unique ID for the output item associated with the web search call.\n */\n item_id: string;\n\n /**\n * The index of the output item that the web search call is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of the web search call being processed.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.web_search_call.in_progress`.\n */\n type: 'response.web_search_call.in_progress';\n}\n\n/**\n * Emitted when a web search call is executing.\n */\nexport interface ResponseWebSearchCallSearchingEvent {\n /**\n * Unique ID for the output item associated with the web search call.\n */\n item_id: string;\n\n /**\n * The index of the output item that the web search call is associated with.\n */\n output_index: number;\n\n /**\n * The sequence number of the web search call being processed.\n */\n sequence_number: number;\n\n /**\n * The type of the event. Always `response.web_search_call.searching`.\n */\n type: 'response.web_search_call.searching';\n}\n\nexport interface ResponsesClientEvent {\n /**\n * The type of the client event. Always `response.create`.\n */\n type: 'response.create';\n\n /**\n * Whether to run the model response in the background.\n * [Learn more](https://platform.openai.com/docs/guides/background).\n */\n background?: boolean | null;\n\n /**\n * Context management configuration for this request.\n */\n context_management?: Array<ResponsesClientEvent.ContextManagement> | null;\n\n /**\n * The conversation that this response belongs to. Items from this conversation are\n * prepended to `input_items` for this response request. Input items and output\n * items from this response are automatically added to this conversation after this\n * response completes.\n */\n conversation?: string | ResponseConversationParam | null;\n\n /**\n * Specify additional output data to include in the model response. Currently\n * supported values are:\n *\n * - `web_search_call.action.sources`: Include the sources of the web search tool\n * call.\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n * in code interpreter tool call items.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n * call output.\n * - `file_search_call.results`: Include the search results of the file search tool\n * call.\n * - `message.input_image.image_url`: Include image urls from the input message.\n * - `message.output_text.logprobs`: Include logprobs with assistant messages.\n * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n * tokens in reasoning item outputs. This enables reasoning items to be used in\n * multi-turn conversations when using the Responses API statelessly (like when\n * the `store` parameter is set to `false`, or when an organization is enrolled\n * in the zero data retention program).\n */\n include?: Array<ResponseIncludable> | null;\n\n /**\n * Text, image, or file inputs to the model, used to generate a response.\n *\n * Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Image inputs](https://platform.openai.com/docs/guides/images)\n * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)\n * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)\n * - [Function calling](https://platform.openai.com/docs/guides/function-calling)\n */\n input?: string | ResponseInput;\n\n /**\n * A system (or developer) message inserted into the model's context.\n *\n * When using along with `previous_response_id`, the instructions from a previous\n * response will not be carried over to the next response. This makes it simple to\n * swap out system (or developer) messages in new responses.\n */\n instructions?: string | null;\n\n /**\n * An upper bound for the number of tokens that can be generated for a response,\n * including visible output tokens and\n * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n */\n max_output_tokens?: number | null;\n\n /**\n * The maximum number of total calls to built-in tools that can be processed in a\n * response. This maximum number applies across all built-in tool calls, not per\n * individual tool. Any further attempts to call a tool by the model will be\n * ignored.\n */\n max_tool_calls?: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model?: Shared.ResponsesModel;\n\n /**\n * Whether to allow the model to run tool calls in parallel.\n */\n parallel_tool_calls?: boolean | null;\n\n /**\n * The unique ID of the previous response to the model. Use this to create\n * multi-turn conversations. Learn more about\n * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n * Cannot be used in conjunction with `conversation`.\n */\n previous_response_id?: string | null;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsePrompt | null;\n\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n prompt_cache_key?: string;\n\n /**\n * The retention policy for the prompt cache. Set to `24h` to enable extended\n * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n * of 24 hours.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n */\n prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n /**\n * **gpt-5 and o-series models only**\n *\n * Configuration options for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n */\n reasoning?: Shared.Reasoning | null;\n\n /**\n * A stable identifier used to help detect users of your application that may be\n * violating OpenAI's usage policies. The IDs should be a string that uniquely\n * identifies each user, with a maximum length of 64 characters. We recommend\n * hashing their username or email address, in order to avoid sending us any\n * identifying information.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n safety_identifier?: string;\n\n /**\n * Specifies the processing type used for serving the request.\n *\n * - If set to 'auto', then the request will be processed with the service tier\n * configured in the Project settings. Unless otherwise configured, the Project\n * will use 'default'.\n * - If set to 'default', then the request will be processed with the standard\n * pricing and performance for the selected model.\n * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n * '[priority](https://openai.com/api-priority-processing/)', then the request\n * will be processed with the corresponding service tier.\n * - When not set, the default behavior is 'auto'.\n *\n * When the `service_tier` parameter is set, the response body will include the\n * `service_tier` value based on the processing mode actually used to serve the\n * request. This response value may be different from the value set in the\n * parameter.\n */\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n /**\n * Whether to store the generated model response for later retrieval via API.\n */\n store?: boolean | null;\n\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream?: boolean | null;\n\n /**\n * Options for streaming responses. Only set this when you set `stream: true`.\n */\n stream_options?: ResponsesClientEvent.StreamOptions | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic. We generally recommend altering this or `top_p` but\n * not both.\n */\n temperature?: number | null;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: ResponseTextConfig;\n\n /**\n * How the model should select which tool (or tools) to use when generating a\n * response. See the `tools` parameter to see how to specify which tools the model\n * can call.\n */\n tool_choice?:\n | ToolChoiceOptions\n | ToolChoiceAllowed\n | ToolChoiceTypes\n | ToolChoiceFunction\n | ToolChoiceMcp\n | ToolChoiceCustom\n | ToolChoiceApplyPatch\n | ToolChoiceShell;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * We support the following categories of tools:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or\n * predefined connectors such as Google Drive and SharePoint. Learn more about\n * [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code with strongly typed arguments and outputs.\n * Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n * You can also use custom tools to call your own code.\n */\n tools?: Array<Tool>;\n\n /**\n * An integer between 0 and 20 specifying the number of most likely tokens to\n * return at each token position, each with an associated log probability.\n */\n top_logprobs?: number | null;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or `temperature` but not both.\n */\n top_p?: number | null;\n\n /**\n * The truncation strategy to use for the model response.\n *\n * - `auto`: If the input to this Response exceeds the model's context window size,\n * the model will truncate the response to fit the context window by dropping\n * items from the beginning of the conversation.\n * - `disabled` (default): If the input size will exceed the context window size\n * for a model, the request will fail with a 400 error.\n */\n truncation?: 'auto' | 'disabled' | null;\n\n /**\n * @deprecated This field is being replaced by `safety_identifier` and\n * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n * optimizations. A stable identifier for your end-users. Used to boost cache hit\n * rates by better bucketing similar requests and to help OpenAI detect and prevent\n * abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n user?: string;\n}\n\nexport namespace ResponsesClientEvent {\n export interface ContextManagement {\n /**\n * The context management entry type. Currently only 'compaction' is supported.\n */\n type: string;\n\n /**\n * Token threshold at which compaction should be triggered for this entry.\n */\n compact_threshold?: number | null;\n }\n\n /**\n * Options for streaming responses. Only set this when you set `stream: true`.\n */\n export interface StreamOptions {\n /**\n * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n * characters to an `obfuscation` field on streaming delta events to normalize\n * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n * fields are included by default, but add a small amount of overhead to the data\n * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n * you trust the network links between your application and the OpenAI API.\n */\n include_obfuscation?: boolean;\n }\n}\n\n/**\n * Server events emitted by the Responses WebSocket server.\n */\nexport type ResponsesServerEvent =\n | ResponseAudioDeltaEvent\n | ResponseAudioDoneEvent\n | ResponseAudioTranscriptDeltaEvent\n | ResponseAudioTranscriptDoneEvent\n | ResponseCodeInterpreterCallCodeDeltaEvent\n | ResponseCodeInterpreterCallCodeDoneEvent\n | ResponseCodeInterpreterCallCompletedEvent\n | ResponseCodeInterpreterCallInProgressEvent\n | ResponseCodeInterpreterCallInterpretingEvent\n | ResponseCompletedEvent\n | ResponseContentPartAddedEvent\n | ResponseContentPartDoneEvent\n | ResponseCreatedEvent\n | ResponseErrorEvent\n | ResponseFileSearchCallCompletedEvent\n | ResponseFileSearchCallInProgressEvent\n | ResponseFileSearchCallSearchingEvent\n | ResponseFunctionCallArgumentsDeltaEvent\n | ResponseFunctionCallArgumentsDoneEvent\n | ResponseInProgressEvent\n | ResponseFailedEvent\n | ResponseIncompleteEvent\n | ResponseOutputItemAddedEvent\n | ResponseOutputItemDoneEvent\n | ResponseReasoningSummaryPartAddedEvent\n | ResponseReasoningSummaryPartDoneEvent\n | ResponseReasoningSummaryTextDeltaEvent\n | ResponseReasoningSummaryTextDoneEvent\n | ResponseReasoningTextDeltaEvent\n | ResponseReasoningTextDoneEvent\n | ResponseRefusalDeltaEvent\n | ResponseRefusalDoneEvent\n | ResponseTextDeltaEvent\n | ResponseTextDoneEvent\n | ResponseWebSearchCallCompletedEvent\n | ResponseWebSearchCallInProgressEvent\n | ResponseWebSearchCallSearchingEvent\n | ResponseImageGenCallCompletedEvent\n | ResponseImageGenCallGeneratingEvent\n | ResponseImageGenCallInProgressEvent\n | ResponseImageGenCallPartialImageEvent\n | ResponseMcpCallArgumentsDeltaEvent\n | ResponseMcpCallArgumentsDoneEvent\n | ResponseMcpCallCompletedEvent\n | ResponseMcpCallFailedEvent\n | ResponseMcpCallInProgressEvent\n | ResponseMcpListToolsCompletedEvent\n | ResponseMcpListToolsFailedEvent\n | ResponseMcpListToolsInProgressEvent\n | ResponseOutputTextAnnotationAddedEvent\n | ResponseQueuedEvent\n | ResponseCustomToolCallInputDeltaEvent\n | ResponseCustomToolCallInputDoneEvent;\n\nexport interface SkillReference {\n /**\n * The ID of the referenced skill.\n */\n skill_id: string;\n\n /**\n * References a skill created with the /v1/skills endpoint.\n */\n type: 'skill_reference';\n\n /**\n * Optional skill version. Use a positive integer or 'latest'. Omit for default.\n */\n version?: string;\n}\n\n/**\n * A tool that can be used to generate a response.\n */\nexport type Tool =\n | FunctionTool\n | FileSearchTool\n | ComputerTool\n | ComputerUsePreviewTool\n | WebSearchTool\n | Tool.Mcp\n | Tool.CodeInterpreter\n | Tool.ImageGeneration\n | Tool.LocalShell\n | FunctionShellTool\n | CustomTool\n | NamespaceTool\n | ToolSearchTool\n | WebSearchPreviewTool\n | ApplyPatchTool;\n\nexport namespace Tool {\n /**\n * Give the model access to additional tools via remote Model Context Protocol\n * (MCP) servers.\n * [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).\n */\n export interface Mcp {\n /**\n * A label for this MCP server, used to identify it in tool calls.\n */\n server_label: string;\n\n /**\n * The type of the MCP tool. Always `mcp`.\n */\n type: 'mcp';\n\n /**\n * List of allowed tool names or a filter object.\n */\n allowed_tools?: Array<string> | Mcp.McpToolFilter | null;\n\n /**\n * An OAuth access token that can be used with a remote MCP server, either with a\n * custom MCP server URL or a service connector. Your application must handle the\n * OAuth authorization flow and provide the token here.\n */\n authorization?: string;\n\n /**\n * Identifier for service connectors, like those available in ChatGPT. One of\n * `server_url` or `connector_id` must be provided. Learn more about service\n * connectors\n * [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).\n *\n * Currently supported `connector_id` values are:\n *\n * - Dropbox: `connector_dropbox`\n * - Gmail: `connector_gmail`\n * - Google Calendar: `connector_googlecalendar`\n * - Google Drive: `connector_googledrive`\n * - Microsoft Teams: `connector_microsoftteams`\n * - Outlook Calendar: `connector_outlookcalendar`\n * - Outlook Email: `connector_outlookemail`\n * - SharePoint: `connector_sharepoint`\n */\n connector_id?:\n | 'connector_dropbox'\n | 'connector_gmail'\n | 'connector_googlecalendar'\n | 'connector_googledrive'\n | 'connector_microsoftteams'\n | 'connector_outlookcalendar'\n | 'connector_outlookemail'\n | 'connector_sharepoint';\n\n /**\n * Whether this MCP tool is deferred and discovered via tool search.\n */\n defer_loading?: boolean;\n\n /**\n * Optional HTTP headers to send to the MCP server. Use for authentication or other\n * purposes.\n */\n headers?: { [key: string]: string } | null;\n\n /**\n * Specify which of the MCP server's tools require approval.\n */\n require_approval?: Mcp.McpToolApprovalFilter | 'always' | 'never' | null;\n\n /**\n * Optional description of the MCP server, used to provide more context.\n */\n server_description?: string;\n\n /**\n * The URL for the MCP server. One of `server_url` or `connector_id` must be\n * provided.\n */\n server_url?: string;\n }\n\n export namespace Mcp {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface McpToolFilter {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * Specify which of the MCP server's tools require approval. Can be `always`,\n * `never`, or a filter object associated with tools that require approval.\n */\n export interface McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n always?: McpToolApprovalFilter.Always;\n\n /**\n * A filter object to specify which tools are allowed.\n */\n never?: McpToolApprovalFilter.Never;\n }\n\n export namespace McpToolApprovalFilter {\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Always {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n\n /**\n * A filter object to specify which tools are allowed.\n */\n export interface Never {\n /**\n * Indicates whether or not a tool modifies data or is read-only. If an MCP server\n * is\n * [annotated with `readOnlyHint`](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations-readonlyhint),\n * it will match this filter.\n */\n read_only?: boolean;\n\n /**\n * List of allowed tool names.\n */\n tool_names?: Array<string>;\n }\n }\n }\n\n /**\n * A tool that runs Python code to help generate a response to a prompt.\n */\n export interface CodeInterpreter {\n /**\n * The code interpreter container. Can be a container ID or an object that\n * specifies uploaded file IDs to make available to your code, along with an\n * optional `memory_limit` setting.\n */\n container: string | CodeInterpreter.CodeInterpreterToolAuto;\n\n /**\n * The type of the code interpreter tool. Always `code_interpreter`.\n */\n type: 'code_interpreter';\n }\n\n export namespace CodeInterpreter {\n /**\n * Configuration for a code interpreter container. Optionally specify the IDs of\n * the files to run the code on.\n */\n export interface CodeInterpreterToolAuto {\n /**\n * Always `auto`.\n */\n type: 'auto';\n\n /**\n * An optional list of uploaded files to make available to your code.\n */\n file_ids?: Array<string>;\n\n /**\n * The memory limit for the code interpreter container.\n */\n memory_limit?: '1g' | '4g' | '16g' | '64g' | null;\n\n /**\n * Network access policy for the container.\n */\n network_policy?:\n | ResponsesAPI.ContainerNetworkPolicyDisabled\n | ResponsesAPI.ContainerNetworkPolicyAllowlist;\n }\n }\n\n /**\n * A tool that generates images using the GPT image models.\n */\n export interface ImageGeneration {\n /**\n * The type of the image generation tool. Always `image_generation`.\n */\n type: 'image_generation';\n\n /**\n * Whether to generate a new image or edit an existing image. Default: `auto`.\n */\n action?: 'generate' | 'edit' | 'auto';\n\n /**\n * Background type for the generated image. One of `transparent`, `opaque`, or\n * `auto`. Default: `auto`.\n */\n background?: 'transparent' | 'opaque' | 'auto';\n\n /**\n * Control how much effort the model will exert to match the style and features,\n * especially facial features, of input images. This parameter is only supported\n * for `gpt-image-1` and `gpt-image-1.5` and later models, unsupported for\n * `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.\n */\n input_fidelity?: 'high' | 'low' | null;\n\n /**\n * Optional mask for inpainting. Contains `image_url` (string, optional) and\n * `file_id` (string, optional).\n */\n input_image_mask?: ImageGeneration.InputImageMask;\n\n /**\n * The image generation model to use. Default: `gpt-image-1`.\n */\n model?: (string & {}) | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5';\n\n /**\n * Moderation level for the generated image. Default: `auto`.\n */\n moderation?: 'auto' | 'low';\n\n /**\n * Compression level for the output image. Default: 100.\n */\n output_compression?: number;\n\n /**\n * The output format of the generated image. One of `png`, `webp`, or `jpeg`.\n * Default: `png`.\n */\n output_format?: 'png' | 'webp' | 'jpeg';\n\n /**\n * Number of partial images to generate in streaming mode, from 0 (default value)\n * to 3.\n */\n partial_images?: number;\n\n /**\n * The quality of the generated image. One of `low`, `medium`, `high`, or `auto`.\n * Default: `auto`.\n */\n quality?: 'low' | 'medium' | 'high' | 'auto';\n\n /**\n * The size of the generated image. One of `1024x1024`, `1024x1536`, `1536x1024`,\n * or `auto`. Default: `auto`.\n */\n size?: '1024x1024' | '1024x1536' | '1536x1024' | 'auto';\n }\n\n export namespace ImageGeneration {\n /**\n * Optional mask for inpainting. Contains `image_url` (string, optional) and\n * `file_id` (string, optional).\n */\n export interface InputImageMask {\n /**\n * File ID for the mask image.\n */\n file_id?: string;\n\n /**\n * Base64-encoded mask image.\n */\n image_url?: string;\n }\n }\n\n /**\n * A tool that allows the model to execute shell commands in a local environment.\n */\n export interface LocalShell {\n /**\n * The type of the local shell tool. Always `local_shell`.\n */\n type: 'local_shell';\n }\n}\n\n/**\n * Constrains the tools available to the model to a pre-defined set.\n */\nexport interface ToolChoiceAllowed {\n /**\n * Constrains the tools available to the model to a pre-defined set.\n *\n * `auto` allows the model to pick from among the allowed tools and generate a\n * message.\n *\n * `required` requires the model to call one or more of the allowed tools.\n */\n mode: 'auto' | 'required';\n\n /**\n * A list of tool definitions that the model should be allowed to call.\n *\n * For the Responses API, the list of tool definitions might look like:\n *\n * ```json\n * [\n * { \"type\": \"function\", \"name\": \"get_weather\" },\n * { \"type\": \"mcp\", \"server_label\": \"deepwiki\" },\n * { \"type\": \"image_generation\" }\n * ]\n * ```\n */\n tools: Array<{ [key: string]: unknown }>;\n\n /**\n * Allowed tool configuration type. Always `allowed_tools`.\n */\n type: 'allowed_tools';\n}\n\n/**\n * Forces the model to call the apply_patch tool when executing a tool call.\n */\nexport interface ToolChoiceApplyPatch {\n /**\n * The tool to call. Always `apply_patch`.\n */\n type: 'apply_patch';\n}\n\n/**\n * Use this option to force the model to call a specific custom tool.\n */\nexport interface ToolChoiceCustom {\n /**\n * The name of the custom tool to call.\n */\n name: string;\n\n /**\n * For custom tool calling, the type is always `custom`.\n */\n type: 'custom';\n}\n\n/**\n * Use this option to force the model to call a specific function.\n */\nexport interface ToolChoiceFunction {\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * For function calling, the type is always `function`.\n */\n type: 'function';\n}\n\n/**\n * Use this option to force the model to call a specific tool on a remote MCP\n * server.\n */\nexport interface ToolChoiceMcp {\n /**\n * The label of the MCP server to use.\n */\n server_label: string;\n\n /**\n * For MCP tools, the type is always `mcp`.\n */\n type: 'mcp';\n\n /**\n * The name of the tool to call on the server.\n */\n name?: string | null;\n}\n\n/**\n * Controls which (if any) tool is called by the model.\n *\n * `none` means the model will not call any tool and instead generates a message.\n *\n * `auto` means the model can pick between generating a message or calling one or\n * more tools.\n *\n * `required` means the model must call one or more tools.\n */\nexport type ToolChoiceOptions = 'none' | 'auto' | 'required';\n\n/**\n * Forces the model to call the shell tool when a tool call is required.\n */\nexport interface ToolChoiceShell {\n /**\n * The tool to call. Always `shell`.\n */\n type: 'shell';\n}\n\n/**\n * Indicates that the model should use a built-in tool to generate a response.\n * [Learn more about built-in tools](https://platform.openai.com/docs/guides/tools).\n */\nexport interface ToolChoiceTypes {\n /**\n * The type of hosted tool the model should to use. Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n *\n * Allowed values are:\n *\n * - `file_search`\n * - `web_search_preview`\n * - `computer`\n * - `computer_use_preview`\n * - `computer_use`\n * - `code_interpreter`\n * - `mcp`\n * - `image_generation`\n */\n type:\n | 'file_search'\n | 'web_search_preview'\n | 'computer'\n | 'computer_use_preview'\n | 'computer_use'\n | 'web_search_preview_2025_03_11'\n | 'image_generation'\n | 'code_interpreter'\n | 'mcp';\n}\n\n/**\n * Hosted or BYOT tool search configuration for deferred tools.\n */\nexport interface ToolSearchTool {\n /**\n * The type of the tool. Always `tool_search`.\n */\n type: 'tool_search';\n\n /**\n * Description shown to the model for a client-executed tool search tool.\n */\n description?: string | null;\n\n /**\n * Whether tool search is executed by the server or by the client.\n */\n execution?: 'server' | 'client';\n\n /**\n * Parameter schema for a client-executed tool search tool.\n */\n parameters?: unknown | null;\n}\n\n/**\n * This tool searches the web for relevant results to use in a response. Learn more\n * about the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search).\n */\nexport interface WebSearchPreviewTool {\n /**\n * The type of the web search tool. One of `web_search_preview` or\n * `web_search_preview_2025_03_11`.\n */\n type: 'web_search_preview' | 'web_search_preview_2025_03_11';\n\n search_content_types?: Array<'text' | 'image'>;\n\n /**\n * High level guidance for the amount of context window space to use for the\n * search. One of `low`, `medium`, or `high`. `medium` is the default.\n */\n search_context_size?: 'low' | 'medium' | 'high';\n\n /**\n * The user's location.\n */\n user_location?: WebSearchPreviewTool.UserLocation | null;\n}\n\nexport namespace WebSearchPreviewTool {\n /**\n * The user's location.\n */\n export interface UserLocation {\n /**\n * The type of location approximation. Always `approximate`.\n */\n type: 'approximate';\n\n /**\n * Free text input for the city of the user, e.g. `San Francisco`.\n */\n city?: string | null;\n\n /**\n * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of\n * the user, e.g. `US`.\n */\n country?: string | null;\n\n /**\n * Free text input for the region of the user, e.g. `California`.\n */\n region?: string | null;\n\n /**\n * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the\n * user, e.g. `America/Los_Angeles`.\n */\n timezone?: string | null;\n }\n}\n\n/**\n * Search the Internet for sources related to the prompt. Learn more about the\n * [web search tool](https://platform.openai.com/docs/guides/tools-web-search).\n */\nexport interface WebSearchTool {\n /**\n * The type of the web search tool. One of `web_search` or `web_search_2025_08_26`.\n */\n type: 'web_search' | 'web_search_2025_08_26';\n\n /**\n * Filters for the search.\n */\n filters?: WebSearchTool.Filters | null;\n\n /**\n * High level guidance for the amount of context window space to use for the\n * search. One of `low`, `medium`, or `high`. `medium` is the default.\n */\n search_context_size?: 'low' | 'medium' | 'high';\n\n /**\n * The approximate location of the user.\n */\n user_location?: WebSearchTool.UserLocation | null;\n}\n\nexport namespace WebSearchTool {\n /**\n * Filters for the search.\n */\n export interface Filters {\n /**\n * Allowed domains for the search. If not provided, all domains are allowed.\n * Subdomains of the provided domains are allowed as well.\n *\n * Example: `[\"pubmed.ncbi.nlm.nih.gov\"]`\n */\n allowed_domains?: Array<string> | null;\n }\n\n /**\n * The approximate location of the user.\n */\n export interface UserLocation {\n /**\n * Free text input for the city of the user, e.g. `San Francisco`.\n */\n city?: string | null;\n\n /**\n * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of\n * the user, e.g. `US`.\n */\n country?: string | null;\n\n /**\n * Free text input for the region of the user, e.g. `California`.\n */\n region?: string | null;\n\n /**\n * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the\n * user, e.g. `America/Los_Angeles`.\n */\n timezone?: string | null;\n\n /**\n * The type of location approximation. Always `approximate`.\n */\n type?: 'approximate';\n }\n}\n\nexport type ResponseCreateParams = ResponseCreateParamsNonStreaming | ResponseCreateParamsStreaming;\n\nexport interface ResponseCreateParamsBase {\n /**\n * Whether to run the model response in the background.\n * [Learn more](https://platform.openai.com/docs/guides/background).\n */\n background?: boolean | null;\n\n /**\n * Context management configuration for this request.\n */\n context_management?: Array<ResponseCreateParams.ContextManagement> | null;\n\n /**\n * The conversation that this response belongs to. Items from this conversation are\n * prepended to `input_items` for this response request. Input items and output\n * items from this response are automatically added to this conversation after this\n * response completes.\n */\n conversation?: string | ResponseConversationParam | null;\n\n /**\n * Specify additional output data to include in the model response. Currently\n * supported values are:\n *\n * - `web_search_call.action.sources`: Include the sources of the web search tool\n * call.\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n * in code interpreter tool call items.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n * call output.\n * - `file_search_call.results`: Include the search results of the file search tool\n * call.\n * - `message.input_image.image_url`: Include image urls from the input message.\n * - `computer_call_output.output.image_url`: Include image urls from the computer\n * call output.\n * - `reasoning.encrypted_content`: Includes an encrypted version of reasoning\n * tokens in reasoning item outputs. This enables reasoning items to be used in\n * multi-turn conversations when using the Responses API statelessly (like when\n * the `store` parameter is set to `false`, or when an organization is enrolled\n * in the zero data retention program).\n * - `code_interpreter_call.outputs`: Includes the outputs of python code execution\n * in code interpreter tool call items.\n */\n include?: Array<ResponseIncludable> | null;\n\n /**\n * Text, image, or file inputs to the model, used to generate a response.\n *\n * Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Image inputs](https://platform.openai.com/docs/guides/images)\n * - [File inputs](https://platform.openai.com/docs/guides/pdf-files)\n * - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)\n * - [Function calling](https://platform.openai.com/docs/guides/function-calling)\n */\n input?: string | ResponseInput;\n\n /**\n * A system (or developer) message inserted into the model's context.\n *\n * When using along with `previous_response_id`, the instructions from a previous\n * response will not be carried over to the next response. This makes it simple to\n * swap out system (or developer) messages in new responses.\n */\n instructions?: string | null;\n\n /**\n * An upper bound for the number of tokens that can be generated for a response,\n * including visible output tokens and\n * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).\n */\n max_output_tokens?: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model?: Shared.ResponsesModel;\n\n /**\n * Whether to allow the model to run tool calls in parallel.\n */\n parallel_tool_calls?: boolean | null;\n\n /**\n * The unique ID of the previous response to the model. Use this to create\n * multi-turn conversations. Learn more about\n * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n * Cannot be used in conjunction with `conversation`.\n */\n previous_response_id?: string | null;\n\n /**\n * Reference to a prompt template and its variables.\n * [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).\n */\n prompt?: ResponsePrompt | null;\n\n /**\n * Used by OpenAI to cache responses for similar requests to optimize your cache\n * hit rates. Replaces the `user` field.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching).\n */\n prompt_cache_key?: string;\n\n /**\n * The retention policy for the prompt cache. Set to `24h` to enable extended\n * prompt caching, which keeps cached prefixes active for longer, up to a maximum\n * of 24 hours.\n * [Learn more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).\n */\n prompt_cache_retention?: 'in-memory' | '24h' | null;\n\n /**\n * **gpt-5 and o-series models only**\n *\n * Configuration options for\n * [reasoning models](https://platform.openai.com/docs/guides/reasoning).\n */\n reasoning?: Shared.Reasoning | null;\n\n /**\n * A stable identifier used to help detect users of your application that may be\n * violating OpenAI's usage policies. The IDs should be a string that uniquely\n * identifies each user, with a maximum length of 64 characters. We recommend\n * hashing their username or email address, in order to avoid sending us any\n * identifying information.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n safety_identifier?: string;\n\n /**\n * Specifies the latency tier to use for processing the request. This parameter is\n * relevant for customers subscribed to the scale tier service:\n *\n * - If set to 'auto', then the request will be processed with the service tier\n * configured in the Project settings. Unless otherwise configured, the Project\n * will use 'default'.\n * - If set to 'default', then the request will be processed with the standard\n * pricing and performance for the selected model.\n * - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or\n * '[priority](https://openai.com/api-priority-processing/)', then the request\n * will be processed with the corresponding service tier.\n * - When not set, the default behavior is 'auto'.\n *\n * When this parameter is set, the response body will include the `service_tier`\n * utilized.\n */\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority' | null;\n\n /**\n * Whether to store the generated model response for later retrieval via API.\n */\n store?: boolean | null;\n\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream?: boolean | null;\n\n /**\n * Options for streaming responses. Only set this when you set `stream: true`.\n */\n stream_options?: ResponseCreateParams.StreamOptions | null;\n\n /**\n * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will\n * make the output more random, while lower values like 0.2 will make it more\n * focused and deterministic. We generally recommend altering this or `top_p` but\n * not both.\n */\n temperature?: number | null;\n\n /**\n * Configuration options for a text response from the model. Can be plain text or\n * structured JSON data. Learn more:\n *\n * - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)\n * - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)\n */\n text?: ResponseTextConfig;\n\n /**\n * How the model should select which tool (or tools) to use when generating a\n * response. See the `tools` parameter to see how to specify which tools the model\n * can call.\n */\n tool_choice?:\n | ToolChoiceOptions\n | ToolChoiceAllowed\n | ToolChoiceTypes\n | ToolChoiceFunction\n | ToolChoiceMcp\n | ToolChoiceCustom\n | ToolChoiceApplyPatch\n | ToolChoiceShell;\n\n /**\n * An array of tools the model may call while generating a response. You can\n * specify which tool to use by setting the `tool_choice` parameter.\n *\n * We support the following categories of tools:\n *\n * - **Built-in tools**: Tools that are provided by OpenAI that extend the model's\n * capabilities, like\n * [web search](https://platform.openai.com/docs/guides/tools-web-search) or\n * [file search](https://platform.openai.com/docs/guides/tools-file-search).\n * Learn more about\n * [built-in tools](https://platform.openai.com/docs/guides/tools).\n * - **MCP Tools**: Integrations with third-party systems via custom MCP servers or\n * predefined connectors such as Google Drive and SharePoint. Learn more about\n * [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).\n * - **Function calls (custom tools)**: Functions that are defined by you, enabling\n * the model to call your own code with strongly typed arguments and outputs.\n * Learn more about\n * [function calling](https://platform.openai.com/docs/guides/function-calling).\n * You can also use custom tools to call your own code.\n */\n tools?: Array<Tool>;\n\n /**\n * An alternative to sampling with temperature, called nucleus sampling, where the\n * model considers the results of the tokens with top_p probability mass. So 0.1\n * means only the tokens comprising the top 10% probability mass are considered.\n *\n * We generally recommend altering this or `temperature` but not both.\n */\n top_p?: number | null;\n\n /**\n * The truncation strategy to use for the model response.\n *\n * - `auto`: If the input to this Response exceeds the model's context window size,\n * the model will truncate the response to fit the context window by dropping\n * items from the beginning of the conversation.\n * - `disabled` (default): If the input size will exceed the context window size\n * for a model, the request will fail with a 400 error.\n */\n truncation?: 'auto' | 'disabled' | null;\n\n /**\n * @deprecated This field is being replaced by `safety_identifier` and\n * `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching\n * optimizations. A stable identifier for your end-users. Used to boost cache hit\n * rates by better bucketing similar requests and to help OpenAI detect and prevent\n * abuse.\n * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).\n */\n user?: string;\n}\n\nexport namespace ResponseCreateParams {\n export interface ContextManagement {\n /**\n * The context management entry type. Currently only 'compaction' is supported.\n */\n type: string;\n\n /**\n * Token threshold at which compaction should be triggered for this entry.\n */\n compact_threshold?: number | null;\n }\n\n /**\n * Options for streaming responses. Only set this when you set `stream: true`.\n */\n export interface StreamOptions {\n /**\n * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n * characters to an `obfuscation` field on streaming delta events to normalize\n * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n * fields are included by default, but add a small amount of overhead to the data\n * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n * you trust the network links between your application and the OpenAI API.\n */\n include_obfuscation?: boolean;\n }\n\n export type ResponseCreateParamsNonStreaming = ResponsesAPI.ResponseCreateParamsNonStreaming;\n export type ResponseCreateParamsStreaming = ResponsesAPI.ResponseCreateParamsStreaming;\n}\n\nexport interface ResponseCreateParamsNonStreaming extends ResponseCreateParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream?: false | null;\n}\n\nexport interface ResponseCreateParamsStreaming extends ResponseCreateParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream: true;\n}\n\nexport type ResponseRetrieveParams = ResponseRetrieveParamsNonStreaming | ResponseRetrieveParamsStreaming;\n\nexport interface ResponseRetrieveParamsBase {\n /**\n * Additional fields to include in the response. See the `include` parameter for\n * Response creation above for more information.\n */\n include?: Array<ResponseIncludable>;\n\n /**\n * When true, stream obfuscation will be enabled. Stream obfuscation adds random\n * characters to an `obfuscation` field on streaming delta events to normalize\n * payload sizes as a mitigation to certain side-channel attacks. These obfuscation\n * fields are included by default, but add a small amount of overhead to the data\n * stream. You can set `include_obfuscation` to false to optimize for bandwidth if\n * you trust the network links between your application and the OpenAI API.\n */\n include_obfuscation?: boolean;\n\n /**\n * The sequence number of the event after which to start streaming.\n */\n starting_after?: number;\n\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream?: boolean;\n}\n\nexport namespace ResponseRetrieveParams {\n export type ResponseRetrieveParamsNonStreaming = ResponsesAPI.ResponseRetrieveParamsNonStreaming;\n export type ResponseRetrieveParamsStreaming = ResponsesAPI.ResponseRetrieveParamsStreaming;\n}\n\nexport interface ResponseRetrieveParamsNonStreaming extends ResponseRetrieveParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream?: false;\n}\n\nexport interface ResponseRetrieveParamsStreaming extends ResponseRetrieveParamsBase {\n /**\n * If set to true, the model response data will be streamed to the client as it is\n * generated using\n * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).\n * See the\n * [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)\n * for more information.\n */\n stream: true;\n}\n\nexport interface ResponseCompactParams {\n /**\n * Model ID used to generate the response, like `gpt-5` or `o3`. OpenAI offers a\n * wide range of models with different capabilities, performance characteristics,\n * and price points. Refer to the\n * [model guide](https://platform.openai.com/docs/models) to browse and compare\n * available models.\n */\n model:\n | 'gpt-5.4'\n | 'gpt-5.3-chat-latest'\n | 'gpt-5.2'\n | 'gpt-5.2-2025-12-11'\n | 'gpt-5.2-chat-latest'\n | 'gpt-5.2-pro'\n | 'gpt-5.2-pro-2025-12-11'\n | 'gpt-5.1'\n | 'gpt-5.1-2025-11-13'\n | 'gpt-5.1-codex'\n | 'gpt-5.1-mini'\n | 'gpt-5.1-chat-latest'\n | 'gpt-5'\n | 'gpt-5-mini'\n | 'gpt-5-nano'\n | 'gpt-5-2025-08-07'\n | 'gpt-5-mini-2025-08-07'\n | 'gpt-5-nano-2025-08-07'\n | 'gpt-5-chat-latest'\n | 'gpt-4.1'\n | 'gpt-4.1-mini'\n | 'gpt-4.1-nano'\n | 'gpt-4.1-2025-04-14'\n | 'gpt-4.1-mini-2025-04-14'\n | 'gpt-4.1-nano-2025-04-14'\n | 'o4-mini'\n | 'o4-mini-2025-04-16'\n | 'o3'\n | 'o3-2025-04-16'\n | 'o3-mini'\n | 'o3-mini-2025-01-31'\n | 'o1'\n | 'o1-2024-12-17'\n | 'o1-preview'\n | 'o1-preview-2024-09-12'\n | 'o1-mini'\n | 'o1-mini-2024-09-12'\n | 'gpt-4o'\n | 'gpt-4o-2024-11-20'\n | 'gpt-4o-2024-08-06'\n | 'gpt-4o-2024-05-13'\n | 'gpt-4o-audio-preview'\n | 'gpt-4o-audio-preview-2024-10-01'\n | 'gpt-4o-audio-preview-2024-12-17'\n | 'gpt-4o-audio-preview-2025-06-03'\n | 'gpt-4o-mini-audio-preview'\n | 'gpt-4o-mini-audio-preview-2024-12-17'\n | 'gpt-4o-search-preview'\n | 'gpt-4o-mini-search-preview'\n | 'gpt-4o-search-preview-2025-03-11'\n | 'gpt-4o-mini-search-preview-2025-03-11'\n | 'chatgpt-4o-latest'\n | 'codex-mini-latest'\n | 'gpt-4o-mini'\n | 'gpt-4o-mini-2024-07-18'\n | 'gpt-4-turbo'\n | 'gpt-4-turbo-2024-04-09'\n | 'gpt-4-0125-preview'\n | 'gpt-4-turbo-preview'\n | 'gpt-4-1106-preview'\n | 'gpt-4-vision-preview'\n | 'gpt-4'\n | 'gpt-4-0314'\n | 'gpt-4-0613'\n | 'gpt-4-32k'\n | 'gpt-4-32k-0314'\n | 'gpt-4-32k-0613'\n | 'gpt-3.5-turbo'\n | 'gpt-3.5-turbo-16k'\n | 'gpt-3.5-turbo-0301'\n | 'gpt-3.5-turbo-0613'\n | 'gpt-3.5-turbo-1106'\n | 'gpt-3.5-turbo-0125'\n | 'gpt-3.5-turbo-16k-0613'\n | 'o1-pro'\n | 'o1-pro-2025-03-19'\n | 'o3-pro'\n | 'o3-pro-2025-06-10'\n | 'o3-deep-research'\n | 'o3-deep-research-2025-06-26'\n | 'o4-mini-deep-research'\n | 'o4-mini-deep-research-2025-06-26'\n | 'computer-use-preview'\n | 'computer-use-preview-2025-03-11'\n | 'gpt-5-codex'\n | 'gpt-5-pro'\n | 'gpt-5-pro-2025-10-06'\n | 'gpt-5.1-codex-max'\n | (string & {})\n | null;\n\n /**\n * Text, image, or file inputs to the model, used to generate a response\n */\n input?: string | Array<ResponseInputItem> | null;\n\n /**\n * A system (or developer) message inserted into the model's context. When used\n * along with `previous_response_id`, the instructions from a previous response\n * will not be carried over to the next response. This makes it simple to swap out\n * system (or developer) messages in new responses.\n */\n instructions?: string | null;\n\n /**\n * The unique ID of the previous response to the model. Use this to create\n * multi-turn conversations. Learn more about\n * [conversation state](https://platform.openai.com/docs/guides/conversation-state).\n * Cannot be used in conjunction with `conversation`.\n */\n previous_response_id?: string | null;\n\n /**\n * A key to use when reading from or writing to the prompt cache.\n */\n prompt_cache_key?: string | null;\n}\n\nResponses.InputItems = InputItems;\nResponses.InputTokens = InputTokens;\n\nexport declare namespace Responses {\n export {\n type ApplyPatchTool as ApplyPatchTool,\n type CompactedResponse as CompactedResponse,\n type ComputerAction as ComputerAction,\n type ComputerActionList as ComputerActionList,\n type ComputerTool as ComputerTool,\n type ComputerUsePreviewTool as ComputerUsePreviewTool,\n type ContainerAuto as ContainerAuto,\n type ContainerNetworkPolicyAllowlist as ContainerNetworkPolicyAllowlist,\n type ContainerNetworkPolicyDisabled as ContainerNetworkPolicyDisabled,\n type ContainerNetworkPolicyDomainSecret as ContainerNetworkPolicyDomainSecret,\n type ContainerReference as ContainerReference,\n type CustomTool as CustomTool,\n type EasyInputMessage as EasyInputMessage,\n type FileSearchTool as FileSearchTool,\n type FunctionShellTool as FunctionShellTool,\n type FunctionTool as FunctionTool,\n type InlineSkill as InlineSkill,\n type InlineSkillSource as InlineSkillSource,\n type LocalEnvironment as LocalEnvironment,\n type LocalSkill as LocalSkill,\n type NamespaceTool as NamespaceTool,\n type Response as Response,\n type ResponseApplyPatchToolCall as ResponseApplyPatchToolCall,\n type ResponseApplyPatchToolCallOutput as ResponseApplyPatchToolCallOutput,\n type ResponseAudioDeltaEvent as ResponseAudioDeltaEvent,\n type ResponseAudioDoneEvent as ResponseAudioDoneEvent,\n type ResponseAudioTranscriptDeltaEvent as ResponseAudioTranscriptDeltaEvent,\n type ResponseAudioTranscriptDoneEvent as ResponseAudioTranscriptDoneEvent,\n type ResponseCodeInterpreterCallCodeDeltaEvent as ResponseCodeInterpreterCallCodeDeltaEvent,\n type ResponseCodeInterpreterCallCodeDoneEvent as ResponseCodeInterpreterCallCodeDoneEvent,\n type ResponseCodeInterpreterCallCompletedEvent as ResponseCodeInterpreterCallCompletedEvent,\n type ResponseCodeInterpreterCallInProgressEvent as ResponseCodeInterpreterCallInProgressEvent,\n type ResponseCodeInterpreterCallInterpretingEvent as ResponseCodeInterpreterCallInterpretingEvent,\n type ResponseCodeInterpreterToolCall as ResponseCodeInterpreterToolCall,\n type ResponseCompactionItem as ResponseCompactionItem,\n type ResponseCompactionItemParam as ResponseCompactionItemParam,\n type ResponseCompletedEvent as ResponseCompletedEvent,\n type ResponseComputerToolCall as ResponseComputerToolCall,\n type ResponseComputerToolCallOutputItem as ResponseComputerToolCallOutputItem,\n type ResponseComputerToolCallOutputScreenshot as ResponseComputerToolCallOutputScreenshot,\n type ResponseContainerReference as ResponseContainerReference,\n type ResponseContent as ResponseContent,\n type ResponseContentPartAddedEvent as ResponseContentPartAddedEvent,\n type ResponseContentPartDoneEvent as ResponseContentPartDoneEvent,\n type ResponseConversationParam as ResponseConversationParam,\n type ResponseCreatedEvent as ResponseCreatedEvent,\n type ResponseCustomToolCall as ResponseCustomToolCall,\n type ResponseCustomToolCallInputDeltaEvent as ResponseCustomToolCallInputDeltaEvent,\n type ResponseCustomToolCallInputDoneEvent as ResponseCustomToolCallInputDoneEvent,\n type ResponseCustomToolCallOutput as ResponseCustomToolCallOutput,\n type ResponseError as ResponseError,\n type ResponseErrorEvent as ResponseErrorEvent,\n type ResponseFailedEvent as ResponseFailedEvent,\n type ResponseFileSearchCallCompletedEvent as ResponseFileSearchCallCompletedEvent,\n type ResponseFileSearchCallInProgressEvent as ResponseFileSearchCallInProgressEvent,\n type ResponseFileSearchCallSearchingEvent as ResponseFileSearchCallSearchingEvent,\n type ResponseFileSearchToolCall as ResponseFileSearchToolCall,\n type ResponseFormatTextConfig as ResponseFormatTextConfig,\n type ResponseFormatTextJSONSchemaConfig as ResponseFormatTextJSONSchemaConfig,\n type ResponseFunctionCallArgumentsDeltaEvent as ResponseFunctionCallArgumentsDeltaEvent,\n type ResponseFunctionCallArgumentsDoneEvent as ResponseFunctionCallArgumentsDoneEvent,\n type ResponseFunctionCallOutputItem as ResponseFunctionCallOutputItem,\n type ResponseFunctionCallOutputItemList as ResponseFunctionCallOutputItemList,\n type ResponseFunctionShellCallOutputContent as ResponseFunctionShellCallOutputContent,\n type ResponseFunctionShellToolCall as ResponseFunctionShellToolCall,\n type ResponseFunctionShellToolCallOutput as ResponseFunctionShellToolCallOutput,\n type ResponseFunctionToolCall as ResponseFunctionToolCall,\n type ResponseFunctionToolCallItem as ResponseFunctionToolCallItem,\n type ResponseFunctionToolCallOutputItem as ResponseFunctionToolCallOutputItem,\n type ResponseFunctionWebSearch as ResponseFunctionWebSearch,\n type ResponseImageGenCallCompletedEvent as ResponseImageGenCallCompletedEvent,\n type ResponseImageGenCallGeneratingEvent as ResponseImageGenCallGeneratingEvent,\n type ResponseImageGenCallInProgressEvent as ResponseImageGenCallInProgressEvent,\n type ResponseImageGenCallPartialImageEvent as ResponseImageGenCallPartialImageEvent,\n type ResponseInProgressEvent as ResponseInProgressEvent,\n type ResponseIncludable as ResponseIncludable,\n type ResponseIncompleteEvent as ResponseIncompleteEvent,\n type ResponseInput as ResponseInput,\n type ResponseInputAudio as ResponseInputAudio,\n type ResponseInputContent as ResponseInputContent,\n type ResponseInputFile as ResponseInputFile,\n type ResponseInputFileContent as ResponseInputFileContent,\n type ResponseInputImage as ResponseInputImage,\n type ResponseInputImageContent as ResponseInputImageContent,\n type ResponseInputItem as ResponseInputItem,\n type ResponseInputMessageContentList as ResponseInputMessageContentList,\n type ResponseInputMessageItem as ResponseInputMessageItem,\n type ResponseInputText as ResponseInputText,\n type ResponseInputTextContent as ResponseInputTextContent,\n type ResponseItem as ResponseItem,\n type ResponseLocalEnvironment as ResponseLocalEnvironment,\n type ResponseMcpCallArgumentsDeltaEvent as ResponseMcpCallArgumentsDeltaEvent,\n type ResponseMcpCallArgumentsDoneEvent as ResponseMcpCallArgumentsDoneEvent,\n type ResponseMcpCallCompletedEvent as ResponseMcpCallCompletedEvent,\n type ResponseMcpCallFailedEvent as ResponseMcpCallFailedEvent,\n type ResponseMcpCallInProgressEvent as ResponseMcpCallInProgressEvent,\n type ResponseMcpListToolsCompletedEvent as ResponseMcpListToolsCompletedEvent,\n type ResponseMcpListToolsFailedEvent as ResponseMcpListToolsFailedEvent,\n type ResponseMcpListToolsInProgressEvent as ResponseMcpListToolsInProgressEvent,\n type ResponseOutputAudio as ResponseOutputAudio,\n type ResponseOutputItem as ResponseOutputItem,\n type ResponseOutputItemAddedEvent as ResponseOutputItemAddedEvent,\n type ResponseOutputItemDoneEvent as ResponseOutputItemDoneEvent,\n type ResponseOutputMessage as ResponseOutputMessage,\n type ResponseOutputRefusal as ResponseOutputRefusal,\n type ResponseOutputText as ResponseOutputText,\n type ResponseOutputTextAnnotationAddedEvent as ResponseOutputTextAnnotationAddedEvent,\n type ResponsePrompt as ResponsePrompt,\n type ResponseQueuedEvent as ResponseQueuedEvent,\n type ResponseReasoningItem as ResponseReasoningItem,\n type ResponseReasoningSummaryPartAddedEvent as ResponseReasoningSummaryPartAddedEvent,\n type ResponseReasoningSummaryPartDoneEvent as ResponseReasoningSummaryPartDoneEvent,\n type ResponseReasoningSummaryTextDeltaEvent as ResponseReasoningSummaryTextDeltaEvent,\n type ResponseReasoningSummaryTextDoneEvent as ResponseReasoningSummaryTextDoneEvent,\n type ResponseReasoningTextDeltaEvent as ResponseReasoningTextDeltaEvent,\n type ResponseReasoningTextDoneEvent as ResponseReasoningTextDoneEvent,\n type ResponseRefusalDeltaEvent as ResponseRefusalDeltaEvent,\n type ResponseRefusalDoneEvent as ResponseRefusalDoneEvent,\n type ResponseStatus as ResponseStatus,\n type ResponseStreamEvent as ResponseStreamEvent,\n type ResponseTextConfig as ResponseTextConfig,\n type ResponseTextDeltaEvent as ResponseTextDeltaEvent,\n type ResponseTextDoneEvent as ResponseTextDoneEvent,\n type ResponseToolSearchCall as ResponseToolSearchCall,\n type ResponseToolSearchOutputItem as ResponseToolSearchOutputItem,\n type ResponseToolSearchOutputItemParam as ResponseToolSearchOutputItemParam,\n type ResponseUsage as ResponseUsage,\n type ResponseWebSearchCallCompletedEvent as ResponseWebSearchCallCompletedEvent,\n type ResponseWebSearchCallInProgressEvent as ResponseWebSearchCallInProgressEvent,\n type ResponseWebSearchCallSearchingEvent as ResponseWebSearchCallSearchingEvent,\n type ResponsesClientEvent as ResponsesClientEvent,\n type ResponsesServerEvent as ResponsesServerEvent,\n type SkillReference as SkillReference,\n type Tool as Tool,\n type ToolChoiceAllowed as ToolChoiceAllowed,\n type ToolChoiceApplyPatch as ToolChoiceApplyPatch,\n type ToolChoiceCustom as ToolChoiceCustom,\n type ToolChoiceFunction as ToolChoiceFunction,\n type ToolChoiceMcp as ToolChoiceMcp,\n type ToolChoiceOptions as ToolChoiceOptions,\n type ToolChoiceShell as ToolChoiceShell,\n type ToolChoiceTypes as ToolChoiceTypes,\n type ToolSearchTool as ToolSearchTool,\n type WebSearchPreviewTool as WebSearchPreviewTool,\n type WebSearchTool as WebSearchTool,\n type ResponseCreateParams as ResponseCreateParams,\n type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming,\n type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming,\n type ResponseRetrieveParams as ResponseRetrieveParams,\n type ResponseRetrieveParamsNonStreaming as ResponseRetrieveParamsNonStreaming,\n type ResponseRetrieveParamsStreaming as ResponseRetrieveParamsStreaming,\n type ResponseCompactParams as ResponseCompactParams,\n };\n\n export {\n InputItems as InputItems,\n type ResponseItemList as ResponseItemList,\n type InputItemListParams as InputItemListParams,\n };\n\n export {\n InputTokens as InputTokens,\n type InputTokenCountResponse as InputTokenCountResponse,\n type InputTokenCountParams as InputTokenCountParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport { APIPromise } from '../../core/api-promise';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class Content extends APIResource {\n /**\n * Download a skill zip bundle by its ID.\n */\n retrieve(skillID: string, options?: RequestOptions): APIPromise<Response> {\n return this._client.get(path`/skills/${skillID}/content`, {\n ...options,\n headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n __binaryResponse: true,\n });\n }\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport { APIPromise } from '../../../core/api-promise';\nimport { buildHeaders } from '../../../internal/headers';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { path } from '../../../internal/utils/path';\n\nexport class Content extends APIResource {\n /**\n * Download a skill version zip bundle.\n */\n retrieve(version: string, params: ContentRetrieveParams, options?: RequestOptions): APIPromise<Response> {\n const { skill_id } = params;\n return this._client.get(path`/skills/${skill_id}/versions/${version}/content`, {\n ...options,\n headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n __binaryResponse: true,\n });\n }\n}\n\nexport interface ContentRetrieveParams {\n /**\n * The identifier of the skill.\n */\n skill_id: string;\n}\n\nexport declare namespace Content {\n export { type ContentRetrieveParams as ContentRetrieveParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../../core/resource';\nimport * as ContentAPI from './content';\nimport { Content, ContentRetrieveParams } from './content';\nimport { APIPromise } from '../../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';\nimport { type Uploadable } from '../../../core/uploads';\nimport { RequestOptions } from '../../../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../../../internal/uploads';\nimport { path } from '../../../internal/utils/path';\n\nexport class Versions extends APIResource {\n content: ContentAPI.Content = new ContentAPI.Content(this._client);\n\n /**\n * Create a new immutable skill version.\n */\n create(\n skillID: string,\n body: VersionCreateParams | null | undefined = {},\n options?: RequestOptions,\n ): APIPromise<SkillVersion> {\n return this._client.post(\n path`/skills/${skillID}/versions`,\n maybeMultipartFormRequestOptions({ body, ...options }, this._client),\n );\n }\n\n /**\n * Get a specific skill version.\n */\n retrieve(\n version: string,\n params: VersionRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<SkillVersion> {\n const { skill_id } = params;\n return this._client.get(path`/skills/${skill_id}/versions/${version}`, options);\n }\n\n /**\n * List skill versions for a skill.\n */\n list(\n skillID: string,\n query: VersionListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<SkillVersionsPage, SkillVersion> {\n return this._client.getAPIList(path`/skills/${skillID}/versions`, CursorPage<SkillVersion>, {\n query,\n ...options,\n });\n }\n\n /**\n * Delete a skill version.\n */\n delete(\n version: string,\n params: VersionDeleteParams,\n options?: RequestOptions,\n ): APIPromise<DeletedSkillVersion> {\n const { skill_id } = params;\n return this._client.delete(path`/skills/${skill_id}/versions/${version}`, options);\n }\n}\n\nexport type SkillVersionsPage = CursorPage<SkillVersion>;\n\nexport interface DeletedSkillVersion {\n id: string;\n\n deleted: boolean;\n\n object: 'skill.version.deleted';\n\n /**\n * The deleted skill version.\n */\n version: string;\n}\n\nexport interface SkillVersion {\n /**\n * Unique identifier for the skill version.\n */\n id: string;\n\n /**\n * Unix timestamp (seconds) for when the version was created.\n */\n created_at: number;\n\n /**\n * Description of the skill version.\n */\n description: string;\n\n /**\n * Name of the skill version.\n */\n name: string;\n\n /**\n * The object type, which is `skill.version`.\n */\n object: 'skill.version';\n\n /**\n * Identifier of the skill for this version.\n */\n skill_id: string;\n\n /**\n * Version number for this skill.\n */\n version: string;\n}\n\nexport interface SkillVersionList {\n /**\n * A list of items\n */\n data: Array<SkillVersion>;\n\n /**\n * The ID of the first item in the list.\n */\n first_id: string | null;\n\n /**\n * Whether there are more items available.\n */\n has_more: boolean;\n\n /**\n * The ID of the last item in the list.\n */\n last_id: string | null;\n\n /**\n * The type of object returned, must be `list`.\n */\n object: 'list';\n}\n\nexport interface VersionCreateParams {\n /**\n * Whether to set this version as the default.\n */\n default?: boolean;\n\n /**\n * Skill files to upload (directory upload) or a single zip file.\n */\n files?: Array<Uploadable> | Uploadable;\n}\n\nexport interface VersionRetrieveParams {\n /**\n * The identifier of the skill.\n */\n skill_id: string;\n}\n\nexport interface VersionListParams extends CursorPageParams {\n /**\n * Sort order of results by version number.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface VersionDeleteParams {\n /**\n * The identifier of the skill.\n */\n skill_id: string;\n}\n\nVersions.Content = Content;\n\nexport declare namespace Versions {\n export {\n type DeletedSkillVersion as DeletedSkillVersion,\n type SkillVersion as SkillVersion,\n type SkillVersionList as SkillVersionList,\n type SkillVersionsPage as SkillVersionsPage,\n type VersionCreateParams as VersionCreateParams,\n type VersionRetrieveParams as VersionRetrieveParams,\n type VersionListParams as VersionListParams,\n type VersionDeleteParams as VersionDeleteParams,\n };\n\n export { Content as Content, type ContentRetrieveParams as ContentRetrieveParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as ContentAPI from './content';\nimport { Content } from './content';\nimport * as VersionsAPI from './versions/versions';\nimport {\n DeletedSkillVersion,\n SkillVersion,\n SkillVersionList,\n SkillVersionsPage,\n VersionCreateParams,\n VersionDeleteParams,\n VersionListParams,\n VersionRetrieveParams,\n Versions,\n} from './versions/versions';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../../internal/uploads';\nimport { path } from '../../internal/utils/path';\n\nexport class Skills extends APIResource {\n content: ContentAPI.Content = new ContentAPI.Content(this._client);\n versions: VersionsAPI.Versions = new VersionsAPI.Versions(this._client);\n\n /**\n * Create a new skill.\n */\n create(body: SkillCreateParams | null | undefined = {}, options?: RequestOptions): APIPromise<Skill> {\n return this._client.post('/skills', maybeMultipartFormRequestOptions({ body, ...options }, this._client));\n }\n\n /**\n * Get a skill by its ID.\n */\n retrieve(skillID: string, options?: RequestOptions): APIPromise<Skill> {\n return this._client.get(path`/skills/${skillID}`, options);\n }\n\n /**\n * Update the default version pointer for a skill.\n */\n update(skillID: string, body: SkillUpdateParams, options?: RequestOptions): APIPromise<Skill> {\n return this._client.post(path`/skills/${skillID}`, { body, ...options });\n }\n\n /**\n * List all skills for the current project.\n */\n list(\n query: SkillListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<SkillsPage, Skill> {\n return this._client.getAPIList('/skills', CursorPage<Skill>, { query, ...options });\n }\n\n /**\n * Delete a skill by its ID.\n */\n delete(skillID: string, options?: RequestOptions): APIPromise<DeletedSkill> {\n return this._client.delete(path`/skills/${skillID}`, options);\n }\n}\n\nexport type SkillsPage = CursorPage<Skill>;\n\nexport interface DeletedSkill {\n id: string;\n\n deleted: boolean;\n\n object: 'skill.deleted';\n}\n\nexport interface Skill {\n /**\n * Unique identifier for the skill.\n */\n id: string;\n\n /**\n * Unix timestamp (seconds) for when the skill was created.\n */\n created_at: number;\n\n /**\n * Default version for the skill.\n */\n default_version: string;\n\n /**\n * Description of the skill.\n */\n description: string;\n\n /**\n * Latest version for the skill.\n */\n latest_version: string;\n\n /**\n * Name of the skill.\n */\n name: string;\n\n /**\n * The object type, which is `skill`.\n */\n object: 'skill';\n}\n\nexport interface SkillList {\n /**\n * A list of items\n */\n data: Array<Skill>;\n\n /**\n * The ID of the first item in the list.\n */\n first_id: string | null;\n\n /**\n * Whether there are more items available.\n */\n has_more: boolean;\n\n /**\n * The ID of the last item in the list.\n */\n last_id: string | null;\n\n /**\n * The type of object returned, must be `list`.\n */\n object: 'list';\n}\n\nexport interface SkillCreateParams {\n /**\n * Skill files to upload (directory upload) or a single zip file.\n */\n files?: Array<Uploadable> | Uploadable;\n}\n\nexport interface SkillUpdateParams {\n /**\n * The skill version number to set as default.\n */\n default_version: string;\n}\n\nexport interface SkillListParams extends CursorPageParams {\n /**\n * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for\n * descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nSkills.Content = Content;\nSkills.Versions = Versions;\n\nexport declare namespace Skills {\n export {\n type DeletedSkill as DeletedSkill,\n type Skill as Skill,\n type SkillList as SkillList,\n type SkillsPage as SkillsPage,\n type SkillCreateParams as SkillCreateParams,\n type SkillUpdateParams as SkillUpdateParams,\n type SkillListParams as SkillListParams,\n };\n\n export { Content as Content };\n\n export {\n Versions as Versions,\n type DeletedSkillVersion as DeletedSkillVersion,\n type SkillVersion as SkillVersion,\n type SkillVersionList as SkillVersionList,\n type SkillVersionsPage as SkillVersionsPage,\n type VersionCreateParams as VersionCreateParams,\n type VersionRetrieveParams as VersionRetrieveParams,\n type VersionListParams as VersionListParams,\n type VersionDeleteParams as VersionDeleteParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport { APIPromise } from '../../core/api-promise';\nimport { type Uploadable } from '../../core/uploads';\nimport { RequestOptions } from '../../internal/request-options';\nimport { multipartFormRequestOptions } from '../../internal/uploads';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Use Uploads to upload large files in multiple parts.\n */\nexport class Parts extends APIResource {\n /**\n * Adds a\n * [Part](https://platform.openai.com/docs/api-reference/uploads/part-object) to an\n * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object.\n * A Part represents a chunk of bytes from the file you are trying to upload.\n *\n * Each Part can be at most 64 MB, and you can add Parts until you hit the Upload\n * maximum of 8 GB.\n *\n * It is possible to add multiple Parts in parallel. You can decide the intended\n * order of the Parts when you\n * [complete the Upload](https://platform.openai.com/docs/api-reference/uploads/complete).\n */\n create(uploadID: string, body: PartCreateParams, options?: RequestOptions): APIPromise<UploadPart> {\n return this._client.post(\n path`/uploads/${uploadID}/parts`,\n multipartFormRequestOptions({ body, ...options }, this._client),\n );\n }\n}\n\n/**\n * The upload Part represents a chunk of bytes we can add to an Upload object.\n */\nexport interface UploadPart {\n /**\n * The upload Part unique identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the Part was created.\n */\n created_at: number;\n\n /**\n * The object type, which is always `upload.part`.\n */\n object: 'upload.part';\n\n /**\n * The ID of the Upload object that this Part was added to.\n */\n upload_id: string;\n}\n\nexport interface PartCreateParams {\n /**\n * The chunk of bytes for this Part.\n */\n data: Uploadable;\n}\n\nexport declare namespace Parts {\n export { type UploadPart as UploadPart, type PartCreateParams as PartCreateParams };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as FilesAPI from '../files';\nimport * as PartsAPI from './parts';\nimport { PartCreateParams, Parts, UploadPart } from './parts';\nimport { APIPromise } from '../../core/api-promise';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\n/**\n * Use Uploads to upload large files in multiple parts.\n */\nexport class Uploads extends APIResource {\n parts: PartsAPI.Parts = new PartsAPI.Parts(this._client);\n\n /**\n * Creates an intermediate\n * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object\n * that you can add\n * [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.\n * Currently, an Upload can accept at most 8 GB in total and expires after an hour\n * after you create it.\n *\n * Once you complete the Upload, we will create a\n * [File](https://platform.openai.com/docs/api-reference/files/object) object that\n * contains all the parts you uploaded. This File is usable in the rest of our\n * platform as a regular File object.\n *\n * For certain `purpose` values, the correct `mime_type` must be specified. Please\n * refer to documentation for the\n * [supported MIME types for your use case](https://platform.openai.com/docs/assistants/tools/file-search#supported-files).\n *\n * For guidance on the proper filename extensions for each purpose, please follow\n * the documentation on\n * [creating a File](https://platform.openai.com/docs/api-reference/files/create).\n *\n * Returns the Upload object with status `pending`.\n */\n create(body: UploadCreateParams, options?: RequestOptions): APIPromise<Upload> {\n return this._client.post('/uploads', { body, ...options });\n }\n\n /**\n * Cancels the Upload. No Parts may be added after an Upload is cancelled.\n *\n * Returns the Upload object with status `cancelled`.\n */\n cancel(uploadID: string, options?: RequestOptions): APIPromise<Upload> {\n return this._client.post(path`/uploads/${uploadID}/cancel`, options);\n }\n\n /**\n * Completes the\n * [Upload](https://platform.openai.com/docs/api-reference/uploads/object).\n *\n * Within the returned Upload object, there is a nested\n * [File](https://platform.openai.com/docs/api-reference/files/object) object that\n * is ready to use in the rest of the platform.\n *\n * You can specify the order of the Parts by passing in an ordered list of the Part\n * IDs.\n *\n * The number of bytes uploaded upon completion must match the number of bytes\n * initially specified when creating the Upload object. No Parts may be added after\n * an Upload is completed. Returns the Upload object with status `completed`,\n * including an additional `file` property containing the created usable File\n * object.\n */\n complete(uploadID: string, body: UploadCompleteParams, options?: RequestOptions): APIPromise<Upload> {\n return this._client.post(path`/uploads/${uploadID}/complete`, { body, ...options });\n }\n}\n\n/**\n * The Upload object can accept byte chunks in the form of Parts.\n */\nexport interface Upload {\n /**\n * The Upload unique identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The intended number of bytes to be uploaded.\n */\n bytes: number;\n\n /**\n * The Unix timestamp (in seconds) for when the Upload was created.\n */\n created_at: number;\n\n /**\n * The Unix timestamp (in seconds) for when the Upload will expire.\n */\n expires_at: number;\n\n /**\n * The name of the file to be uploaded.\n */\n filename: string;\n\n /**\n * The object type, which is always \"upload\".\n */\n object: 'upload';\n\n /**\n * The intended purpose of the file.\n * [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose)\n * for acceptable values.\n */\n purpose: string;\n\n /**\n * The status of the Upload.\n */\n status: 'pending' | 'completed' | 'cancelled' | 'expired';\n\n /**\n * The `File` object represents a document that has been uploaded to OpenAI.\n */\n file?: FilesAPI.FileObject | null;\n}\n\nexport interface UploadCreateParams {\n /**\n * The number of bytes in the file you are uploading.\n */\n bytes: number;\n\n /**\n * The name of the file to upload.\n */\n filename: string;\n\n /**\n * The MIME type of the file.\n *\n * This must fall within the supported MIME types for your file purpose. See the\n * supported MIME types for assistants and vision.\n */\n mime_type: string;\n\n /**\n * The intended purpose of the uploaded file.\n *\n * See the\n * [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).\n */\n purpose: FilesAPI.FilePurpose;\n\n /**\n * The expiration policy for a file. By default, files with `purpose=batch` expire\n * after 30 days and all other files are persisted until they are manually deleted.\n */\n expires_after?: UploadCreateParams.ExpiresAfter;\n}\n\nexport namespace UploadCreateParams {\n /**\n * The expiration policy for a file. By default, files with `purpose=batch` expire\n * after 30 days and all other files are persisted until they are manually deleted.\n */\n export interface ExpiresAfter {\n /**\n * Anchor timestamp after which the expiration policy applies. Supported anchors:\n * `created_at`.\n */\n anchor: 'created_at';\n\n /**\n * The number of seconds after the anchor time that the file will expire. Must be\n * between 3600 (1 hour) and 2592000 (30 days).\n */\n seconds: number;\n }\n}\n\nexport interface UploadCompleteParams {\n /**\n * The ordered list of Part IDs.\n */\n part_ids: Array<string>;\n\n /**\n * The optional md5 checksum for the file contents to verify if the bytes uploaded\n * matches what you expect.\n */\n md5?: string;\n}\n\nUploads.Parts = Parts;\n\nexport declare namespace Uploads {\n export {\n type Upload as Upload,\n type UploadCreateParams as UploadCreateParams,\n type UploadCompleteParams as UploadCompleteParams,\n };\n\n export { Parts as Parts, type UploadPart as UploadPart, type PartCreateParams as PartCreateParams };\n}\n","/**\n * Like `Promise.allSettled()` but throws an error if any promises are rejected.\n */\nexport const allSettledWithThrow = async <R>(promises: Promise<R>[]): Promise<R[]> => {\n const results = await Promise.allSettled(promises);\n const rejected = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');\n if (rejected.length) {\n for (const result of rejected) {\n console.error(result.reason);\n }\n\n throw new Error(`${rejected.length} promise(s) failed - see the above errors`);\n }\n\n // Note: TS was complaining about using `.filter().map()` here for some reason\n const values: R[] = [];\n for (const result of results) {\n if (result.status === 'fulfilled') {\n values.push(result.value);\n }\n }\n return values;\n};\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as FilesAPI from './files';\nimport { VectorStoreFilesPage } from './files';\nimport * as VectorStoresAPI from './vector-stores';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { sleep } from '../../internal/utils/sleep';\nimport { type Uploadable } from '../../uploads';\nimport { allSettledWithThrow } from '../../lib/Util';\nimport { path } from '../../internal/utils/path';\n\nexport class FileBatches extends APIResource {\n /**\n * Create a vector store file batch.\n */\n create(\n vectorStoreID: string,\n body: FileBatchCreateParams,\n options?: RequestOptions,\n ): APIPromise<VectorStoreFileBatch> {\n return this._client.post(path`/vector_stores/${vectorStoreID}/file_batches`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Retrieves a vector store file batch.\n */\n retrieve(\n batchID: string,\n params: FileBatchRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<VectorStoreFileBatch> {\n const { vector_store_id } = params;\n return this._client.get(path`/vector_stores/${vector_store_id}/file_batches/${batchID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Cancel a vector store file batch. This attempts to cancel the processing of\n * files in this batch as soon as possible.\n */\n cancel(\n batchID: string,\n params: FileBatchCancelParams,\n options?: RequestOptions,\n ): APIPromise<VectorStoreFileBatch> {\n const { vector_store_id } = params;\n return this._client.post(path`/vector_stores/${vector_store_id}/file_batches/${batchID}/cancel`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Create a vector store batch and poll until all files have been processed.\n */\n async createAndPoll(\n vectorStoreId: string,\n body: FileBatchCreateParams,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<VectorStoreFileBatch> {\n const batch = await this.create(vectorStoreId, body);\n return await this.poll(vectorStoreId, batch.id, options);\n }\n\n /**\n * Returns a list of vector store files in a batch.\n */\n listFiles(\n batchID: string,\n params: FileBatchListFilesParams,\n options?: RequestOptions,\n ): PagePromise<VectorStoreFilesPage, FilesAPI.VectorStoreFile> {\n const { vector_store_id, ...query } = params;\n return this._client.getAPIList(\n path`/vector_stores/${vector_store_id}/file_batches/${batchID}/files`,\n CursorPage<FilesAPI.VectorStoreFile>,\n { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]) },\n );\n }\n\n /**\n * Wait for the given file batch to be processed.\n *\n * Note: this will return even if one of the files failed to process, you need to\n * check batch.file_counts.failed_count to handle this case.\n */\n async poll(\n vectorStoreID: string,\n batchID: string,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<VectorStoreFileBatch> {\n const headers = buildHeaders([\n options?.headers,\n {\n 'X-Stainless-Poll-Helper': 'true',\n 'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined,\n },\n ]);\n\n while (true) {\n const { data: batch, response } = await this.retrieve(\n batchID,\n { vector_store_id: vectorStoreID },\n {\n ...options,\n headers,\n },\n ).withResponse();\n\n switch (batch.status) {\n case 'in_progress':\n let sleepInterval = 5000;\n\n if (options?.pollIntervalMs) {\n sleepInterval = options.pollIntervalMs;\n } else {\n const headerInterval = response.headers.get('openai-poll-after-ms');\n if (headerInterval) {\n const headerIntervalMs = parseInt(headerInterval);\n if (!isNaN(headerIntervalMs)) {\n sleepInterval = headerIntervalMs;\n }\n }\n }\n await sleep(sleepInterval);\n break;\n case 'failed':\n case 'cancelled':\n case 'completed':\n return batch;\n }\n }\n }\n\n /**\n * Uploads the given files concurrently and then creates a vector store file batch.\n *\n * The concurrency limit is configurable using the `maxConcurrency` parameter.\n */\n async uploadAndPoll(\n vectorStoreId: string,\n { files, fileIds = [] }: { files: Uploadable[]; fileIds?: string[] },\n options?: RequestOptions & { pollIntervalMs?: number; maxConcurrency?: number },\n ): Promise<VectorStoreFileBatch> {\n if (files == null || files.length == 0) {\n throw new Error(\n `No \\`files\\` provided to process. If you've already uploaded files you should use \\`.createAndPoll()\\` instead`,\n );\n }\n\n const configuredConcurrency = options?.maxConcurrency ?? 5;\n\n // We cap the number of workers at the number of files (so we don't start any unnecessary workers)\n const concurrencyLimit = Math.min(configuredConcurrency, files.length);\n\n const client = this._client;\n const fileIterator = files.values();\n const allFileIds: string[] = [...fileIds];\n\n // This code is based on this design. The libraries don't accommodate our environment limits.\n // https://stackoverflow.com/questions/40639432/what-is-the-best-way-to-limit-concurrency-when-using-es6s-promise-all\n async function processFiles(iterator: IterableIterator<Uploadable>) {\n for (let item of iterator) {\n const fileObj = await client.files.create({ file: item, purpose: 'assistants' }, options);\n allFileIds.push(fileObj.id);\n }\n }\n\n // Start workers to process results\n const workers = Array(concurrencyLimit).fill(fileIterator).map(processFiles);\n\n // Wait for all processing to complete.\n await allSettledWithThrow(workers);\n\n return await this.createAndPoll(vectorStoreId, {\n file_ids: allFileIds,\n });\n }\n}\n\n/**\n * A batch of files attached to a vector store.\n */\nexport interface VectorStoreFileBatch {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the vector store files batch was\n * created.\n */\n created_at: number;\n\n file_counts: VectorStoreFileBatch.FileCounts;\n\n /**\n * The object type, which is always `vector_store.file_batch`.\n */\n object: 'vector_store.files_batch';\n\n /**\n * The status of the vector store files batch, which can be either `in_progress`,\n * `completed`, `cancelled` or `failed`.\n */\n status: 'in_progress' | 'completed' | 'cancelled' | 'failed';\n\n /**\n * The ID of the\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * that the [File](https://platform.openai.com/docs/api-reference/files) is\n * attached to.\n */\n vector_store_id: string;\n}\n\nexport namespace VectorStoreFileBatch {\n export interface FileCounts {\n /**\n * The number of files that where cancelled.\n */\n cancelled: number;\n\n /**\n * The number of files that have been processed.\n */\n completed: number;\n\n /**\n * The number of files that have failed to process.\n */\n failed: number;\n\n /**\n * The number of files that are currently being processed.\n */\n in_progress: number;\n\n /**\n * The total number of files.\n */\n total: number;\n }\n}\n\nexport interface FileBatchCreateParams {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters, booleans, or numbers.\n */\n attributes?: { [key: string]: string | number | boolean } | null;\n\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy. Only applicable if `file_ids` is non-empty.\n */\n chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;\n\n /**\n * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that\n * the vector store should use. Useful for tools like `file_search` that can access\n * files. If `attributes` or `chunking_strategy` are provided, they will be applied\n * to all files in the batch. The maximum batch size is 2000 files. Mutually\n * exclusive with `files`.\n */\n file_ids?: Array<string>;\n\n /**\n * A list of objects that each include a `file_id` plus optional `attributes` or\n * `chunking_strategy`. Use this when you need to override metadata for specific\n * files. The global `attributes` or `chunking_strategy` will be ignored and must\n * be specified for each file. The maximum batch size is 2000 files. Mutually\n * exclusive with `file_ids`.\n */\n files?: Array<FileBatchCreateParams.File>;\n}\n\nexport namespace FileBatchCreateParams {\n export interface File {\n /**\n * A [File](https://platform.openai.com/docs/api-reference/files) ID that the\n * vector store should use. Useful for tools like `file_search` that can access\n * files.\n */\n file_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters, booleans, or numbers.\n */\n attributes?: { [key: string]: string | number | boolean } | null;\n\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy. Only applicable if `file_ids` is non-empty.\n */\n chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;\n }\n}\n\nexport interface FileBatchRetrieveParams {\n /**\n * The ID of the vector store that the file batch belongs to.\n */\n vector_store_id: string;\n}\n\nexport interface FileBatchCancelParams {\n /**\n * The ID of the vector store that the file batch belongs to.\n */\n vector_store_id: string;\n}\n\nexport interface FileBatchListFilesParams extends CursorPageParams {\n /**\n * Path param: The ID of the vector store that the files belong to.\n */\n vector_store_id: string;\n\n /**\n * Query param: A cursor for use in pagination. `before` is an object ID that\n * defines your place in the list. For instance, if you make a list request and\n * receive 100 objects, starting with obj_foo, your subsequent call can include\n * before=obj_foo in order to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Query param: Filter by file status. One of `in_progress`, `completed`, `failed`,\n * `cancelled`.\n */\n filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';\n\n /**\n * Query param: Sort order by the `created_at` timestamp of the objects. `asc` for\n * ascending order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport declare namespace FileBatches {\n export {\n type VectorStoreFileBatch as VectorStoreFileBatch,\n type FileBatchCreateParams as FileBatchCreateParams,\n type FileBatchRetrieveParams as FileBatchRetrieveParams,\n type FileBatchCancelParams as FileBatchCancelParams,\n type FileBatchListFilesParams as FileBatchListFilesParams,\n };\n}\n\nexport { type VectorStoreFilesPage };\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as VectorStoresAPI from './vector-stores';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, PagePromise, Page } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { sleep } from '../../internal/utils';\nimport { Uploadable } from '../../uploads';\nimport { path } from '../../internal/utils/path';\n\nexport class Files extends APIResource {\n /**\n * Create a vector store file by attaching a\n * [File](https://platform.openai.com/docs/api-reference/files) to a\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object).\n */\n create(\n vectorStoreID: string,\n body: FileCreateParams,\n options?: RequestOptions,\n ): APIPromise<VectorStoreFile> {\n return this._client.post(path`/vector_stores/${vectorStoreID}/files`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Retrieves a vector store file.\n */\n retrieve(\n fileID: string,\n params: FileRetrieveParams,\n options?: RequestOptions,\n ): APIPromise<VectorStoreFile> {\n const { vector_store_id } = params;\n return this._client.get(path`/vector_stores/${vector_store_id}/files/${fileID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Update attributes on a vector store file.\n */\n update(fileID: string, params: FileUpdateParams, options?: RequestOptions): APIPromise<VectorStoreFile> {\n const { vector_store_id, ...body } = params;\n return this._client.post(path`/vector_stores/${vector_store_id}/files/${fileID}`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Returns a list of vector store files.\n */\n list(\n vectorStoreID: string,\n query: FileListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<VectorStoreFilesPage, VectorStoreFile> {\n return this._client.getAPIList(path`/vector_stores/${vectorStoreID}/files`, CursorPage<VectorStoreFile>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Delete a vector store file. This will remove the file from the vector store but\n * the file itself will not be deleted. To delete the file, use the\n * [delete file](https://platform.openai.com/docs/api-reference/files/delete)\n * endpoint.\n */\n delete(\n fileID: string,\n params: FileDeleteParams,\n options?: RequestOptions,\n ): APIPromise<VectorStoreFileDeleted> {\n const { vector_store_id } = params;\n return this._client.delete(path`/vector_stores/${vector_store_id}/files/${fileID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Attach a file to the given vector store and wait for it to be processed.\n */\n async createAndPoll(\n vectorStoreId: string,\n body: FileCreateParams,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<VectorStoreFile> {\n const file = await this.create(vectorStoreId, body, options);\n return await this.poll(vectorStoreId, file.id, options);\n }\n /**\n * Wait for the vector store file to finish processing.\n *\n * Note: this will return even if the file failed to process, you need to check\n * file.last_error and file.status to handle these cases\n */\n async poll(\n vectorStoreID: string,\n fileID: string,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<VectorStoreFile> {\n const headers = buildHeaders([\n options?.headers,\n {\n 'X-Stainless-Poll-Helper': 'true',\n 'X-Stainless-Custom-Poll-Interval': options?.pollIntervalMs?.toString() ?? undefined,\n },\n ]);\n\n while (true) {\n const fileResponse = await this.retrieve(\n fileID,\n {\n vector_store_id: vectorStoreID,\n },\n { ...options, headers },\n ).withResponse();\n\n const file = fileResponse.data;\n\n switch (file.status) {\n case 'in_progress':\n let sleepInterval = 5000;\n\n if (options?.pollIntervalMs) {\n sleepInterval = options.pollIntervalMs;\n } else {\n const headerInterval = fileResponse.response.headers.get('openai-poll-after-ms');\n if (headerInterval) {\n const headerIntervalMs = parseInt(headerInterval);\n if (!isNaN(headerIntervalMs)) {\n sleepInterval = headerIntervalMs;\n }\n }\n }\n await sleep(sleepInterval);\n break;\n case 'failed':\n case 'completed':\n return file;\n }\n }\n }\n /**\n * Upload a file to the `files` API and then attach it to the given vector store.\n *\n * Note the file will be asynchronously processed (you can use the alternative\n * polling helper method to wait for processing to complete).\n */\n async upload(vectorStoreId: string, file: Uploadable, options?: RequestOptions): Promise<VectorStoreFile> {\n const fileInfo = await this._client.files.create({ file: file, purpose: 'assistants' }, options);\n return this.create(vectorStoreId, { file_id: fileInfo.id }, options);\n }\n /**\n * Add a file to a vector store and poll until processing is complete.\n */\n async uploadAndPoll(\n vectorStoreId: string,\n file: Uploadable,\n options?: RequestOptions & { pollIntervalMs?: number },\n ): Promise<VectorStoreFile> {\n const fileInfo = await this.upload(vectorStoreId, file, options);\n return await this.poll(vectorStoreId, fileInfo.id, options);\n }\n\n /**\n * Retrieve the parsed contents of a vector store file.\n */\n content(\n fileID: string,\n params: FileContentParams,\n options?: RequestOptions,\n ): PagePromise<FileContentResponsesPage, FileContentResponse> {\n const { vector_store_id } = params;\n return this._client.getAPIList(\n path`/vector_stores/${vector_store_id}/files/${fileID}/content`,\n Page<FileContentResponse>,\n { ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]) },\n );\n }\n}\n\nexport type VectorStoreFilesPage = CursorPage<VectorStoreFile>;\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type FileContentResponsesPage = Page<FileContentResponse>;\n\n/**\n * A list of files attached to a vector store.\n */\nexport interface VectorStoreFile {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the vector store file was created.\n */\n created_at: number;\n\n /**\n * The last error associated with this vector store file. Will be `null` if there\n * are no errors.\n */\n last_error: VectorStoreFile.LastError | null;\n\n /**\n * The object type, which is always `vector_store.file`.\n */\n object: 'vector_store.file';\n\n /**\n * The status of the vector store file, which can be either `in_progress`,\n * `completed`, `cancelled`, or `failed`. The status `completed` indicates that the\n * vector store file is ready for use.\n */\n status: 'in_progress' | 'completed' | 'cancelled' | 'failed';\n\n /**\n * The total vector store usage in bytes. Note that this may be different from the\n * original file size.\n */\n usage_bytes: number;\n\n /**\n * The ID of the\n * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)\n * that the [File](https://platform.openai.com/docs/api-reference/files) is\n * attached to.\n */\n vector_store_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters, booleans, or numbers.\n */\n attributes?: { [key: string]: string | number | boolean } | null;\n\n /**\n * The strategy used to chunk the file.\n */\n chunking_strategy?: VectorStoresAPI.FileChunkingStrategy;\n}\n\nexport namespace VectorStoreFile {\n /**\n * The last error associated with this vector store file. Will be `null` if there\n * are no errors.\n */\n export interface LastError {\n /**\n * One of `server_error`, `unsupported_file`, or `invalid_file`.\n */\n code: 'server_error' | 'unsupported_file' | 'invalid_file';\n\n /**\n * A human-readable description of the error.\n */\n message: string;\n }\n}\n\nexport interface VectorStoreFileDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'vector_store.file.deleted';\n}\n\nexport interface FileContentResponse {\n /**\n * The text content\n */\n text?: string;\n\n /**\n * The content type (currently only `\"text\"`)\n */\n type?: string;\n}\n\nexport interface FileCreateParams {\n /**\n * A [File](https://platform.openai.com/docs/api-reference/files) ID that the\n * vector store should use. Useful for tools like `file_search` that can access\n * files.\n */\n file_id: string;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters, booleans, or numbers.\n */\n attributes?: { [key: string]: string | number | boolean } | null;\n\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy. Only applicable if `file_ids` is non-empty.\n */\n chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;\n}\n\nexport interface FileRetrieveParams {\n /**\n * The ID of the vector store that the file belongs to.\n */\n vector_store_id: string;\n}\n\nexport interface FileUpdateParams {\n /**\n * Path param: The ID of the vector store the file belongs to.\n */\n vector_store_id: string;\n\n /**\n * Body param: Set of 16 key-value pairs that can be attached to an object. This\n * can be useful for storing additional information about the object in a\n * structured format, and querying for objects via API or the dashboard. Keys are\n * strings with a maximum length of 64 characters. Values are strings with a\n * maximum length of 512 characters, booleans, or numbers.\n */\n attributes: { [key: string]: string | number | boolean } | null;\n}\n\nexport interface FileListParams extends CursorPageParams {\n /**\n * A cursor for use in pagination. `before` is an object ID that defines your place\n * in the list. For instance, if you make a list request and receive 100 objects,\n * starting with obj_foo, your subsequent call can include before=obj_foo in order\n * to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`.\n */\n filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';\n\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface FileDeleteParams {\n /**\n * The ID of the vector store that the file belongs to.\n */\n vector_store_id: string;\n}\n\nexport interface FileContentParams {\n /**\n * The ID of the vector store.\n */\n vector_store_id: string;\n}\n\nexport declare namespace Files {\n export {\n type VectorStoreFile as VectorStoreFile,\n type VectorStoreFileDeleted as VectorStoreFileDeleted,\n type FileContentResponse as FileContentResponse,\n type VectorStoreFilesPage as VectorStoreFilesPage,\n type FileContentResponsesPage as FileContentResponsesPage,\n type FileCreateParams as FileCreateParams,\n type FileRetrieveParams as FileRetrieveParams,\n type FileUpdateParams as FileUpdateParams,\n type FileListParams as FileListParams,\n type FileDeleteParams as FileDeleteParams,\n type FileContentParams as FileContentParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../../core/resource';\nimport * as Shared from '../shared';\nimport * as FileBatchesAPI from './file-batches';\nimport {\n FileBatchCancelParams,\n FileBatchCreateParams,\n FileBatchListFilesParams,\n FileBatchRetrieveParams,\n FileBatches,\n VectorStoreFileBatch,\n} from './file-batches';\nimport * as FilesAPI from './files';\nimport {\n FileContentParams,\n FileContentResponse,\n FileContentResponsesPage,\n FileCreateParams,\n FileDeleteParams,\n FileListParams,\n FileRetrieveParams,\n FileUpdateParams,\n Files,\n VectorStoreFile,\n VectorStoreFileDeleted,\n VectorStoreFilesPage,\n} from './files';\nimport { APIPromise } from '../../core/api-promise';\nimport { CursorPage, type CursorPageParams, Page, PagePromise } from '../../core/pagination';\nimport { buildHeaders } from '../../internal/headers';\nimport { RequestOptions } from '../../internal/request-options';\nimport { path } from '../../internal/utils/path';\n\nexport class VectorStores extends APIResource {\n files: FilesAPI.Files = new FilesAPI.Files(this._client);\n fileBatches: FileBatchesAPI.FileBatches = new FileBatchesAPI.FileBatches(this._client);\n\n /**\n * Create a vector store.\n */\n create(body: VectorStoreCreateParams, options?: RequestOptions): APIPromise<VectorStore> {\n return this._client.post('/vector_stores', {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Retrieves a vector store.\n */\n retrieve(vectorStoreID: string, options?: RequestOptions): APIPromise<VectorStore> {\n return this._client.get(path`/vector_stores/${vectorStoreID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Modifies a vector store.\n */\n update(\n vectorStoreID: string,\n body: VectorStoreUpdateParams,\n options?: RequestOptions,\n ): APIPromise<VectorStore> {\n return this._client.post(path`/vector_stores/${vectorStoreID}`, {\n body,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Returns a list of vector stores.\n */\n list(\n query: VectorStoreListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<VectorStoresPage, VectorStore> {\n return this._client.getAPIList('/vector_stores', CursorPage<VectorStore>, {\n query,\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Delete a vector store.\n */\n delete(vectorStoreID: string, options?: RequestOptions): APIPromise<VectorStoreDeleted> {\n return this._client.delete(path`/vector_stores/${vectorStoreID}`, {\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n });\n }\n\n /**\n * Search a vector store for relevant chunks based on a query and file attributes\n * filter.\n */\n search(\n vectorStoreID: string,\n body: VectorStoreSearchParams,\n options?: RequestOptions,\n ): PagePromise<VectorStoreSearchResponsesPage, VectorStoreSearchResponse> {\n return this._client.getAPIList(\n path`/vector_stores/${vectorStoreID}/search`,\n Page<VectorStoreSearchResponse>,\n {\n body,\n method: 'post',\n ...options,\n headers: buildHeaders([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),\n },\n );\n }\n}\n\nexport type VectorStoresPage = CursorPage<VectorStore>;\n\n// Note: no pagination actually occurs yet, this is for forwards-compatibility.\nexport type VectorStoreSearchResponsesPage = Page<VectorStoreSearchResponse>;\n\n/**\n * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of\n * `800` and `chunk_overlap_tokens` of `400`.\n */\nexport interface AutoFileChunkingStrategyParam {\n /**\n * Always `auto`.\n */\n type: 'auto';\n}\n\n/**\n * The strategy used to chunk the file.\n */\nexport type FileChunkingStrategy = StaticFileChunkingStrategyObject | OtherFileChunkingStrategyObject;\n\n/**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy. Only applicable if `file_ids` is non-empty.\n */\nexport type FileChunkingStrategyParam = AutoFileChunkingStrategyParam | StaticFileChunkingStrategyObjectParam;\n\n/**\n * This is returned when the chunking strategy is unknown. Typically, this is\n * because the file was indexed before the `chunking_strategy` concept was\n * introduced in the API.\n */\nexport interface OtherFileChunkingStrategyObject {\n /**\n * Always `other`.\n */\n type: 'other';\n}\n\nexport interface StaticFileChunkingStrategy {\n /**\n * The number of tokens that overlap between chunks. The default value is `400`.\n *\n * Note that the overlap must not exceed half of `max_chunk_size_tokens`.\n */\n chunk_overlap_tokens: number;\n\n /**\n * The maximum number of tokens in each chunk. The default value is `800`. The\n * minimum value is `100` and the maximum value is `4096`.\n */\n max_chunk_size_tokens: number;\n}\n\nexport interface StaticFileChunkingStrategyObject {\n static: StaticFileChunkingStrategy;\n\n /**\n * Always `static`.\n */\n type: 'static';\n}\n\n/**\n * Customize your own chunking strategy by setting chunk size and chunk overlap.\n */\nexport interface StaticFileChunkingStrategyObjectParam {\n static: StaticFileChunkingStrategy;\n\n /**\n * Always `static`.\n */\n type: 'static';\n}\n\n/**\n * A vector store is a collection of processed files can be used by the\n * `file_search` tool.\n */\nexport interface VectorStore {\n /**\n * The identifier, which can be referenced in API endpoints.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) for when the vector store was created.\n */\n created_at: number;\n\n file_counts: VectorStore.FileCounts;\n\n /**\n * The Unix timestamp (in seconds) for when the vector store was last active.\n */\n last_active_at: number | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata: Shared.Metadata | null;\n\n /**\n * The name of the vector store.\n */\n name: string;\n\n /**\n * The object type, which is always `vector_store`.\n */\n object: 'vector_store';\n\n /**\n * The status of the vector store, which can be either `expired`, `in_progress`, or\n * `completed`. A status of `completed` indicates that the vector store is ready\n * for use.\n */\n status: 'expired' | 'in_progress' | 'completed';\n\n /**\n * The total number of bytes used by the files in the vector store.\n */\n usage_bytes: number;\n\n /**\n * The expiration policy for a vector store.\n */\n expires_after?: VectorStore.ExpiresAfter;\n\n /**\n * The Unix timestamp (in seconds) for when the vector store will expire.\n */\n expires_at?: number | null;\n}\n\nexport namespace VectorStore {\n export interface FileCounts {\n /**\n * The number of files that were cancelled.\n */\n cancelled: number;\n\n /**\n * The number of files that have been successfully processed.\n */\n completed: number;\n\n /**\n * The number of files that have failed to process.\n */\n failed: number;\n\n /**\n * The number of files that are currently being processed.\n */\n in_progress: number;\n\n /**\n * The total number of files.\n */\n total: number;\n }\n\n /**\n * The expiration policy for a vector store.\n */\n export interface ExpiresAfter {\n /**\n * Anchor timestamp after which the expiration policy applies. Supported anchors:\n * `last_active_at`.\n */\n anchor: 'last_active_at';\n\n /**\n * The number of days after the anchor time that the vector store will expire.\n */\n days: number;\n }\n}\n\nexport interface VectorStoreDeleted {\n id: string;\n\n deleted: boolean;\n\n object: 'vector_store.deleted';\n}\n\nexport interface VectorStoreSearchResponse {\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard. Keys are strings with a maximum\n * length of 64 characters. Values are strings with a maximum length of 512\n * characters, booleans, or numbers.\n */\n attributes: { [key: string]: string | number | boolean } | null;\n\n /**\n * Content chunks from the file.\n */\n content: Array<VectorStoreSearchResponse.Content>;\n\n /**\n * The ID of the vector store file.\n */\n file_id: string;\n\n /**\n * The name of the vector store file.\n */\n filename: string;\n\n /**\n * The similarity score for the result.\n */\n score: number;\n}\n\nexport namespace VectorStoreSearchResponse {\n export interface Content {\n /**\n * The text content returned from search.\n */\n text: string;\n\n /**\n * The type of content.\n */\n type: 'text';\n }\n}\n\nexport interface VectorStoreCreateParams {\n /**\n * The chunking strategy used to chunk the file(s). If not set, will use the `auto`\n * strategy. Only applicable if `file_ids` is non-empty.\n */\n chunking_strategy?: FileChunkingStrategyParam;\n\n /**\n * A description for the vector store. Can be used to describe the vector store's\n * purpose.\n */\n description?: string;\n\n /**\n * The expiration policy for a vector store.\n */\n expires_after?: VectorStoreCreateParams.ExpiresAfter;\n\n /**\n * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that\n * the vector store should use. Useful for tools like `file_search` that can access\n * files.\n */\n file_ids?: Array<string>;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The name of the vector store.\n */\n name?: string;\n}\n\nexport namespace VectorStoreCreateParams {\n /**\n * The expiration policy for a vector store.\n */\n export interface ExpiresAfter {\n /**\n * Anchor timestamp after which the expiration policy applies. Supported anchors:\n * `last_active_at`.\n */\n anchor: 'last_active_at';\n\n /**\n * The number of days after the anchor time that the vector store will expire.\n */\n days: number;\n }\n}\n\nexport interface VectorStoreUpdateParams {\n /**\n * The expiration policy for a vector store.\n */\n expires_after?: VectorStoreUpdateParams.ExpiresAfter | null;\n\n /**\n * Set of 16 key-value pairs that can be attached to an object. This can be useful\n * for storing additional information about the object in a structured format, and\n * querying for objects via API or the dashboard.\n *\n * Keys are strings with a maximum length of 64 characters. Values are strings with\n * a maximum length of 512 characters.\n */\n metadata?: Shared.Metadata | null;\n\n /**\n * The name of the vector store.\n */\n name?: string | null;\n}\n\nexport namespace VectorStoreUpdateParams {\n /**\n * The expiration policy for a vector store.\n */\n export interface ExpiresAfter {\n /**\n * Anchor timestamp after which the expiration policy applies. Supported anchors:\n * `last_active_at`.\n */\n anchor: 'last_active_at';\n\n /**\n * The number of days after the anchor time that the vector store will expire.\n */\n days: number;\n }\n}\n\nexport interface VectorStoreListParams extends CursorPageParams {\n /**\n * A cursor for use in pagination. `before` is an object ID that defines your place\n * in the list. For instance, if you make a list request and receive 100 objects,\n * starting with obj_foo, your subsequent call can include before=obj_foo in order\n * to fetch the previous page of the list.\n */\n before?: string;\n\n /**\n * Sort order by the `created_at` timestamp of the objects. `asc` for ascending\n * order and `desc` for descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface VectorStoreSearchParams {\n /**\n * A query string for a search\n */\n query: string | Array<string>;\n\n /**\n * A filter to apply based on file attributes.\n */\n filters?: Shared.ComparisonFilter | Shared.CompoundFilter;\n\n /**\n * The maximum number of results to return. This number should be between 1 and 50\n * inclusive.\n */\n max_num_results?: number;\n\n /**\n * Ranking options for search.\n */\n ranking_options?: VectorStoreSearchParams.RankingOptions;\n\n /**\n * Whether to rewrite the natural language query for vector search.\n */\n rewrite_query?: boolean;\n}\n\nexport namespace VectorStoreSearchParams {\n /**\n * Ranking options for search.\n */\n export interface RankingOptions {\n /**\n * Enable re-ranking; set to `none` to disable, which can help reduce latency.\n */\n ranker?: 'none' | 'auto' | 'default-2024-11-15';\n\n score_threshold?: number;\n }\n}\n\nVectorStores.Files = Files;\nVectorStores.FileBatches = FileBatches;\n\nexport declare namespace VectorStores {\n export {\n type AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam,\n type FileChunkingStrategy as FileChunkingStrategy,\n type FileChunkingStrategyParam as FileChunkingStrategyParam,\n type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,\n type StaticFileChunkingStrategy as StaticFileChunkingStrategy,\n type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,\n type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,\n type VectorStore as VectorStore,\n type VectorStoreDeleted as VectorStoreDeleted,\n type VectorStoreSearchResponse as VectorStoreSearchResponse,\n type VectorStoresPage as VectorStoresPage,\n type VectorStoreSearchResponsesPage as VectorStoreSearchResponsesPage,\n type VectorStoreCreateParams as VectorStoreCreateParams,\n type VectorStoreUpdateParams as VectorStoreUpdateParams,\n type VectorStoreListParams as VectorStoreListParams,\n type VectorStoreSearchParams as VectorStoreSearchParams,\n };\n\n export {\n Files as Files,\n type VectorStoreFile as VectorStoreFile,\n type VectorStoreFileDeleted as VectorStoreFileDeleted,\n type FileContentResponse as FileContentResponse,\n type VectorStoreFilesPage as VectorStoreFilesPage,\n type FileContentResponsesPage as FileContentResponsesPage,\n type FileCreateParams as FileCreateParams,\n type FileRetrieveParams as FileRetrieveParams,\n type FileUpdateParams as FileUpdateParams,\n type FileListParams as FileListParams,\n type FileDeleteParams as FileDeleteParams,\n type FileContentParams as FileContentParams,\n };\n\n export {\n FileBatches as FileBatches,\n type VectorStoreFileBatch as VectorStoreFileBatch,\n type FileBatchCreateParams as FileBatchCreateParams,\n type FileBatchRetrieveParams as FileBatchRetrieveParams,\n type FileBatchCancelParams as FileBatchCancelParams,\n type FileBatchListFilesParams as FileBatchListFilesParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { APIResource } from '../core/resource';\nimport { APIPromise } from '../core/api-promise';\nimport { ConversationCursorPage, type ConversationCursorPageParams, PagePromise } from '../core/pagination';\nimport { type Uploadable } from '../core/uploads';\nimport { buildHeaders } from '../internal/headers';\nimport { RequestOptions } from '../internal/request-options';\nimport { maybeMultipartFormRequestOptions } from '../internal/uploads';\nimport { path } from '../internal/utils/path';\n\nexport class Videos extends APIResource {\n /**\n * Create a new video generation job from a prompt and optional reference assets.\n */\n create(body: VideoCreateParams, options?: RequestOptions): APIPromise<Video> {\n return this._client.post('/videos', maybeMultipartFormRequestOptions({ body, ...options }, this._client));\n }\n\n /**\n * Fetch the latest metadata for a generated video.\n */\n retrieve(videoID: string, options?: RequestOptions): APIPromise<Video> {\n return this._client.get(path`/videos/${videoID}`, options);\n }\n\n /**\n * List recently generated videos for the current project.\n */\n list(\n query: VideoListParams | null | undefined = {},\n options?: RequestOptions,\n ): PagePromise<VideosPage, Video> {\n return this._client.getAPIList('/videos', ConversationCursorPage<Video>, { query, ...options });\n }\n\n /**\n * Permanently delete a completed or failed video and its stored assets.\n */\n delete(videoID: string, options?: RequestOptions): APIPromise<VideoDeleteResponse> {\n return this._client.delete(path`/videos/${videoID}`, options);\n }\n\n /**\n * Download the generated video bytes or a derived preview asset.\n *\n * Streams the rendered video content for the specified video job.\n */\n downloadContent(\n videoID: string,\n query: VideoDownloadContentParams | null | undefined = {},\n options?: RequestOptions,\n ): APIPromise<Response> {\n return this._client.get(path`/videos/${videoID}/content`, {\n query,\n ...options,\n headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),\n __binaryResponse: true,\n });\n }\n\n /**\n * Create a remix of a completed video using a refreshed prompt.\n */\n remix(videoID: string, body: VideoRemixParams, options?: RequestOptions): APIPromise<Video> {\n return this._client.post(\n path`/videos/${videoID}/remix`,\n maybeMultipartFormRequestOptions({ body, ...options }, this._client),\n );\n }\n}\n\nexport type VideosPage = ConversationCursorPage<Video>;\n\n/**\n * Structured information describing a generated video job.\n */\nexport interface Video {\n /**\n * Unique identifier for the video job.\n */\n id: string;\n\n /**\n * Unix timestamp (seconds) for when the job completed, if finished.\n */\n completed_at: number | null;\n\n /**\n * Unix timestamp (seconds) for when the job was created.\n */\n created_at: number;\n\n /**\n * Error payload that explains why generation failed, if applicable.\n */\n error: VideoCreateError | null;\n\n /**\n * Unix timestamp (seconds) for when the downloadable assets expire, if set.\n */\n expires_at: number | null;\n\n /**\n * The video generation model that produced the job.\n */\n model: VideoModel;\n\n /**\n * The object type, which is always `video`.\n */\n object: 'video';\n\n /**\n * Approximate completion percentage for the generation task.\n */\n progress: number;\n\n /**\n * The prompt that was used to generate the video.\n */\n prompt: string | null;\n\n /**\n * Identifier of the source video if this video is a remix.\n */\n remixed_from_video_id: string | null;\n\n /**\n * Duration of the generated clip in seconds. For extensions, this is the stitched\n * total duration.\n */\n seconds: (string & {}) | VideoSeconds;\n\n /**\n * The resolution of the generated video.\n */\n size: VideoSize;\n\n /**\n * Current lifecycle status of the video job.\n */\n status: 'queued' | 'in_progress' | 'completed' | 'failed';\n}\n\n/**\n * An error that occurred while generating the response.\n */\nexport interface VideoCreateError {\n /**\n * A machine-readable error code that was returned.\n */\n code: string;\n\n /**\n * A human-readable description of the error that was returned.\n */\n message: string;\n}\n\nexport type VideoModel =\n | (string & {})\n | 'sora-2'\n | 'sora-2-pro'\n | 'sora-2-2025-10-06'\n | 'sora-2-pro-2025-10-06'\n | 'sora-2-2025-12-08';\n\nexport type VideoSeconds = '4' | '8' | '12';\n\nexport type VideoSize = '720x1280' | '1280x720' | '1024x1792' | '1792x1024';\n\n/**\n * Confirmation payload returned after deleting a video.\n */\nexport interface VideoDeleteResponse {\n /**\n * Identifier of the deleted video.\n */\n id: string;\n\n /**\n * Indicates that the video resource was deleted.\n */\n deleted: boolean;\n\n /**\n * The object type that signals the deletion response.\n */\n object: 'video.deleted';\n}\n\nexport interface VideoCreateParams {\n /**\n * Text prompt that describes the video to generate.\n */\n prompt: string;\n\n /**\n * Optional multipart reference asset that guides generation.\n */\n input_reference?: Uploadable;\n\n /**\n * The video generation model to use (allowed values: sora-2, sora-2-pro). Defaults\n * to `sora-2`.\n */\n model?: VideoModel;\n\n /**\n * Clip duration in seconds (allowed values: 4, 8, 12). Defaults to 4 seconds.\n */\n seconds?: VideoSeconds;\n\n /**\n * Output resolution formatted as width x height (allowed values: 720x1280,\n * 1280x720, 1024x1792, 1792x1024). Defaults to 720x1280.\n */\n size?: VideoSize;\n}\n\nexport interface VideoListParams extends ConversationCursorPageParams {\n /**\n * Sort order of results by timestamp. Use `asc` for ascending order or `desc` for\n * descending order.\n */\n order?: 'asc' | 'desc';\n}\n\nexport interface VideoDownloadContentParams {\n /**\n * Which downloadable asset to return. Defaults to the MP4 video.\n */\n variant?: 'video' | 'thumbnail' | 'spritesheet';\n}\n\nexport interface VideoRemixParams {\n /**\n * Updated text prompt that directs the remix generation.\n */\n prompt: string;\n}\n\nexport declare namespace Videos {\n export {\n type Video as Video,\n type VideoCreateError as VideoCreateError,\n type VideoModel as VideoModel,\n type VideoSeconds as VideoSeconds,\n type VideoSize as VideoSize,\n type VideoDeleteResponse as VideoDeleteResponse,\n type VideosPage as VideosPage,\n type VideoCreateParams as VideoCreateParams,\n type VideoListParams as VideoListParams,\n type VideoDownloadContentParams as VideoDownloadContentParams,\n type VideoRemixParams as VideoRemixParams,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport { InvalidWebhookSignatureError } from '../../error';\nimport { APIResource } from '../../core/resource';\nimport { buildHeaders, HeadersLike } from '../../internal/headers';\n\nexport class Webhooks extends APIResource {\n /**\n * Validates that the given payload was sent by OpenAI and parses the payload.\n */\n async unwrap(\n payload: string,\n headers: HeadersLike,\n secret: string | undefined | null = this._client.webhookSecret,\n tolerance: number = 300,\n ): Promise<UnwrapWebhookEvent> {\n await this.verifySignature(payload, headers, secret, tolerance);\n\n return JSON.parse(payload) as UnwrapWebhookEvent;\n }\n\n /**\n * Validates whether or not the webhook payload was sent by OpenAI.\n *\n * An error will be raised if the webhook payload was not sent by OpenAI.\n *\n * @param payload - The webhook payload\n * @param headers - The webhook headers\n * @param secret - The webhook secret (optional, will use client secret if not provided)\n * @param tolerance - Maximum age of the webhook in seconds (default: 300 = 5 minutes)\n */\n async verifySignature(\n payload: string,\n headers: HeadersLike,\n secret: string | undefined | null = this._client.webhookSecret,\n tolerance: number = 300,\n ): Promise<void> {\n if (\n typeof crypto === 'undefined' ||\n typeof crypto.subtle.importKey !== 'function' ||\n typeof crypto.subtle.verify !== 'function'\n ) {\n throw new Error('Webhook signature verification is only supported when the `crypto` global is defined');\n }\n\n this.#validateSecret(secret);\n\n const headersObj = buildHeaders([headers]).values;\n const signatureHeader = this.#getRequiredHeader(headersObj, 'webhook-signature');\n const timestamp = this.#getRequiredHeader(headersObj, 'webhook-timestamp');\n const webhookId = this.#getRequiredHeader(headersObj, 'webhook-id');\n\n // Validate timestamp to prevent replay attacks\n const timestampSeconds = parseInt(timestamp, 10);\n if (isNaN(timestampSeconds)) {\n throw new InvalidWebhookSignatureError('Invalid webhook timestamp format');\n }\n\n const nowSeconds = Math.floor(Date.now() / 1000);\n\n if (nowSeconds - timestampSeconds > tolerance) {\n throw new InvalidWebhookSignatureError('Webhook timestamp is too old');\n }\n\n if (timestampSeconds > nowSeconds + tolerance) {\n throw new InvalidWebhookSignatureError('Webhook timestamp is too new');\n }\n\n // Extract signatures from v1,<base64> format\n // The signature header can have multiple values, separated by spaces.\n // Each value is in the format v1,<base64>. We should accept if any match.\n const signatures = signatureHeader\n .split(' ')\n .map((part) => (part.startsWith('v1,') ? part.substring(3) : part));\n\n // Decode the secret if it starts with whsec_\n const decodedSecret =\n secret.startsWith('whsec_') ?\n Buffer.from(secret.replace('whsec_', ''), 'base64')\n : Buffer.from(secret, 'utf-8');\n\n // Create the signed payload: {webhook_id}.{timestamp}.{payload}\n const signedPayload = webhookId ? `${webhookId}.${timestamp}.${payload}` : `${timestamp}.${payload}`;\n\n // Import the secret as a cryptographic key for HMAC\n const key = await crypto.subtle.importKey(\n 'raw',\n decodedSecret,\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['verify'],\n );\n\n // Check if any signature matches using timing-safe WebCrypto verify\n for (const signature of signatures) {\n try {\n const signatureBytes = Buffer.from(signature, 'base64');\n const isValid = await crypto.subtle.verify(\n 'HMAC',\n key,\n signatureBytes,\n new TextEncoder().encode(signedPayload),\n );\n\n if (isValid) {\n return; // Valid signature found\n }\n } catch {\n // Invalid base64 or signature format, continue to next signature\n continue;\n }\n }\n\n throw new InvalidWebhookSignatureError(\n 'The given webhook signature does not match the expected signature',\n );\n }\n\n #validateSecret(secret: string | null | undefined): asserts secret is string {\n if (typeof secret !== 'string' || secret.length === 0) {\n throw new Error(\n `The webhook secret must either be set using the env var, OPENAI_WEBHOOK_SECRET, on the client class, OpenAI({ webhookSecret: '123' }), or passed to this function`,\n );\n }\n }\n\n #getRequiredHeader(headers: Headers, name: string): string {\n if (!headers) {\n throw new Error(`Headers are required`);\n }\n\n const value = headers.get(name);\n\n if (value === null || value === undefined) {\n throw new Error(`Missing required header: ${name}`);\n }\n\n return value;\n }\n}\n\n/**\n * Sent when a batch API request has been cancelled.\n */\nexport interface BatchCancelledWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the batch API request was cancelled.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: BatchCancelledWebhookEvent.Data;\n\n /**\n * The type of the event. Always `batch.cancelled`.\n */\n type: 'batch.cancelled';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace BatchCancelledWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the batch API request.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a batch API request has been completed.\n */\nexport interface BatchCompletedWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the batch API request was completed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: BatchCompletedWebhookEvent.Data;\n\n /**\n * The type of the event. Always `batch.completed`.\n */\n type: 'batch.completed';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace BatchCompletedWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the batch API request.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a batch API request has expired.\n */\nexport interface BatchExpiredWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the batch API request expired.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: BatchExpiredWebhookEvent.Data;\n\n /**\n * The type of the event. Always `batch.expired`.\n */\n type: 'batch.expired';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace BatchExpiredWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the batch API request.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a batch API request has failed.\n */\nexport interface BatchFailedWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the batch API request failed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: BatchFailedWebhookEvent.Data;\n\n /**\n * The type of the event. Always `batch.failed`.\n */\n type: 'batch.failed';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace BatchFailedWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the batch API request.\n */\n id: string;\n }\n}\n\n/**\n * Sent when an eval run has been canceled.\n */\nexport interface EvalRunCanceledWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the eval run was canceled.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: EvalRunCanceledWebhookEvent.Data;\n\n /**\n * The type of the event. Always `eval.run.canceled`.\n */\n type: 'eval.run.canceled';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace EvalRunCanceledWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the eval run.\n */\n id: string;\n }\n}\n\n/**\n * Sent when an eval run has failed.\n */\nexport interface EvalRunFailedWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the eval run failed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: EvalRunFailedWebhookEvent.Data;\n\n /**\n * The type of the event. Always `eval.run.failed`.\n */\n type: 'eval.run.failed';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace EvalRunFailedWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the eval run.\n */\n id: string;\n }\n}\n\n/**\n * Sent when an eval run has succeeded.\n */\nexport interface EvalRunSucceededWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the eval run succeeded.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: EvalRunSucceededWebhookEvent.Data;\n\n /**\n * The type of the event. Always `eval.run.succeeded`.\n */\n type: 'eval.run.succeeded';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace EvalRunSucceededWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the eval run.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a fine-tuning job has been cancelled.\n */\nexport interface FineTuningJobCancelledWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the fine-tuning job was cancelled.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: FineTuningJobCancelledWebhookEvent.Data;\n\n /**\n * The type of the event. Always `fine_tuning.job.cancelled`.\n */\n type: 'fine_tuning.job.cancelled';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace FineTuningJobCancelledWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the fine-tuning job.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a fine-tuning job has failed.\n */\nexport interface FineTuningJobFailedWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the fine-tuning job failed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: FineTuningJobFailedWebhookEvent.Data;\n\n /**\n * The type of the event. Always `fine_tuning.job.failed`.\n */\n type: 'fine_tuning.job.failed';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace FineTuningJobFailedWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the fine-tuning job.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a fine-tuning job has succeeded.\n */\nexport interface FineTuningJobSucceededWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the fine-tuning job succeeded.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: FineTuningJobSucceededWebhookEvent.Data;\n\n /**\n * The type of the event. Always `fine_tuning.job.succeeded`.\n */\n type: 'fine_tuning.job.succeeded';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace FineTuningJobSucceededWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the fine-tuning job.\n */\n id: string;\n }\n}\n\n/**\n * Sent when Realtime API Receives a incoming SIP call.\n */\nexport interface RealtimeCallIncomingWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the model response was completed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: RealtimeCallIncomingWebhookEvent.Data;\n\n /**\n * The type of the event. Always `realtime.call.incoming`.\n */\n type: 'realtime.call.incoming';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace RealtimeCallIncomingWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of this call.\n */\n call_id: string;\n\n /**\n * Headers from the SIP Invite.\n */\n sip_headers: Array<Data.SipHeader>;\n }\n\n export namespace Data {\n /**\n * A header from the SIP Invite.\n */\n export interface SipHeader {\n /**\n * Name of the SIP Header.\n */\n name: string;\n\n /**\n * Value of the SIP Header.\n */\n value: string;\n }\n }\n}\n\n/**\n * Sent when a background response has been cancelled.\n */\nexport interface ResponseCancelledWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the model response was cancelled.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: ResponseCancelledWebhookEvent.Data;\n\n /**\n * The type of the event. Always `response.cancelled`.\n */\n type: 'response.cancelled';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace ResponseCancelledWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the model response.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a background response has been completed.\n */\nexport interface ResponseCompletedWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the model response was completed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: ResponseCompletedWebhookEvent.Data;\n\n /**\n * The type of the event. Always `response.completed`.\n */\n type: 'response.completed';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace ResponseCompletedWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the model response.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a background response has failed.\n */\nexport interface ResponseFailedWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the model response failed.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: ResponseFailedWebhookEvent.Data;\n\n /**\n * The type of the event. Always `response.failed`.\n */\n type: 'response.failed';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace ResponseFailedWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the model response.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a background response has been interrupted.\n */\nexport interface ResponseIncompleteWebhookEvent {\n /**\n * The unique ID of the event.\n */\n id: string;\n\n /**\n * The Unix timestamp (in seconds) of when the model response was interrupted.\n */\n created_at: number;\n\n /**\n * Event data payload.\n */\n data: ResponseIncompleteWebhookEvent.Data;\n\n /**\n * The type of the event. Always `response.incomplete`.\n */\n type: 'response.incomplete';\n\n /**\n * The object of the event. Always `event`.\n */\n object?: 'event';\n}\n\nexport namespace ResponseIncompleteWebhookEvent {\n /**\n * Event data payload.\n */\n export interface Data {\n /**\n * The unique ID of the model response.\n */\n id: string;\n }\n}\n\n/**\n * Sent when a batch API request has been cancelled.\n */\nexport type UnwrapWebhookEvent =\n | BatchCancelledWebhookEvent\n | BatchCompletedWebhookEvent\n | BatchExpiredWebhookEvent\n | BatchFailedWebhookEvent\n | EvalRunCanceledWebhookEvent\n | EvalRunFailedWebhookEvent\n | EvalRunSucceededWebhookEvent\n | FineTuningJobCancelledWebhookEvent\n | FineTuningJobFailedWebhookEvent\n | FineTuningJobSucceededWebhookEvent\n | RealtimeCallIncomingWebhookEvent\n | ResponseCancelledWebhookEvent\n | ResponseCompletedWebhookEvent\n | ResponseFailedWebhookEvent\n | ResponseIncompleteWebhookEvent;\n\nexport declare namespace Webhooks {\n export {\n type BatchCancelledWebhookEvent as BatchCancelledWebhookEvent,\n type BatchCompletedWebhookEvent as BatchCompletedWebhookEvent,\n type BatchExpiredWebhookEvent as BatchExpiredWebhookEvent,\n type BatchFailedWebhookEvent as BatchFailedWebhookEvent,\n type EvalRunCanceledWebhookEvent as EvalRunCanceledWebhookEvent,\n type EvalRunFailedWebhookEvent as EvalRunFailedWebhookEvent,\n type EvalRunSucceededWebhookEvent as EvalRunSucceededWebhookEvent,\n type FineTuningJobCancelledWebhookEvent as FineTuningJobCancelledWebhookEvent,\n type FineTuningJobFailedWebhookEvent as FineTuningJobFailedWebhookEvent,\n type FineTuningJobSucceededWebhookEvent as FineTuningJobSucceededWebhookEvent,\n type RealtimeCallIncomingWebhookEvent as RealtimeCallIncomingWebhookEvent,\n type ResponseCancelledWebhookEvent as ResponseCancelledWebhookEvent,\n type ResponseCompletedWebhookEvent as ResponseCompletedWebhookEvent,\n type ResponseFailedWebhookEvent as ResponseFailedWebhookEvent,\n type ResponseIncompleteWebhookEvent as ResponseIncompleteWebhookEvent,\n type UnwrapWebhookEvent as UnwrapWebhookEvent,\n };\n}\n","// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.\n\nimport type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';\nimport type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';\nimport { uuid4 } from './internal/utils/uuid';\nimport { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';\nimport { sleep } from './internal/utils/sleep';\nexport type { Logger, LogLevel } from './internal/utils/log';\nimport { castToError, isAbortError } from './internal/errors';\nimport type { APIResponseProps } from './internal/parse';\nimport { getPlatformHeaders } from './internal/detect-platform';\nimport * as Shims from './internal/shims';\nimport * as Opts from './internal/request-options';\nimport { stringifyQuery } from './internal/utils/query';\nimport { VERSION } from './version';\nimport * as Errors from './core/error';\nimport * as Pagination from './core/pagination';\nimport {\n AbstractPage,\n type ConversationCursorPageParams,\n ConversationCursorPageResponse,\n type CursorPageParams,\n CursorPageResponse,\n PageResponse,\n} from './core/pagination';\nimport * as Uploads from './core/uploads';\nimport * as API from './resources/index';\nimport { APIPromise } from './core/api-promise';\nimport {\n Batch,\n BatchCreateParams,\n BatchError,\n BatchListParams,\n BatchRequestCounts,\n BatchUsage,\n Batches,\n BatchesPage,\n} from './resources/batches';\nimport {\n Completion,\n CompletionChoice,\n CompletionCreateParams,\n CompletionCreateParamsNonStreaming,\n CompletionCreateParamsStreaming,\n CompletionUsage,\n Completions,\n} from './resources/completions';\nimport {\n CreateEmbeddingResponse,\n Embedding,\n EmbeddingCreateParams,\n EmbeddingModel,\n Embeddings,\n} from './resources/embeddings';\nimport {\n FileContent,\n FileCreateParams,\n FileDeleted,\n FileListParams,\n FileObject,\n FileObjectsPage,\n FilePurpose,\n Files,\n} from './resources/files';\nimport {\n Image,\n ImageCreateVariationParams,\n ImageEditCompletedEvent,\n ImageEditParams,\n ImageEditParamsNonStreaming,\n ImageEditParamsStreaming,\n ImageEditPartialImageEvent,\n ImageEditStreamEvent,\n ImageGenCompletedEvent,\n ImageGenPartialImageEvent,\n ImageGenStreamEvent,\n ImageGenerateParams,\n ImageGenerateParamsNonStreaming,\n ImageGenerateParamsStreaming,\n ImageModel,\n Images,\n ImagesResponse,\n} from './resources/images';\nimport { Model, ModelDeleted, Models, ModelsPage } from './resources/models';\nimport {\n Moderation,\n ModerationCreateParams,\n ModerationCreateResponse,\n ModerationImageURLInput,\n ModerationModel,\n ModerationMultiModalInput,\n ModerationTextInput,\n Moderations,\n} from './resources/moderations';\nimport {\n Video,\n VideoCreateError,\n VideoCreateParams,\n VideoDeleteResponse,\n VideoDownloadContentParams,\n VideoListParams,\n VideoModel,\n VideoRemixParams,\n VideoSeconds,\n VideoSize,\n Videos,\n VideosPage,\n} from './resources/videos';\nimport { Audio, AudioModel, AudioResponseFormat } from './resources/audio/audio';\nimport { Beta } from './resources/beta/beta';\nimport { Chat } from './resources/chat/chat';\nimport {\n ContainerCreateParams,\n ContainerCreateResponse,\n ContainerListParams,\n ContainerListResponse,\n ContainerListResponsesPage,\n ContainerRetrieveResponse,\n Containers,\n} from './resources/containers/containers';\nimport { Conversations } from './resources/conversations/conversations';\nimport {\n EvalCreateParams,\n EvalCreateResponse,\n EvalCustomDataSourceConfig,\n EvalDeleteResponse,\n EvalListParams,\n EvalListResponse,\n EvalListResponsesPage,\n EvalRetrieveResponse,\n EvalStoredCompletionsDataSourceConfig,\n EvalUpdateParams,\n EvalUpdateResponse,\n Evals,\n} from './resources/evals/evals';\nimport { FineTuning } from './resources/fine-tuning/fine-tuning';\nimport { Graders } from './resources/graders/graders';\nimport { Realtime } from './resources/realtime/realtime';\nimport { Responses } from './resources/responses/responses';\nimport {\n DeletedSkill,\n Skill,\n SkillCreateParams,\n SkillList,\n SkillListParams,\n SkillUpdateParams,\n Skills,\n SkillsPage,\n} from './resources/skills/skills';\nimport {\n Upload,\n UploadCompleteParams,\n UploadCreateParams,\n Uploads as UploadsAPIUploads,\n} from './resources/uploads/uploads';\nimport {\n AutoFileChunkingStrategyParam,\n FileChunkingStrategy,\n FileChunkingStrategyParam,\n OtherFileChunkingStrategyObject,\n StaticFileChunkingStrategy,\n StaticFileChunkingStrategyObject,\n StaticFileChunkingStrategyObjectParam,\n VectorStore,\n VectorStoreCreateParams,\n VectorStoreDeleted,\n VectorStoreListParams,\n VectorStoreSearchParams,\n VectorStoreSearchResponse,\n VectorStoreSearchResponsesPage,\n VectorStoreUpdateParams,\n VectorStores,\n VectorStoresPage,\n} from './resources/vector-stores/vector-stores';\nimport { Webhooks } from './resources/webhooks/webhooks';\nimport {\n ChatCompletion,\n ChatCompletionAllowedToolChoice,\n ChatCompletionAllowedTools,\n ChatCompletionAssistantMessageParam,\n ChatCompletionAudio,\n ChatCompletionAudioParam,\n ChatCompletionChunk,\n ChatCompletionContentPart,\n ChatCompletionContentPartImage,\n ChatCompletionContentPartInputAudio,\n ChatCompletionContentPartRefusal,\n ChatCompletionContentPartText,\n ChatCompletionCreateParams,\n ChatCompletionCreateParamsNonStreaming,\n ChatCompletionCreateParamsStreaming,\n ChatCompletionCustomTool,\n ChatCompletionDeleted,\n ChatCompletionDeveloperMessageParam,\n ChatCompletionFunctionCallOption,\n ChatCompletionFunctionMessageParam,\n ChatCompletionFunctionTool,\n ChatCompletionListParams,\n ChatCompletionMessage,\n ChatCompletionMessageCustomToolCall,\n ChatCompletionMessageFunctionToolCall,\n ChatCompletionMessageParam,\n ChatCompletionMessageToolCall,\n ChatCompletionModality,\n ChatCompletionNamedToolChoice,\n ChatCompletionNamedToolChoiceCustom,\n ChatCompletionPredictionContent,\n ChatCompletionReasoningEffort,\n ChatCompletionRole,\n ChatCompletionStoreMessage,\n ChatCompletionStreamOptions,\n ChatCompletionSystemMessageParam,\n ChatCompletionTokenLogprob,\n ChatCompletionTool,\n ChatCompletionToolChoiceOption,\n ChatCompletionToolMessageParam,\n ChatCompletionUpdateParams,\n ChatCompletionUserMessageParam,\n ChatCompletionsPage,\n} from './resources/chat/completions/completions';\nimport { type Fetch } from './internal/builtin-types';\nimport { isRunningInBrowser } from './internal/detect-platform';\nimport { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';\nimport { FinalRequestOptions, RequestOptions } from './internal/request-options';\nimport { readEnv } from './internal/utils/env';\nimport {\n type LogLevel,\n type Logger,\n formatRequestDetails,\n loggerFor,\n parseLogLevel,\n} from './internal/utils/log';\nimport { isEmptyObj } from './internal/utils/values';\n\nexport type ApiKeySetter = () => Promise<string>;\n\nexport interface ClientOptions {\n /**\n * API key used for authentication.\n *\n * - Accepts either a static string or an async function that resolves to a string.\n * - Defaults to process.env['OPENAI_API_KEY'].\n * - When a function is provided, it is invoked before each request so you can rotate\n * or refresh credentials at runtime.\n * - The function must return a non-empty string; otherwise an OpenAIError is thrown.\n * - If the function throws, the error is wrapped in an OpenAIError with the original\n * error available as `cause`.\n */\n apiKey?: string | ApiKeySetter | undefined;\n /**\n * Defaults to process.env['OPENAI_ORG_ID'].\n */\n organization?: string | null | undefined;\n\n /**\n * Defaults to process.env['OPENAI_PROJECT_ID'].\n */\n project?: string | null | undefined;\n\n /**\n * Defaults to process.env['OPENAI_WEBHOOK_SECRET'].\n */\n webhookSecret?: string | null | undefined;\n\n /**\n * Override the default base URL for the API, e.g., \"https://api.example.com/v2/\"\n *\n * Defaults to process.env['OPENAI_BASE_URL'].\n */\n baseURL?: string | null | undefined;\n\n /**\n * The maximum amount of time (in milliseconds) that the client should wait for a response\n * from the server before timing out a single request.\n *\n * Note that request timeouts are retried by default, so in a worst-case scenario you may wait\n * much longer than this timeout before the promise succeeds or fails.\n *\n * @unit milliseconds\n */\n timeout?: number | undefined;\n /**\n * Additional `RequestInit` options to be passed to `fetch` calls.\n * Properties will be overridden by per-request `fetchOptions`.\n */\n fetchOptions?: MergedRequestInit | undefined;\n\n /**\n * Specify a custom `fetch` function implementation.\n *\n * If not provided, we expect that `fetch` is defined globally.\n */\n fetch?: Fetch | undefined;\n\n /**\n * The maximum number of times that the client will retry a request in case of a\n * temporary failure, like a network error or a 5XX error from the server.\n *\n * @default 2\n */\n maxRetries?: number | undefined;\n\n /**\n * Default headers to include with every request to the API.\n *\n * These can be removed in individual requests by explicitly setting the\n * header to `null` in request options.\n */\n defaultHeaders?: HeadersLike | undefined;\n\n /**\n * Default query parameters to include with every request to the API.\n *\n * These can be removed in individual requests by explicitly setting the\n * param to `undefined` in request options.\n */\n defaultQuery?: Record<string, string | undefined> | undefined;\n\n /**\n * By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.\n * Only set this option to `true` if you understand the risks and have appropriate mitigations in place.\n */\n dangerouslyAllowBrowser?: boolean | undefined;\n\n /**\n * Set the log level.\n *\n * Defaults to process.env['OPENAI_LOG'] or 'warn' if it isn't set.\n */\n logLevel?: LogLevel | undefined;\n\n /**\n * Set the logger.\n *\n * Defaults to globalThis.console.\n */\n logger?: Logger | undefined;\n}\n\n/**\n * API Client for interfacing with the OpenAI API.\n */\nexport class OpenAI {\n apiKey: string;\n organization: string | null;\n project: string | null;\n webhookSecret: string | null;\n\n baseURL: string;\n maxRetries: number;\n timeout: number;\n logger: Logger;\n logLevel: LogLevel | undefined;\n fetchOptions: MergedRequestInit | undefined;\n\n private fetch: Fetch;\n #encoder: Opts.RequestEncoder;\n protected idempotencyHeader?: string;\n protected _options: ClientOptions;\n\n /**\n * API Client for interfacing with the OpenAI API.\n *\n * @param {string | undefined} [opts.apiKey=process.env['OPENAI_API_KEY'] ?? undefined]\n * @param {string | null | undefined} [opts.organization=process.env['OPENAI_ORG_ID'] ?? null]\n * @param {string | null | undefined} [opts.project=process.env['OPENAI_PROJECT_ID'] ?? null]\n * @param {string | null | undefined} [opts.webhookSecret=process.env['OPENAI_WEBHOOK_SECRET'] ?? null]\n * @param {string} [opts.baseURL=process.env['OPENAI_BASE_URL'] ?? https://api.openai.com/v1] - Override the default base URL for the API.\n * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.\n * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.\n * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.\n * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.\n * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.\n * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.\n * @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.\n */\n constructor({\n baseURL = readEnv('OPENAI_BASE_URL'),\n apiKey = readEnv('OPENAI_API_KEY'),\n organization = readEnv('OPENAI_ORG_ID') ?? null,\n project = readEnv('OPENAI_PROJECT_ID') ?? null,\n webhookSecret = readEnv('OPENAI_WEBHOOK_SECRET') ?? null,\n ...opts\n }: ClientOptions = {}) {\n if (apiKey === undefined) {\n throw new Errors.OpenAIError(\n 'Missing credentials. Please pass an `apiKey`, or set the `OPENAI_API_KEY` environment variable.',\n );\n }\n\n const options: ClientOptions = {\n apiKey,\n organization,\n project,\n webhookSecret,\n ...opts,\n baseURL: baseURL || `https://api.openai.com/v1`,\n };\n\n if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {\n throw new Errors.OpenAIError(\n \"It looks like you're running in a browser-like environment.\\n\\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\\nIf you understand the risks and have appropriate mitigations in place,\\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\\n\\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\\n\\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\\n\",\n );\n }\n\n this.baseURL = options.baseURL!;\n this.timeout = options.timeout ?? OpenAI.DEFAULT_TIMEOUT /* 10 minutes */;\n this.logger = options.logger ?? console;\n const defaultLogLevel = 'warn';\n // Set default logLevel early so that we can log a warning in parseLogLevel.\n this.logLevel = defaultLogLevel;\n this.logLevel =\n parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??\n parseLogLevel(readEnv('OPENAI_LOG'), \"process.env['OPENAI_LOG']\", this) ??\n defaultLogLevel;\n this.fetchOptions = options.fetchOptions;\n this.maxRetries = options.maxRetries ?? 2;\n this.fetch = options.fetch ?? Shims.getDefaultFetch();\n this.#encoder = Opts.FallbackEncoder;\n\n this._options = options;\n\n this.apiKey = typeof apiKey === 'string' ? apiKey : 'Missing Key';\n this.organization = organization;\n this.project = project;\n this.webhookSecret = webhookSecret;\n }\n\n /**\n * Create a new client instance re-using the same options given to the current client with optional overriding.\n */\n withOptions(options: Partial<ClientOptions>): this {\n const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({\n ...this._options,\n baseURL: this.baseURL,\n maxRetries: this.maxRetries,\n timeout: this.timeout,\n logger: this.logger,\n logLevel: this.logLevel,\n fetch: this.fetch,\n fetchOptions: this.fetchOptions,\n apiKey: this.apiKey,\n organization: this.organization,\n project: this.project,\n webhookSecret: this.webhookSecret,\n ...options,\n });\n return client;\n }\n\n /**\n * Check whether the base URL is set to its default.\n */\n #baseURLOverridden(): boolean {\n return this.baseURL !== 'https://api.openai.com/v1';\n }\n\n protected defaultQuery(): Record<string, string | undefined> | undefined {\n return this._options.defaultQuery;\n }\n\n protected validateHeaders({ values, nulls }: NullableHeaders) {\n return;\n }\n\n protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {\n return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);\n }\n\n protected stringifyQuery(query: object | Record<string, unknown>): string {\n return stringifyQuery(query);\n }\n\n private getUserAgent(): string {\n return `${this.constructor.name}/JS ${VERSION}`;\n }\n\n protected defaultIdempotencyKey(): string {\n return `stainless-node-retry-${uuid4()}`;\n }\n\n protected makeStatusError(\n status: number,\n error: Object,\n message: string | undefined,\n headers: Headers,\n ): Errors.APIError {\n return Errors.APIError.generate(status, error, message, headers);\n }\n\n async _callApiKey(): Promise<boolean> {\n const apiKey = this._options.apiKey;\n if (typeof apiKey !== 'function') return false;\n\n let token: unknown;\n try {\n token = await apiKey();\n } catch (err: any) {\n if (err instanceof Errors.OpenAIError) throw err;\n throw new Errors.OpenAIError(\n `Failed to get token from 'apiKey' function: ${err.message}`,\n // @ts-ignore\n { cause: err },\n );\n }\n\n if (typeof token !== 'string' || !token) {\n throw new Errors.OpenAIError(\n `Expected 'apiKey' function argument to return a string but it returned ${token}`,\n );\n }\n this.apiKey = token;\n return true;\n }\n\n buildURL(\n path: string,\n query: Record<string, unknown> | null | undefined,\n defaultBaseURL?: string | undefined,\n ): string {\n const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;\n const url =\n isAbsoluteURL(path) ?\n new URL(path)\n : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));\n\n const defaultQuery = this.defaultQuery();\n if (!isEmptyObj(defaultQuery)) {\n query = { ...defaultQuery, ...query };\n }\n\n if (typeof query === 'object' && query && !Array.isArray(query)) {\n url.search = this.stringifyQuery(query);\n }\n\n return url.toString();\n }\n\n /**\n * Used as a callback for mutating the given `FinalRequestOptions` object.\n */\n protected async prepareOptions(options: FinalRequestOptions): Promise<void> {\n await this._callApiKey();\n }\n\n /**\n * Used as a callback for mutating the given `RequestInit` object.\n *\n * This is useful for cases where you want to add certain headers based off of\n * the request properties, e.g. `method` or `url`.\n */\n protected async prepareRequest(\n request: RequestInit,\n { url, options }: { url: string; options: FinalRequestOptions },\n ): Promise<void> {}\n\n get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n return this.methodRequest('get', path, opts);\n }\n\n post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n return this.methodRequest('post', path, opts);\n }\n\n patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n return this.methodRequest('patch', path, opts);\n }\n\n put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n return this.methodRequest('put', path, opts);\n }\n\n delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {\n return this.methodRequest('delete', path, opts);\n }\n\n private methodRequest<Rsp>(\n method: HTTPMethod,\n path: string,\n opts?: PromiseOrValue<RequestOptions>,\n ): APIPromise<Rsp> {\n return this.request(\n Promise.resolve(opts).then((opts) => {\n return { method, path, ...opts };\n }),\n );\n }\n\n request<Rsp>(\n options: PromiseOrValue<FinalRequestOptions>,\n remainingRetries: number | null = null,\n ): APIPromise<Rsp> {\n return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));\n }\n\n private async makeRequest(\n optionsInput: PromiseOrValue<FinalRequestOptions>,\n retriesRemaining: number | null,\n retryOfRequestLogID: string | undefined,\n ): Promise<APIResponseProps> {\n const options = await optionsInput;\n const maxRetries = options.maxRetries ?? this.maxRetries;\n if (retriesRemaining == null) {\n retriesRemaining = maxRetries;\n }\n\n await this.prepareOptions(options);\n\n const { req, url, timeout } = await this.buildRequest(options, {\n retryCount: maxRetries - retriesRemaining,\n });\n\n await this.prepareRequest(req, { url, options });\n\n /** Not an API request ID, just for correlating local log entries. */\n const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');\n const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;\n const startTime = Date.now();\n\n loggerFor(this).debug(\n `[${requestLogID}] sending request`,\n formatRequestDetails({\n retryOfRequestLogID,\n method: options.method,\n url,\n options,\n headers: req.headers,\n }),\n );\n\n if (options.signal?.aborted) {\n throw new Errors.APIUserAbortError();\n }\n\n const controller = new AbortController();\n const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);\n const headersTime = Date.now();\n\n if (response instanceof globalThis.Error) {\n const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;\n if (options.signal?.aborted) {\n throw new Errors.APIUserAbortError();\n }\n // detect native connection timeout errors\n // deno throws \"TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)\"\n // undici throws \"TypeError: fetch failed\" with cause \"ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)\"\n // others do not provide enough information to distinguish timeouts from other connection errors\n const isTimeout =\n isAbortError(response) ||\n /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));\n if (retriesRemaining) {\n loggerFor(this).info(\n `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,\n );\n loggerFor(this).debug(\n `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,\n formatRequestDetails({\n retryOfRequestLogID,\n url,\n durationMs: headersTime - startTime,\n message: response.message,\n }),\n );\n return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);\n }\n loggerFor(this).info(\n `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,\n );\n loggerFor(this).debug(\n `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,\n formatRequestDetails({\n retryOfRequestLogID,\n url,\n durationMs: headersTime - startTime,\n message: response.message,\n }),\n );\n if (isTimeout) {\n throw new Errors.APIConnectionTimeoutError();\n }\n throw new Errors.APIConnectionError({ cause: response });\n }\n\n const specialHeaders = [...response.headers.entries()]\n .filter(([name]) => name === 'x-request-id')\n .map(([name, value]) => ', ' + name + ': ' + JSON.stringify(value))\n .join('');\n const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${\n response.ok ? 'succeeded' : 'failed'\n } with status ${response.status} in ${headersTime - startTime}ms`;\n\n if (!response.ok) {\n const shouldRetry = await this.shouldRetry(response);\n if (retriesRemaining && shouldRetry) {\n const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;\n\n // We don't need the body of this response.\n await Shims.CancelReadableStream(response.body);\n loggerFor(this).info(`${responseInfo} - ${retryMessage}`);\n loggerFor(this).debug(\n `[${requestLogID}] response error (${retryMessage})`,\n formatRequestDetails({\n retryOfRequestLogID,\n url: response.url,\n status: response.status,\n headers: response.headers,\n durationMs: headersTime - startTime,\n }),\n );\n return this.retryRequest(\n options,\n retriesRemaining,\n retryOfRequestLogID ?? requestLogID,\n response.headers,\n );\n }\n\n const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;\n\n loggerFor(this).info(`${responseInfo} - ${retryMessage}`);\n\n const errText = await response.text().catch((err: any) => castToError(err).message);\n const errJSON = safeJSON(errText) as any;\n const errMessage = errJSON ? undefined : errText;\n\n loggerFor(this).debug(\n `[${requestLogID}] response error (${retryMessage})`,\n formatRequestDetails({\n retryOfRequestLogID,\n url: response.url,\n status: response.status,\n headers: response.headers,\n message: errMessage,\n durationMs: Date.now() - startTime,\n }),\n );\n\n const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);\n throw err;\n }\n\n loggerFor(this).info(responseInfo);\n loggerFor(this).debug(\n `[${requestLogID}] response start`,\n formatRequestDetails({\n retryOfRequestLogID,\n url: response.url,\n status: response.status,\n headers: response.headers,\n durationMs: headersTime - startTime,\n }),\n );\n\n return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };\n }\n\n getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(\n path: string,\n Page: new (...args: any[]) => PageClass,\n opts?: PromiseOrValue<RequestOptions>,\n ): Pagination.PagePromise<PageClass, Item> {\n return this.requestAPIList(\n Page,\n opts && 'then' in opts ?\n opts.then((opts) => ({ method: 'get', path, ...opts }))\n : { method: 'get', path, ...opts },\n );\n }\n\n requestAPIList<\n Item = unknown,\n PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,\n >(\n Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,\n options: PromiseOrValue<FinalRequestOptions>,\n ): Pagination.PagePromise<PageClass, Item> {\n const request = this.makeRequest(options, null, undefined);\n return new Pagination.PagePromise<PageClass, Item>(this as any as OpenAI, request, Page);\n }\n\n async fetchWithTimeout(\n url: RequestInfo,\n init: RequestInit | undefined,\n ms: number,\n controller: AbortController,\n ): Promise<Response> {\n const { signal, method, ...options } = init || {};\n const abort = this._makeAbort(controller);\n if (signal) signal.addEventListener('abort', abort, { once: true });\n\n const timeout = setTimeout(abort, ms);\n\n const isReadableBody =\n ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||\n (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);\n\n const fetchOptions: RequestInit = {\n signal: controller.signal as any,\n ...(isReadableBody ? { duplex: 'half' } : {}),\n method: 'GET',\n ...options,\n };\n if (method) {\n // Custom methods like 'patch' need to be uppercased\n // See https://github.com/nodejs/undici/issues/2294\n fetchOptions.method = method.toUpperCase();\n }\n\n try {\n // use undefined this binding; fetch errors if bound to something else in browser/cloudflare\n return await this.fetch.call(undefined, url, fetchOptions);\n } finally {\n clearTimeout(timeout);\n }\n }\n\n private async shouldRetry(response: Response): Promise<boolean> {\n // Note this is not a standard header.\n const shouldRetryHeader = response.headers.get('x-should-retry');\n\n // If the server explicitly says whether or not to retry, obey.\n if (shouldRetryHeader === 'true') return true;\n if (shouldRetryHeader === 'false') return false;\n\n // Retry on request timeouts.\n if (response.status === 408) return true;\n\n // Retry on lock timeouts.\n if (response.status === 409) return true;\n\n // Retry on rate limits.\n if (response.status === 429) return true;\n\n // Retry internal errors.\n if (response.status >= 500) return true;\n\n return false;\n }\n\n private async retryRequest(\n options: FinalRequestOptions,\n retriesRemaining: number,\n requestLogID: string,\n responseHeaders?: Headers | undefined,\n ): Promise<APIResponseProps> {\n let timeoutMillis: number | undefined;\n\n // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.\n const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');\n if (retryAfterMillisHeader) {\n const timeoutMs = parseFloat(retryAfterMillisHeader);\n if (!Number.isNaN(timeoutMs)) {\n timeoutMillis = timeoutMs;\n }\n }\n\n // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After\n const retryAfterHeader = responseHeaders?.get('retry-after');\n if (retryAfterHeader && !timeoutMillis) {\n const timeoutSeconds = parseFloat(retryAfterHeader);\n if (!Number.isNaN(timeoutSeconds)) {\n timeoutMillis = timeoutSeconds * 1000;\n } else {\n timeoutMillis = Date.parse(retryAfterHeader) - Date.now();\n }\n }\n\n // If the API asks us to wait a certain amount of time, just do what it\n // says, but otherwise calculate a default\n if (timeoutMillis === undefined) {\n const maxRetries = options.maxRetries ?? this.maxRetries;\n timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);\n }\n await sleep(timeoutMillis);\n\n return this.makeRequest(options, retriesRemaining - 1, requestLogID);\n }\n\n private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {\n const initialRetryDelay = 0.5;\n const maxRetryDelay = 8.0;\n\n const numRetries = maxRetries - retriesRemaining;\n\n // Apply exponential backoff, but not more than the max.\n const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);\n\n // Apply some jitter, take up to at most 25 percent of the retry time.\n const jitter = 1 - Math.random() * 0.25;\n\n return sleepSeconds * jitter * 1000;\n }\n\n async buildRequest(\n inputOptions: FinalRequestOptions,\n { retryCount = 0 }: { retryCount?: number } = {},\n ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {\n const options = { ...inputOptions };\n const { method, path, query, defaultBaseURL } = options;\n\n const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);\n if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);\n options.timeout = options.timeout ?? this.timeout;\n const { bodyHeaders, body } = this.buildBody({ options });\n const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });\n\n const req: FinalizedRequestInit = {\n method,\n headers: reqHeaders,\n ...(options.signal && { signal: options.signal }),\n ...((globalThis as any).ReadableStream &&\n body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),\n ...(body && { body }),\n ...((this.fetchOptions as any) ?? {}),\n ...((options.fetchOptions as any) ?? {}),\n };\n\n return { req, url, timeout: options.timeout };\n }\n\n private async buildHeaders({\n options,\n method,\n bodyHeaders,\n retryCount,\n }: {\n options: FinalRequestOptions;\n method: HTTPMethod;\n bodyHeaders: HeadersLike;\n retryCount: number;\n }): Promise<Headers> {\n let idempotencyHeaders: HeadersLike = {};\n if (this.idempotencyHeader && method !== 'get') {\n if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();\n idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;\n }\n\n const headers = buildHeaders([\n idempotencyHeaders,\n {\n Accept: 'application/json',\n 'User-Agent': this.getUserAgent(),\n 'X-Stainless-Retry-Count': String(retryCount),\n ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),\n ...getPlatformHeaders(),\n 'OpenAI-Organization': this.organization,\n 'OpenAI-Project': this.project,\n },\n await this.authHeaders(options),\n this._options.defaultHeaders,\n bodyHeaders,\n options.headers,\n ]);\n\n this.validateHeaders(headers);\n\n return headers.values;\n }\n\n private _makeAbort(controller: AbortController) {\n // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure\n // would capture all request options, and cause a memory leak.\n return () => controller.abort();\n }\n\n private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {\n bodyHeaders: HeadersLike;\n body: BodyInit | undefined;\n } {\n if (!body) {\n return { bodyHeaders: undefined, body: undefined };\n }\n const headers = buildHeaders([rawHeaders]);\n if (\n // Pass raw type verbatim\n ArrayBuffer.isView(body) ||\n body instanceof ArrayBuffer ||\n body instanceof DataView ||\n (typeof body === 'string' &&\n // Preserve legacy string encoding behavior for now\n headers.values.has('content-type')) ||\n // `Blob` is superset of `File`\n ((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||\n // `FormData` -> `multipart/form-data`\n body instanceof FormData ||\n // `URLSearchParams` -> `application/x-www-form-urlencoded`\n body instanceof URLSearchParams ||\n // Send chunked stream (each chunk has own `length`)\n ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)\n ) {\n return { bodyHeaders: undefined, body: body as BodyInit };\n } else if (\n typeof body === 'object' &&\n (Symbol.asyncIterator in body ||\n (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))\n ) {\n return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };\n } else if (\n typeof body === 'object' &&\n headers.values.get('content-type') === 'application/x-www-form-urlencoded'\n ) {\n return {\n bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },\n body: this.stringifyQuery(body),\n };\n } else {\n return this.#encoder({ body, headers });\n }\n }\n\n static OpenAI = this;\n static DEFAULT_TIMEOUT = 600000; // 10 minutes\n\n static OpenAIError = Errors.OpenAIError;\n static APIError = Errors.APIError;\n static APIConnectionError = Errors.APIConnectionError;\n static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;\n static APIUserAbortError = Errors.APIUserAbortError;\n static NotFoundError = Errors.NotFoundError;\n static ConflictError = Errors.ConflictError;\n static RateLimitError = Errors.RateLimitError;\n static BadRequestError = Errors.BadRequestError;\n static AuthenticationError = Errors.AuthenticationError;\n static InternalServerError = Errors.InternalServerError;\n static PermissionDeniedError = Errors.PermissionDeniedError;\n static UnprocessableEntityError = Errors.UnprocessableEntityError;\n static InvalidWebhookSignatureError = Errors.InvalidWebhookSignatureError;\n\n static toFile = Uploads.toFile;\n\n /**\n * Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.\n */\n completions: API.Completions = new API.Completions(this);\n chat: API.Chat = new API.Chat(this);\n /**\n * Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.\n */\n embeddings: API.Embeddings = new API.Embeddings(this);\n /**\n * Files are used to upload documents that can be used with features like Assistants and Fine-tuning.\n */\n files: API.Files = new API.Files(this);\n /**\n * Given a prompt and/or an input image, the model will generate a new image.\n */\n images: API.Images = new API.Images(this);\n audio: API.Audio = new API.Audio(this);\n /**\n * Given text and/or image inputs, classifies if those inputs are potentially harmful.\n */\n moderations: API.Moderations = new API.Moderations(this);\n /**\n * List and describe the various models available in the API.\n */\n models: API.Models = new API.Models(this);\n fineTuning: API.FineTuning = new API.FineTuning(this);\n graders: API.Graders = new API.Graders(this);\n vectorStores: API.VectorStores = new API.VectorStores(this);\n webhooks: API.Webhooks = new API.Webhooks(this);\n beta: API.Beta = new API.Beta(this);\n /**\n * Create large batches of API requests to run asynchronously.\n */\n batches: API.Batches = new API.Batches(this);\n /**\n * Use Uploads to upload large files in multiple parts.\n */\n uploads: API.Uploads = new API.Uploads(this);\n responses: API.Responses = new API.Responses(this);\n realtime: API.Realtime = new API.Realtime(this);\n /**\n * Manage conversations and conversation items.\n */\n conversations: API.Conversations = new API.Conversations(this);\n /**\n * Manage and run evals in the OpenAI platform.\n */\n evals: API.Evals = new API.Evals(this);\n containers: API.Containers = new API.Containers(this);\n skills: API.Skills = new API.Skills(this);\n videos: API.Videos = new API.Videos(this);\n}\n\nOpenAI.Completions = Completions;\nOpenAI.Chat = Chat;\nOpenAI.Embeddings = Embeddings;\nOpenAI.Files = Files;\nOpenAI.Images = Images;\nOpenAI.Audio = Audio;\nOpenAI.Moderations = Moderations;\nOpenAI.Models = Models;\nOpenAI.FineTuning = FineTuning;\nOpenAI.Graders = Graders;\nOpenAI.VectorStores = VectorStores;\nOpenAI.Webhooks = Webhooks;\nOpenAI.Beta = Beta;\nOpenAI.Batches = Batches;\nOpenAI.Uploads = UploadsAPIUploads;\nOpenAI.Responses = Responses;\nOpenAI.Realtime = Realtime;\nOpenAI.Conversations = Conversations;\nOpenAI.Evals = Evals;\nOpenAI.Containers = Containers;\nOpenAI.Skills = Skills;\nOpenAI.Videos = Videos;\n\nexport declare namespace OpenAI {\n export type RequestOptions = Opts.RequestOptions;\n\n export import Page = Pagination.Page;\n export { type PageResponse as PageResponse };\n\n export import CursorPage = Pagination.CursorPage;\n export { type CursorPageParams as CursorPageParams, type CursorPageResponse as CursorPageResponse };\n\n export import ConversationCursorPage = Pagination.ConversationCursorPage;\n export {\n type ConversationCursorPageParams as ConversationCursorPageParams,\n type ConversationCursorPageResponse as ConversationCursorPageResponse,\n };\n\n export {\n Completions as Completions,\n type Completion as Completion,\n type CompletionChoice as CompletionChoice,\n type CompletionUsage as CompletionUsage,\n type CompletionCreateParams as CompletionCreateParams,\n type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,\n type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,\n };\n\n export {\n Chat as Chat,\n type ChatCompletion as ChatCompletion,\n type ChatCompletionAllowedToolChoice as ChatCompletionAllowedToolChoice,\n type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,\n type ChatCompletionAudio as ChatCompletionAudio,\n type ChatCompletionAudioParam as ChatCompletionAudioParam,\n type ChatCompletionChunk as ChatCompletionChunk,\n type ChatCompletionContentPart as ChatCompletionContentPart,\n type ChatCompletionContentPartImage as ChatCompletionContentPartImage,\n type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,\n type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,\n type ChatCompletionContentPartText as ChatCompletionContentPartText,\n type ChatCompletionCustomTool as ChatCompletionCustomTool,\n type ChatCompletionDeleted as ChatCompletionDeleted,\n type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,\n type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,\n type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,\n type ChatCompletionFunctionTool as ChatCompletionFunctionTool,\n type ChatCompletionMessage as ChatCompletionMessage,\n type ChatCompletionMessageCustomToolCall as ChatCompletionMessageCustomToolCall,\n type ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall,\n type ChatCompletionMessageParam as ChatCompletionMessageParam,\n type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,\n type ChatCompletionModality as ChatCompletionModality,\n type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,\n type ChatCompletionNamedToolChoiceCustom as ChatCompletionNamedToolChoiceCustom,\n type ChatCompletionPredictionContent as ChatCompletionPredictionContent,\n type ChatCompletionRole as ChatCompletionRole,\n type ChatCompletionStoreMessage as ChatCompletionStoreMessage,\n type ChatCompletionStreamOptions as ChatCompletionStreamOptions,\n type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,\n type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,\n type ChatCompletionTool as ChatCompletionTool,\n type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,\n type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,\n type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,\n type ChatCompletionAllowedTools as ChatCompletionAllowedTools,\n type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,\n type ChatCompletionsPage as ChatCompletionsPage,\n type ChatCompletionCreateParams as ChatCompletionCreateParams,\n type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,\n type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,\n type ChatCompletionUpdateParams as ChatCompletionUpdateParams,\n type ChatCompletionListParams as ChatCompletionListParams,\n };\n\n export {\n Embeddings as Embeddings,\n type CreateEmbeddingResponse as CreateEmbeddingResponse,\n type Embedding as Embedding,\n type EmbeddingModel as EmbeddingModel,\n type EmbeddingCreateParams as EmbeddingCreateParams,\n };\n\n export {\n Files as Files,\n type FileContent as FileContent,\n type FileDeleted as FileDeleted,\n type FileObject as FileObject,\n type FilePurpose as FilePurpose,\n type FileObjectsPage as FileObjectsPage,\n type FileCreateParams as FileCreateParams,\n type FileListParams as FileListParams,\n };\n\n export {\n Images as Images,\n type Image as Image,\n type ImageEditCompletedEvent as ImageEditCompletedEvent,\n type ImageEditPartialImageEvent as ImageEditPartialImageEvent,\n type ImageEditStreamEvent as ImageEditStreamEvent,\n type ImageGenCompletedEvent as ImageGenCompletedEvent,\n type ImageGenPartialImageEvent as ImageGenPartialImageEvent,\n type ImageGenStreamEvent as ImageGenStreamEvent,\n type ImageModel as ImageModel,\n type ImagesResponse as ImagesResponse,\n type ImageCreateVariationParams as ImageCreateVariationParams,\n type ImageEditParams as ImageEditParams,\n type ImageEditParamsNonStreaming as ImageEditParamsNonStreaming,\n type ImageEditParamsStreaming as ImageEditParamsStreaming,\n type ImageGenerateParams as ImageGenerateParams,\n type ImageGenerateParamsNonStreaming as ImageGenerateParamsNonStreaming,\n type ImageGenerateParamsStreaming as ImageGenerateParamsStreaming,\n };\n\n export { Audio as Audio, type AudioModel as AudioModel, type AudioResponseFormat as AudioResponseFormat };\n\n export {\n Moderations as Moderations,\n type Moderation as Moderation,\n type ModerationImageURLInput as ModerationImageURLInput,\n type ModerationModel as ModerationModel,\n type ModerationMultiModalInput as ModerationMultiModalInput,\n type ModerationTextInput as ModerationTextInput,\n type ModerationCreateResponse as ModerationCreateResponse,\n type ModerationCreateParams as ModerationCreateParams,\n };\n\n export {\n Models as Models,\n type Model as Model,\n type ModelDeleted as ModelDeleted,\n type ModelsPage as ModelsPage,\n };\n\n export { FineTuning as FineTuning };\n\n export { Graders as Graders };\n\n export {\n VectorStores as VectorStores,\n type AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam,\n type FileChunkingStrategy as FileChunkingStrategy,\n type FileChunkingStrategyParam as FileChunkingStrategyParam,\n type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,\n type StaticFileChunkingStrategy as StaticFileChunkingStrategy,\n type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,\n type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,\n type VectorStore as VectorStore,\n type VectorStoreDeleted as VectorStoreDeleted,\n type VectorStoreSearchResponse as VectorStoreSearchResponse,\n type VectorStoresPage as VectorStoresPage,\n type VectorStoreSearchResponsesPage as VectorStoreSearchResponsesPage,\n type VectorStoreCreateParams as VectorStoreCreateParams,\n type VectorStoreUpdateParams as VectorStoreUpdateParams,\n type VectorStoreListParams as VectorStoreListParams,\n type VectorStoreSearchParams as VectorStoreSearchParams,\n };\n\n export { Webhooks as Webhooks };\n\n export { Beta as Beta };\n\n export {\n Batches as Batches,\n type Batch as Batch,\n type BatchError as BatchError,\n type BatchRequestCounts as BatchRequestCounts,\n type BatchUsage as BatchUsage,\n type BatchesPage as BatchesPage,\n type BatchCreateParams as BatchCreateParams,\n type BatchListParams as BatchListParams,\n };\n\n export {\n UploadsAPIUploads as Uploads,\n type Upload as Upload,\n type UploadCreateParams as UploadCreateParams,\n type UploadCompleteParams as UploadCompleteParams,\n };\n\n export { Responses as Responses };\n\n export { Realtime as Realtime };\n\n export { Conversations as Conversations };\n\n export {\n Evals as Evals,\n type EvalCustomDataSourceConfig as EvalCustomDataSourceConfig,\n type EvalStoredCompletionsDataSourceConfig as EvalStoredCompletionsDataSourceConfig,\n type EvalCreateResponse as EvalCreateResponse,\n type EvalRetrieveResponse as EvalRetrieveResponse,\n type EvalUpdateResponse as EvalUpdateResponse,\n type EvalListResponse as EvalListResponse,\n type EvalDeleteResponse as EvalDeleteResponse,\n type EvalListResponsesPage as EvalListResponsesPage,\n type EvalCreateParams as EvalCreateParams,\n type EvalUpdateParams as EvalUpdateParams,\n type EvalListParams as EvalListParams,\n };\n\n export {\n Containers as Containers,\n type ContainerCreateResponse as ContainerCreateResponse,\n type ContainerRetrieveResponse as ContainerRetrieveResponse,\n type ContainerListResponse as ContainerListResponse,\n type ContainerListResponsesPage as ContainerListResponsesPage,\n type ContainerCreateParams as ContainerCreateParams,\n type ContainerListParams as ContainerListParams,\n };\n\n export {\n Skills as Skills,\n type DeletedSkill as DeletedSkill,\n type Skill as Skill,\n type SkillList as SkillList,\n type SkillsPage as SkillsPage,\n type SkillCreateParams as SkillCreateParams,\n type SkillUpdateParams as SkillUpdateParams,\n type SkillListParams as SkillListParams,\n };\n\n export {\n Videos as Videos,\n type Video as Video,\n type VideoCreateError as VideoCreateError,\n type VideoModel as VideoModel,\n type VideoSeconds as VideoSeconds,\n type VideoSize as VideoSize,\n type VideoDeleteResponse as VideoDeleteResponse,\n type VideosPage as VideosPage,\n type VideoCreateParams as VideoCreateParams,\n type VideoListParams as VideoListParams,\n type VideoDownloadContentParams as VideoDownloadContentParams,\n type VideoRemixParams as VideoRemixParams,\n };\n\n export type AllModels = API.AllModels;\n export type ChatModel = API.ChatModel;\n export type ComparisonFilter = API.ComparisonFilter;\n export type CompoundFilter = API.CompoundFilter;\n export type CustomToolInputFormat = API.CustomToolInputFormat;\n export type ErrorObject = API.ErrorObject;\n export type FunctionDefinition = API.FunctionDefinition;\n export type FunctionParameters = API.FunctionParameters;\n export type Metadata = API.Metadata;\n export type Reasoning = API.Reasoning;\n export type ReasoningEffort = API.ReasoningEffort;\n export type ResponseFormatJSONObject = API.ResponseFormatJSONObject;\n export type ResponseFormatJSONSchema = API.ResponseFormatJSONSchema;\n export type ResponseFormatText = API.ResponseFormatText;\n export type ResponseFormatTextGrammar = API.ResponseFormatTextGrammar;\n export type ResponseFormatTextPython = API.ResponseFormatTextPython;\n export type ResponsesModel = API.ResponsesModel;\n}\n","// ─── Cue (one subtitle entry) ─────────────────────────────────────────────────\n\nexport type SubtitleFormat = \"srt\" | \"vtt\";\n\nexport interface Cue {\n id: number; // original sequence number\n startMs: number; // start time in milliseconds\n endMs: number; // end time in milliseconds\n text: string; // raw display text (may be a sentence fragment)\n lines: string[]; // original line breaks preserved\n}\n\n// ─── Reconstructed sentence ────────────────────────────────────────────────────\n\nexport interface ReconstructedSentence {\n sentenceId: number;\n text: string;\n cueIds: number[]; // which original cues contributed to this sentence\n // ratio of each cue's chars in the merged text (for re-anchoring)\n charRatios: number[];\n}\n\n// ─── Translation job ───────────────────────────────────────────────────────────\n\nexport type SupportedLanguage =\n | \"en\" | \"fr\" | \"pt\" | \"es\" | \"de\" | \"it\"\n | \"yo\" | \"ig\" | \"ha\" // Yoruba, Igbo, Hausa\n | \"ar\" | \"sw\" | \"zu\" | \"am\" // Arabic, Swahili, Zulu, Amharic\n | (string & {}); // escape hatch for unlisted BCP-47 tags\n\nexport interface TranslationMeta {\n /** Speaker / pastor name — will NOT be translated, kept as-is */\n speakerName?: string;\n /** Church or ministry name — will NOT be translated */\n churchName?: string;\n /** Recurring branded phrase, e.g. \"The Grace Revolution\" */\n seriesTitle?: string;\n /** Any extra glossary entries: source term → target term */\n glossary?: Record<string, string>;\n}\n\nexport type ContentDomain = \"sermon\" | \"general\";\n\nexport interface TranslateOptions {\n /** Source language BCP-47 tag. Defaults to \"en\" */\n sourceLang?: SupportedLanguage;\n /** Target language BCP-47 tag — required */\n targetLang: SupportedLanguage;\n /** Domain unlocks pre-baked register + vocabulary. Defaults to \"sermon\" */\n domain?: ContentDomain;\n /** Proper nouns + glossary — replaces the primer call entirely */\n meta?: TranslationMeta;\n /** Sentences per batch (default 25). Tune down for long sermons on tight rate limits */\n batchSize?: number;\n /** Context overlap: N sentences from the prev batch prepended (default 4) */\n contextOverlap?: number;\n /** OpenAI model override. Defaults to gpt-4o for non-Latin scripts, gpt-4o-mini otherwise */\n model?: \"gpt-4o\" | \"gpt-4o-mini\";\n /** Max concurrent batch requests (default 8) */\n concurrency?: number;\n /** Enable AI primer call — for general/unknown content only */\n primer?: boolean;\n}\n\n// ─── Output ────────────────────────────────────────────────────────────────────\n\nexport interface TranslatedCue extends Cue {\n translatedText: string;\n translatedLines: string[];\n}\n\nexport interface TranslationResult {\n sourceLang: string;\n targetLang: string;\n cues: TranslatedCue[];\n\n /** Render back to SRT string */\n toSRT(): string;\n\n /** Render back to VTT string */\n toVTT(): string;\n\n stats: TranslationStats;\n}\n\nexport interface TranslationStats {\n totalCues: number;\n totalSentences: number;\n totalBatches: number;\n inputTokens: number;\n outputTokens: number;\n estimatedCostUsd: number;\n durationMs: number;\n}\n\n// ─── Internal batch types ──────────────────────────────────────────────────────\n\nexport interface BatchPayload {\n batchIndex: number;\n sentences: ReconstructedSentence[];\n contextSentences: ReconstructedSentence[]; // overlap — model reads but does not re-translate\n}\n\nexport interface BatchResult {\n batchIndex: number;\n translations: Record<number, string>; // sentenceId → translated text\n inputTokens: number;\n outputTokens: number;\n}\n\n// ─── Errors ────────────────────────────────────────────────────────────────────\n\nexport class SubtitleTranslationError extends Error {\n constructor(\n message: string,\n public readonly code:\n | \"PARSE_ERROR\"\n | \"EMPTY_FILE\"\n | \"API_ERROR\"\n | \"BATCH_FAILED\"\n | \"REANCHOR_ERROR\",\n public override readonly cause?: unknown\n ) {\n super(message);\n this.name = \"SubtitleTranslationError\";\n }\n}\n","import type {Cue, SubtitleFormat} from \"../types/types.js\";\nimport {SubtitleTranslationError} from \"../types/types.js\";\n\n// ─── Time helpers ──────────────────────────────────────────────────────────────\n\nfunction srtTimeToMs(t: string): number {\n // 00:01:23,456\n const [hms, ms] = t.split(\",\");\n const [h, m, s] = hms!.split(\":\").map(Number);\n //TODO; Revisit if default 0 is problematic\n return (h ?? 0) * 3_600_000 + (m ?? 0) * 60_000 + (s ?? 0) * 1_000 + Number(ms);\n}\n\nfunction vttTimeToMs(t: string): number {\n // 00:01:23.456 or 01:23.456\n const parts = t.split(\":\");\n let h = 0, m = 0, s = 0;\n if (parts.length === 3) {\n [h, m] = [Number(parts[0]), Number(parts[1])];\n s = parseFloat(parts[2]!);\n } else {\n m = Number(parts[0]);\n s = parseFloat(parts[1]!);\n }\n return Math.round(h * 3_600_000 + m * 60_000 + s * 1_000);\n}\n\nexport function msToSrtTime(ms: number): string {\n const h = Math.floor(ms / 3_600_000);\n const m = Math.floor((ms % 3_600_000) / 60_000);\n const s = Math.floor((ms % 60_000) / 1_000);\n const f = ms % 1_000;\n return `${pad(h)}:${pad(m)}:${pad(s)},${pad(f, 3)}`;\n}\n\nexport function msToVttTime(ms: number): string {\n return msToSrtTime(ms).replace(\",\", \".\");\n}\n\nfunction pad(n: number, len = 2): string {\n return String(n).padStart(len, \"0\");\n}\n\n// ─── Strip markup ──────────────────────────────────────────────────────────────\n\nfunction stripTags(text: string): string {\n return text\n .replace(/<[^>]+>/g, \"\") // HTML/VTT tags\n .replace(/\\{[^}]+\\}/g, \"\") // ASS/SSA style overrides\n .trim();\n}\n\n// ─── SRT parser ───────────────────────────────────────────────────────────────\n\nfunction parseSRT(raw: string): Cue[] {\n const blocks = raw\n .replace(/\\r\\n/g, \"\\n\")\n .replace(/\\r/g, \"\\n\")\n .trim()\n .split(/\\n{2,}/);\n\n const cues: Cue[] = [];\n\n for (const block of blocks) {\n const lines = block.split(\"\\n\").map((l) => l.trim()).filter(Boolean);\n if (lines.length < 3) continue;\n\n const id = parseInt(lines[0]!, 10);\n const timeParts = lines[1]!.match(\n /(\\d{2}:\\d{2}:\\d{2},\\d{3})\\s*-->\\s*(\\d{2}:\\d{2}:\\d{2},\\d{3})/\n );\n if (!timeParts) continue;\n\n const textLines = lines.slice(2).map(stripTags);\n cues.push({\n id,\n startMs: srtTimeToMs(timeParts[1]!),\n endMs: srtTimeToMs(timeParts[2]!),\n text: textLines.join(\" \"),\n lines: textLines,\n });\n }\n\n return cues;\n}\n\n// ─── VTT parser ───────────────────────────────────────────────────────────────\n\nfunction parseVTT(raw: string): Cue[] {\n const normalised = raw\n .replace(/\\r\\n/g, \"\\n\")\n .replace(/\\r/g, \"\\n\")\n .trim();\n\n if (!normalised.startsWith(\"WEBVTT\")) {\n throw new SubtitleTranslationError(\n \"VTT file must start with WEBVTT header\",\n \"PARSE_ERROR\"\n );\n }\n\n const blocks = normalised.split(/\\n{2,}/).slice(1); // drop header block\n const cues: Cue[] = [];\n let autoId = 1;\n\n for (const block of blocks) {\n const lines = block.split(\"\\n\").map((l) => l.trim()).filter(Boolean);\n if (!lines.length) continue;\n\n // Optional cue identifier line\n let offset = 0;\n if (!lines[0]?.includes(\"-->\")) offset = 1;\n\n const timeLine = lines[offset];\n if (!timeLine?.includes(\"-->\")) continue;\n\n const timeParts = timeLine.match(\n /([\\d:.]+)\\s*-->\\s*([\\d:.]+)/\n );\n if (!timeParts) continue;\n\n const textLines = lines.slice(offset + 1).map(stripTags);\n if (!textLines.length) continue;\n\n cues.push({\n id: autoId++,\n startMs: vttTimeToMs(timeParts[1]!),\n endMs: vttTimeToMs(timeParts[2]!),\n text: textLines.join(\" \"),\n lines: textLines,\n });\n }\n\n return cues;\n}\n\n// ─── Public API ───────────────────────────────────────────────────────────────\n\nexport function detectFormat(raw: string): SubtitleFormat {\n return raw.trimStart().startsWith(\"WEBVTT\") ? \"vtt\" : \"srt\";\n}\n\nexport function parseCues(raw: string, format?: SubtitleFormat): Cue[] {\n const fmt = format ?? detectFormat(raw);\n const cues = fmt === \"vtt\" ? parseVTT(raw) : parseSRT(raw);\n\n if (!cues.length) {\n throw new SubtitleTranslationError(\n \"No cues found in subtitle file\",\n \"EMPTY_FILE\"\n );\n }\n\n return cues;\n}\n","import type {Cue, ReconstructedSentence} from \"../types/types.js\";\n\n// A sentence ends when the text finishes with one of these patterns\nconst SENTENCE_END = /[.!?…][\"'»\\s]?$/;\n\n// Filler words that shouldn't trigger a sentence boundary even if preceded by a period\n// e.g. \"Rev.\", \"Dr.\", \"Mt.\", \"vs.\" — avoids premature splits\nconst ABBREV = /\\b(Mr|Mrs|Ms|Dr|Prof|Rev|St|Mt|vs|etc|approx|Corp|Inc|Ltd)\\.\\s*$/i;\n\nfunction isSentenceEnd(text: string): boolean {\n const trimmed = text.trimEnd();\n if (ABBREV.test(trimmed)) return false;\n return SENTENCE_END.test(trimmed);\n}\n\nexport function reconstructSentences(cues: Cue[]): ReconstructedSentence[] {\n const sentences: ReconstructedSentence[] = [];\n let buffer: Cue[] = [];\n let sentenceId = 0;\n\n const flush = () => {\n if (!buffer.length) return;\n\n const fullText = buffer.map((c) => c.text).join(\" \").replace(/\\s+/g, \" \").trim();\n const totalChars = buffer.reduce((sum, c) => sum + c.text.length, 0);\n\n const charRatios = buffer.map((c) =>\n totalChars > 0 ? c.text.length / totalChars : 1 / buffer.length\n );\n\n sentences.push({\n sentenceId: sentenceId++,\n text: fullText,\n cueIds: buffer.map((c) => c.id),\n charRatios,\n });\n\n buffer = [];\n };\n\n for (const cue of cues) {\n buffer.push(cue);\n\n if (isSentenceEnd(cue.text)) {\n flush();\n }\n }\n\n // Flush any trailing fragment (e.g. \"Amen.\" without trailing newline)\n flush();\n\n return sentences;\n}\n","import type { ContentDomain, SupportedLanguage, TranslationMeta, TranslateOptions } from \"../types/types.js\";\n\nconst DOMAIN_INSTRUCTIONS: Record<ContentDomain, string> = {\n sermon: `Domain: Christian sermon / religious teaching.\nRegister: reverent, formal — never use casual or colloquial substitutes for sacred terms.\nPreserve exactly: scripture references (e.g. \"John 3:16\"), \"Amen\", \"Hallelujah\", \"the Holy Spirit\", \"grace\", \"salvation\".\nFragmented exclamations (\"Praise God!\", \"Glory!\") are intentional — keep them as fragments.\nDo not explain metaphors or idioms — translate them faithfully.`,\n\n general: `Domain: general video content.\nPreserve the speaker's natural register and sentence rhythm.\nDo not add formality that isn't in the source.`,\n};\n\n// Languages that use non-Latin scripts — always route to gpt-4o\nconst NON_LATIN_SCRIPTS = new Set([\"ar\", \"am\", \"zh\", \"ja\", \"ko\", \"hi\", \"ru\", \"uk\", \"el\"]);\n\nexport function pickModel(\n targetLang: SupportedLanguage,\n override?: TranslateOptions[\"model\"]\n): \"gpt-4o\" | \"gpt-4o-mini\" {\n if (override) return override;\n // Yoruba, Igbo, Hausa — also need 4o for quality\n const needsFullModel = NON_LATIN_SCRIPTS.has(targetLang) ||\n [\"yo\", \"ig\", \"ha\", \"sw\", \"zu\"].includes(targetLang);\n return needsFullModel ? \"gpt-4o\" : \"gpt-4o-mini\";\n}\n\nfunction buildGlossaryBlock(meta: TranslationMeta): string {\n const lines: string[] = [];\n\n if (meta.speakerName) {\n lines.push(`Speaker name: \"${meta.speakerName}\" — keep exactly, do not translate.`);\n }\n if (meta.churchName) {\n lines.push(`Church/ministry: \"${meta.churchName}\" — keep exactly, do not translate.`);\n }\n if (meta.seriesTitle) {\n lines.push(`Series title: \"${meta.seriesTitle}\" — keep exactly as-is.`);\n }\n if (meta.glossary) {\n for (const [src, tgt] of Object.entries(meta.glossary)) {\n lines.push(`\"${src}\" → \"${tgt}\"`);\n }\n }\n\n return lines.length\n ? `GLOSSARY (must follow exactly):\\n${lines.map((l) => `- ${l}`).join(\"\\n\")}`\n : \"\";\n}\n\nexport function buildSystemPrompt(opts: TranslateOptions): string {\n const sourceLang = opts.sourceLang ?? \"en\";\n const domain = opts.domain ?? \"sermon\";\n const domainBlock = DOMAIN_INSTRUCTIONS[domain];\n const glossaryBlock = opts.meta ? buildGlossaryBlock(opts.meta) : \"\";\n\n return [\n `You are a professional subtitle translator. Translate from ${sourceLang} to ${opts.targetLang}.`,\n domainBlock,\n glossaryBlock,\n `RULES:\n- Preserve ALL-CAPS emphasis, ellipses (...), dashes (—), and line-ending punctuation exactly.\n- Never merge or split sentences — one input item = one output item.\n- Never add explanatory text, parentheticals, or translator notes.\n- Output ONLY valid JSON. No markdown, no code fences, no preamble.`,\n `OUTPUT FORMAT:\n[{\"id\":<number>,\"t\":\"<translated text>\"},...]`,\n ]\n .filter(Boolean)\n .join(\"\\n\\n\");\n}\n\nexport function buildUserMessage(\n sentences: Array<{ sentenceId: number; text: string }>,\n contextSentences: Array<{ sentenceId: number; text: string }>\n): string {\n const parts: string[] = [];\n\n if (contextSentences.length) {\n parts.push(\n \"CONTEXT (already translated — do NOT include in output):\\n\" +\n contextSentences.map((s) => `[${s.sentenceId}] ${s.text}`).join(\"\\n\")\n );\n }\n\n parts.push(\n \"TRANSLATE:\\n\" +\n JSON.stringify(sentences.map((s) => ({ id: s.sentenceId, text: s.text })))\n );\n\n return parts.join(\"\\n\\n\");\n}\n","import OpenAI from \"openai\";\nimport type {\n BatchPayload,\n BatchResult,\n ReconstructedSentence,\n TranslateOptions,\n} from \"../types/types.js\";\nimport {\n SubtitleTranslationError,\n} from \"../types/types.js\";\nimport {buildSystemPrompt, buildUserMessage, pickModel} from \"./prompts.js\";\n\n// ─── Concurrency limiter (no external deps) ────────────────────────────────────\n\nasync function pLimit<T>(\n tasks: Array<() => Promise<T>>,\n concurrency: number\n): Promise<T[]> {\n const results: T[] = new Array(tasks.length);\n let index = 0;\n\n const worker = async () => {\n while (index < tasks.length) {\n const i = index++;\n results[i] = await tasks[i]!();\n }\n };\n\n await Promise.all(Array.from({length: concurrency}, worker));\n return results;\n}\n\n// ─── Parse model JSON response ────────────────────────────────────────────────\n\nfunction parseTranslations(raw: string): Record<number, string> {\n let text = raw.trim();\n // Strip accidental code fences\n text = text.replace(/^```(?:json)?\\n?/i, \"\").replace(/\\n?```$/i, \"\");\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n throw new SubtitleTranslationError(\n `Model returned invalid JSON: ${text.slice(0, 200)}`,\n \"BATCH_FAILED\"\n );\n }\n\n if (!Array.isArray(parsed)) {\n throw new SubtitleTranslationError(\n \"Model response was not a JSON array\",\n \"BATCH_FAILED\"\n );\n }\n\n const map: Record<number, string> = {};\n for (const item of parsed) {\n if (\n typeof item === \"object\" &&\n item !== null &&\n typeof (item as any).id === \"number\" &&\n typeof (item as any).t === \"string\"\n ) {\n map[(item as any).id] = (item as any).t;\n }\n }\n return map;\n}\n\n// ─── Single batch call ────────────────────────────────────────────────────────\n\nasync function executeBatch(\n client: OpenAI,\n payload: BatchPayload,\n systemPrompt: string,\n model: \"gpt-4o\" | \"gpt-4o-mini\",\n retries = 2\n): Promise<BatchResult> {\n const userMessage = buildUserMessage(\n payload.sentences,\n payload.contextSentences\n );\n\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= retries; attempt++) {\n try {\n const response = await client.chat.completions.create({\n model,\n temperature: 0.1, // low temp = deterministic, less hallucination\n messages: [\n {role: \"system\", content: systemPrompt},\n {role: \"user\", content: userMessage},\n ],\n });\n\n const content = response.choices[0]?.message?.content ?? \"\";\n const translations = parseTranslations(content);\n\n return {\n batchIndex: payload.batchIndex,\n translations,\n inputTokens: response.usage?.prompt_tokens ?? 0,\n outputTokens: response.usage?.completion_tokens ?? 0,\n };\n } catch (err) {\n lastError = err;\n if (attempt < retries) {\n // Exponential backoff: 500ms, 1000ms\n await new Promise((r) => setTimeout(r, 500 * Math.pow(2, attempt)));\n }\n }\n }\n\n throw new SubtitleTranslationError(\n `Batch ${payload.batchIndex} failed after ${retries + 1} attempts`,\n \"BATCH_FAILED\",\n lastError\n );\n}\n\n// ─── Build batch payloads ─────────────────────────────────────────────────────\n\nfunction buildBatches(\n sentences: ReconstructedSentence[],\n batchSize: number,\n overlap: number\n): BatchPayload[] {\n const payloads: BatchPayload[] = [];\n\n for (let i = 0; i < sentences.length; i += batchSize) {\n const chunk = sentences.slice(i, i + batchSize);\n const context = i > 0 ? sentences.slice(Math.max(0, i - overlap), i) : [];\n\n payloads.push({\n batchIndex: payloads.length,\n sentences: chunk,\n contextSentences: context,\n });\n }\n\n return payloads;\n}\n\n// ─── Public executor ──────────────────────────────────────────────────────────\n\nexport interface ExecuteResult {\n translations: Record<number, string>;\n totalInputTokens: number;\n totalOutputTokens: number;\n totalBatches: number;\n}\n\nexport async function executeTranslation(\n client: OpenAI,\n sentences: ReconstructedSentence[],\n opts: TranslateOptions\n): Promise<ExecuteResult> {\n const batchSize = opts.batchSize ?? 25;\n const overlap = opts.contextOverlap ?? 4;\n const concurrency = opts.concurrency ?? 8;\n const model = pickModel(opts.targetLang, opts.model);\n const systemPrompt = buildSystemPrompt(opts);\n\n const payloads = buildBatches(sentences, batchSize, overlap);\n\n const tasks = payloads.map(\n (payload) => () => executeBatch(client, payload, systemPrompt, model)\n );\n\n const results = await pLimit(tasks, concurrency);\n\n const merged: Record<number, string> = {};\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n\n for (const result of results) {\n Object.assign(merged, result.translations);\n totalInputTokens += result.inputTokens;\n totalOutputTokens += result.outputTokens;\n }\n\n return {\n translations: merged,\n totalInputTokens,\n totalOutputTokens,\n totalBatches: payloads.length,\n };\n}\n","import type {Cue, ReconstructedSentence, TranslatedCue} from \"../types/types.js\";\n\n/**\n * Splits a translated sentence across the original cues it came from,\n * using character ratios as a proportional guide.\n *\n * Strategy:\n * 1. Try to split on word boundaries near the ratio breakpoints.\n * 2. Fall back to hard char-count split if no word boundary found nearby.\n */\nfunction splitByRatios(text: string, ratios: number[]): string[] {\n if (ratios.length === 1) return [text];\n\n const words = text.split(\" \");\n const totalChars = text.length;\n const parts: string[] = [];\n\n let charTarget = 0;\n let wordOffset = 0;\n\n for (let i = 0; i < ratios.length - 1; i++) {\n charTarget += Math.round(ratios[i]! * totalChars);\n\n // Walk words until we've consumed ~charTarget characters\n let accumulated = wordOffset > 0 ? -1 : 0; // account for spaces\n let splitAt = wordOffset;\n\n for (let w = wordOffset; w < words.length; w++) {\n accumulated += (w > wordOffset ? 1 : 0) + words[w]!.length;\n splitAt = w + 1;\n if (accumulated >= charTarget - wordOffset) break;\n }\n\n const chunk = words.slice(wordOffset, splitAt).join(\" \");\n parts.push(chunk.trim());\n wordOffset = splitAt;\n }\n\n // Last part gets remainder\n parts.push(words.slice(wordOffset).join(\" \").trim());\n\n return parts;\n}\n\n/**\n * Wraps a translated string to respect the original line structure.\n * Tries to preserve the same number of lines; falls back to a single line.\n */\nfunction wrapToLines(text: string, originalLines: string[]): string[] {\n if (originalLines.length === 1) return [text];\n\n const words = text.split(\" \");\n const totalLines = originalLines.length;\n const wordsPerLine = Math.ceil(words.length / totalLines);\n const result: string[] = [];\n\n for (let i = 0; i < totalLines; i++) {\n const slice = words.slice(i * wordsPerLine, (i + 1) * wordsPerLine);\n if (slice.length) result.push(slice.join(\" \"));\n }\n\n return result.length ? result : [text];\n}\n\nexport function reanchorCues(\n originalCues: Cue[],\n sentences: ReconstructedSentence[],\n translations: Record<number, string>\n): TranslatedCue[] {\n // Index cues by id for O(1) lookup\n const cueMap = new Map<number, Cue>(originalCues.map((c) => [c.id, c]));\n\n // Index translated sentences by sentenceId\n const sentenceMap = new Map<number, ReconstructedSentence>(\n sentences.map((s) => [s.sentenceId, s])\n );\n\n // Build translated text for each cue id\n const translatedByCueId = new Map<number, string>();\n\n for (const sentence of sentences) {\n const translated = translations[sentence.sentenceId];\n if (!translated) continue;\n\n if (sentence.cueIds.length === 1) {\n translatedByCueId.set(sentence.cueIds.at(0)!, translated);\n } else {\n const parts = splitByRatios(translated, sentence.charRatios);\n sentence.cueIds.forEach((cueId, i) => {\n translatedByCueId.set(cueId, parts[i] ?? \"\");\n });\n }\n }\n\n // Assemble final translated cues — preserve ALL original cues, even untranslated ones\n return originalCues.map((cue): TranslatedCue => {\n const translatedText = translatedByCueId.get(cue.id) ?? cue.text;\n const translatedLines = wrapToLines(translatedText, cue.lines);\n\n return {\n ...cue,\n translatedText,\n translatedLines,\n };\n });\n}\n","import type {TranslatedCue} from \"../types/types.js\";\nimport { msToSrtTime, msToVttTime } from \"./parser.js\";\n\nexport function emitSRT(cues: TranslatedCue[]): string {\n return cues\n .map((cue, i) =>\n [\n String(i + 1),\n `${msToSrtTime(cue.startMs)} --> ${msToSrtTime(cue.endMs)}`,\n cue.translatedLines.join(\"\\n\"),\n ].join(\"\\n\")\n )\n .join(\"\\n\\n\");\n}\n\nexport function emitVTT(cues: TranslatedCue[]): string {\n const header = \"WEBVTT\\n\\n\";\n const body = cues\n .map((cue, i) =>\n [\n String(i + 1),\n `${msToVttTime(cue.startMs)} --> ${msToVttTime(cue.endMs)}`,\n cue.translatedLines.join(\"\\n\"),\n ].join(\"\\n\")\n )\n .join(\"\\n\\n\");\n return header + body;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,uBAAuB,UAAU,OAAO,OAAO,MAAM,GAAG;AAC7D,MAAI,SAAS;AACT,UAAM,IAAI,UAAU,gCAAgC;AACxD,MAAI,SAAS,OAAO,CAAC;AACjB,UAAM,IAAI,UAAU,+CAA+C;AACvE,MAAI,OAAO,UAAU,aAAa,aAAa,SAAS,CAAC,IAAI,CAAC,MAAM,IAAI,QAAQ;AAC5E,UAAM,IAAI,UAAU,yEAAyE;AACjG,SAAO,SAAS,MAAM,EAAE,KAAK,UAAU,KAAK,IAAI,IAAK,EAAE,QAAQ,QAAS,MAAM,IAAI,UAAU,KAAK,GAAG;AACxG;AACA,SAAS,uBAAuB,UAAU,OAAO,MAAM,GAAG;AACtD,MAAI,SAAS,OAAO,CAAC;AACjB,UAAM,IAAI,UAAU,+CAA+C;AACvE,MAAI,OAAO,UAAU,aAAa,aAAa,SAAS,CAAC,IAAI,CAAC,MAAM,IAAI,QAAQ;AAC5E,UAAM,IAAI,UAAU,0EAA0E;AAClG,SAAO,SAAS,MAAM,IAAI,SAAS,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,EAAE,QAAQ,MAAM,IAAI,QAAQ;AAChG;;;ACVO,IAAI,QAAQ,WAAA;AACjB,QA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AAsB,cAClB,WACA,YACA,MACA,QAC0B;AAC1B,QAAM,UAAU,UAAM,0BAAS,WAAW,OAAO;AACjD,QAAM,SAAS,MAAM,UAAU,SAAS,MAAM,MAAM;AAEpD,QAAM,UAAM,uBAAQ,UAAU,EAAE,YAAY;AAC5C,QAAM,SAAS,QAAQ,SAAS,OAAO,MAAM,IAAI,OAAO,MAAM;AAC9D,YAAM,2BAAU,YAAY,QAAQ,OAAO;AAE3C,SAAO;AACX;","names":["crypto","str","str","str","parseResponse","Page","client","process","fetch","str","path","inputTool","content","name","_AbstractChatCompletionRunner_getFinalMessage","_AbstractChatCompletionRunner_getFinalFunctionToolCall","_AbstractChatCompletionRunner_getFinalFunctionToolCallResult","_AbstractChatCompletionRunner_calculateTotalUsage","_AbstractChatCompletionRunner_validateParams","_AbstractChatCompletionRunner_stringifyFunctionCallResult","escape","e","_ChatCompletionStream_beginRequest","_ChatCompletionStream_getChoiceEventState","_ChatCompletionStream_addChunk","_ChatCompletionStream_emitToolCallDoneEvent","_ChatCompletionStream_emitContentDoneEvents","_ChatCompletionStream_endRequest","_ChatCompletionStream_getAutoParseableResponseFormat","_ChatCompletionStream_accumulateChatCompletion","content","refusal","rest","_a","index","chunk","id","Sessions","Sessions","Messages","chunk","assertNever","_AssistantStream_endRequest","_AssistantStream_handleMessage","_AssistantStream_handleRunStep","_AssistantStream_handleEvent","_AssistantStream_accumulateRunStep","_AssistantStream_accumulateMessage","_AssistantStream_accumulateContent","_AssistantStream_handleRun","Threads","Messages","Threads","Completions","response","Runs","Runs","Files","Checkpoints","Checkpoints","Graders","Realtime","hasAutoParseableInput","parseToolCall","content","output","isAutoParsableTool","parseToolCall","_ResponseStream_beginRequest","_ResponseStream_addEvent","event","_ResponseStream_endRequest","_ResponseStream_accumulateResponse","Content","Content","Content","Content","Files","Files","_Webhooks_getRequiredHeader","Completions","Files","Graders","Realtime","_a","path","opts","retryMessage","err","Page","import_path"]}
|