Docs menu

Platform APIs

OpenAI API

Every handle of the OpenAI fake: the openai fixture, the scripts a test answers the model's calls with, and the calls it reads and waits for. How to script the model, step by step, is in the OpenAI guide.

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

Besides the errors listed with each method, most methods can fail with action_requires, cross_workspace_credential, fake_actor_in_live_world, internal, invalid_argument, live_misconfigured, live_not_allowlisted, not_found, session_not_found, unauthorized, unsupported_in_live: a bad request, a closed session, or live mode refusing or misconfigured.

OpenAIFixture#

Returned by Session.openai().

FieldPython / RustType
baseUrlbase_urlstring

respond()#

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

const script = await openai.respond({ when });
ParameterTypeRequired
turnsOpenAITurnInput | OpenAITurnInput[]nopositional
whenOpenAIMatchnooption
timesnumbernooption
timingOpenAITimingnooption
responderbooleannooption

Returns OpenAIScript.

calls()#

Every model call attributed to this session, oldest first.

const sessionCalls = await openai.calls({ endpoint });
ParameterTypeRequired
endpointOpenAIEndpointnooption
errortrue | stringnooption

Returns OpenAISessionCalls.

toolCalls()#

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

const sessionToolCalls = await openai.toolCalls({ name: "…" });
ParameterTypeRequired
namestringnooption

Returns OpenAISessionToolCalls.

problems()#

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

const problems = await openai.problems();

Returns OpenAIProblems.

sentSecrets()#

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

const sentSecrets = await openai.sentSecrets();

Returns OpenAISentSecrets.

unattributed()#

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

const unattributedCalls = await openai.unattributed({ withinMs });
ParameterPython / RustTypeRequired
withinMswithin_msnumber | undefinednooption

Returns OpenAIUnattributedCalls.

rateLimit()#

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

const rateLimit = await openai.rateLimit({ requests });
ParameterTypeRequired
requests{ limit: number; per?: Duration }nooption
tokens{ limit: number; per?: Duration }nooption
error"rate_limit" | "slow_down"nooption

Returns OpenAIRateLimit.

waitForCall()#

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

const call = await openai.waitForCall({ endpoint });
ParameterTypeRequired
endpointOpenAIEndpointnofilter
errortrue | stringnofilter
timeoutDurationnodefault 10s

Returns OpenAICall. When the time is up, it fails with what it was waiting for.

latestCall()#

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

const call = await openai.latestCall({ endpoint });
ParameterPython / RustTypeRequired
endpointendpointOpenAIEndpointnofilter
errorerrortrue | stringnofilter
timeouttimeoutDurationnodefault 10s
quietForquiet_forDurationnodefault 750ms

Returns OpenAICall. When the time is up, it fails with what it was waiting for.

OpenAIScript#

Returned by OpenAIFixture.respond(), OpenAIScript.refresh().

FieldType
idstring
responderboolean
timesnumber
usednumber
problemsstring[]

refresh()#

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

const updated = await script.refresh();

Returns OpenAIScript.

undo()#

Remove a script. Closing the session does it too.

await script.undo();

Returns nothing. Disposing the handle calls it.

resume()#

Let the streams this script holds at pauseAfter go on.

await script.resume();

Returns nothing.

calls()#

The calls this script answered.

const calls = await script.calls();

Returns OpenAICalls.

pausedCalls()#

The calls whose streams this script holds at pauseAfter.

const pausedCalls = await script.pausedCalls();

Returns OpenAIPausedCalls.

toolCalls()#

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

const toolCalls = await script.toolCalls({ name: "…" });
ParameterTypeRequired
namestringnooption

Returns OpenAIToolCalls.

heldCalls()#

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

const heldPage = await script.heldCalls({ since: "…" });
ParameterPython / RustTypeRequired
sincesincestringnooption
waitMswait_msnumber | undefinednooption

Returns OpenAIHeldPage.

answerHeld()#

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

await script.answerHeld("…", { turn });
ParameterTypeRequired
heldstringyespositional
turnOpenAITurnInputnooption
errorstringnooption

Returns nothing.

waitForCall()#

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

const call = await script.waitForCall();
ParameterTypeRequired
timeoutDurationnodefault 10s

Returns OpenAICall. When the time is up, it fails with what it was waiting for.

waitForPause()#

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

const call = await script.waitForPause();
ParameterTypeRequired
timeoutDurationnodefault 10s

Returns OpenAICall. When the time is up, it fails with what it was waiting for.

OpenAICall#

Returned by OpenAICall.refresh().

FieldPython / RustType
ididstring
endpointendpointOpenAIEndpoint
modelmodelstring
streamstreamboolean
atatstring
durationMsduration_msnumber
attemptattemptnumber
donedoneboolean
requestrequestOpenAIRequest
responseresponse{ status: number; text?: string; finish?: string; error?: string; aborted: boolean; chunksSent?: number; end?: "completed" | "errored" | "dropped" | "stalled" | "aborted" }
toolCallstool_callsOpenAIToolCall[]
scriptscriptstring | undefined

refresh()#

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

const updated = await call.refresh();

Returns OpenAICall.

OpenAIRateLimit#

Returned by OpenAIFixture.rateLimit(), OpenAIRateLimit.remaining().

FieldPython / RustType
ididstring
requestsrequestsnumber | undefined
tokenstokensnumber | undefined
resetsInMsresets_in_msnumber

remaining()#

What the rate limit's headers would say now.

const updated = await rateLimit.remaining();

Returns OpenAIRateLimit.

undo()#

Remove the rate limit.

await rateLimit.undo();

Returns nothing. Disposing the handle calls it.

Types#

Plain values the handles return and take.

OpenAITurnInput#

type OpenAITurnInput = string | OpenAITurn;

OpenAITurn#

FieldPython / RustType
texttextstring | string[] | undefined
toolCallstool_callsOpenAIToolCallSpec[] | undefined
citationscitationsArray<{ quote: string; url?: string; title?: string; file?: string }> | undefined
imageimageOpenAIMediaSource | OpenAIMediaSource[] | undefined
audioaudioOpenAIMediaSource | undefined
reasoningreasoning{ summary?: string | string[]; tokens?: number } | undefined
refusalrefusalstring | undefined
finishfinish"stop" | "length" | "content_filter" | undefined
usageusage{ input?: number; output?: number; reasoning?: number; cached?: number } | undefined
timingtimingOpenAITiming | undefined
failAfterfail_after{ chunks: number; how?: "error" | "drop" | "stall" } | undefined
pauseAfterpause_afternumber | undefined
errorerror"rate_limit" | "slow_down" | "insufficient_quota" | "credit_balance_exhausted" | "organization_spend_limit_exceeded" | "project_spend_limit_exceeded" | "organization_usage_limit_exceeded" | "server_error" | "overloaded" | "timeout" | "context_length_exceeded" | "content_policy" | "invalid_api_key" | "not_in_organization" | "ip_not_authorized" | "unsupported_region" | undefined
retryAfterretry_afternumber | string | undefined
shouldRetryshould_retryboolean | undefined
messagemessagestring | undefined

OpenAIToolCallSpec#

FieldPython / RustType
namenamestring | undefined
argumentsargumentsRecord<string, unknown> | string | undefined
inputinputstring | undefined
webSearchweb_search{ query: string; action?: "search" | "open_page" | "find_in_page"; url?: string; pattern?: string; sources?: Array<{ url: string; title?: string }> } | undefined
fileSearchfile_search{ queries: string[]; results?: Array<{ file: string; text: string; score?: number }> } | undefined
codeInterpretercode_interpreter{ code: string; logs?: string; files?: OpenAIMediaSource[] } | undefined
imageGenerationimage_generation{ image: OpenAIMediaSource; revisedPrompt?: string } | undefined
mcpmcp{ server: string; tool: string; arguments?: Record<string, unknown>; output?: string; error?: string; approval?: boolean } | undefined
shellshell{ commands: string[]; output?: string } | undefined
computercomputer{ actions: OpenAIComputerAction[] } | undefined
applyPatchapply_patch{ operations: OpenAIPatchOperation[] } | undefined

OpenAIMediaSource#

type OpenAIMediaSource = MediaSource;

OpenAIComputerAction#

FieldPython / RustType
typetype · r#typestring

OpenAIPatchOperation#

FieldPython / RustType
typetype · r#type"create_file" | "update_file" | "delete_file"
pathpathstring
diffdiffstring | undefined

OpenAITiming#

FieldPython / RustType
firstTokenfirst_tokennumber | string | undefined
betweenChunksbetween_chunksnumber | string | undefined

OpenAIMatch#

FieldPython / RustType
texttextstring | RegExp | undefined
promptpromptstring | RegExp | undefined
toolstoolsstring[] | undefined
toolResulttool_resultboolean | string | undefined
endpointendpoint"chat.completions" | "responses" | "images.generations" | "images.edits" | "audio.speech" | "audio.transcriptions" | "audio.translations" | undefined
modelmodelstring | RegExp | undefined
streamstreamboolean | undefined
fromfrom_ · fromSlackUser | GitHubUser | LinearUser | NotionUser | ResendUser | GoogleUser | DiscordUser | undefined
inin_ · r#inSlackConversation | GitHubRepo | LinearTeam | NotionPage | NotionDatabase | ResendThread | GoogleThread | DiscordChannel | undefined
approvalapprovalboolean | undefined

OpenAICalls#

type OpenAICalls = OpenAICall[];

OpenAIEndpoint#

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

OpenAIRequest#

FieldPython / RustType
endpointendpointOpenAIEndpoint
modelmodelstring
streamstreamboolean
promptpromptstring | undefined
filefileOpenAIPart | undefined
instructionsinstructionsstring | undefined
messagesmessagesOpenAIMessage[]
toolstoolsOpenAITool[]
toolChoicetool_choiceunknown | undefined
responseFormatresponse_formatunknown | undefined
lastUserTextlast_user_textstring | undefined
lastToolResultslast_tool_resultsArray<{ callId: string; name?: string; text: string }>
texttextstring
contextcontextOpenAIContext
bodybodyunknown | undefined
headersheadersRecord<string, string>

OpenAIPart#

FieldPython / RustType
typetype · r#type"image" | "file" | "audio"
fromfrom_ · from"data" | "file_id" | "url"
urlurlstring | undefined
fileIdfile_idstring | undefined
mediaTypemedia_typestring | undefined
bytesbytesnumber | undefined
sha256sha256string | undefined
filenamefilenamestring | undefined

OpenAIMessage#

FieldPython / RustType
rolerole"system" | "developer" | "user" | "assistant" | "tool"
texttextstring
toolCallstool_callsArray<{ id: string; name: string; arguments?: unknown }> | undefined
callIdcall_idstring | undefined
namenamestring | undefined
partspartsOpenAIPart[] | undefined

OpenAITool#

FieldPython / RustType
typetype · r#typestring
namenamestring | undefined
descriptiondescriptionstring | undefined
parametersparametersunknown | undefined
strictstrictboolean | undefined
settingssettingsRecord<string, unknown> | undefined

OpenAIContext#

FieldPython / RustType
channelchannelstring | undefined
fromfrom_ · fromOpenAIRef | undefined
conversationconversationOpenAIRef | undefined
threadthreadOpenAIRef | undefined
messagemessageOpenAIRef | undefined
attributedByattributed_by"minted_id" | "tag" | "owned_id" | "text" | "order" | undefined
matchedmatchedstring | undefined
tiedWithtied_withstring[] | undefined

OpenAIRef#

FieldType
idstring

OpenAIToolCall#

FieldPython / RustType
ididstring
typetype · r#type"function" | "custom" | "web_search" | "file_search" | "code_interpreter" | "image_generation" | "mcp" | "shell" | "computer" | "apply_patch"
hostedhostedboolean
namenamestring
argumentsargumentsunknown | undefined
madeInmade_instring
resultresult{ text: string; sentIn: string } | undefined

OpenAIPausedCalls#

type OpenAIPausedCalls = OpenAICall[];

OpenAIToolCalls#

type OpenAIToolCalls = OpenAIToolCall[];

OpenAIHeldPage#

FieldType
heldOpenAIHeldCall[]
cursorstring

OpenAIHeldCall#

FieldType
idstring
requestOpenAIRequest

OpenAISessionCalls#

type OpenAISessionCalls = OpenAICall[];

OpenAISessionToolCalls#

type OpenAISessionToolCalls = OpenAIToolCall[];

OpenAIProblems#

type OpenAIProblems = string[];

OpenAISentSecrets#

type OpenAISentSecrets = OpenAISentSecret[];

OpenAISentSecret#

FieldType
callstring
kindsstring[]

OpenAIUnattributedCalls#

type OpenAIUnattributedCalls = OpenAIUnattributedCall[];

OpenAIUnattributedCall#

FieldPython / RustType
ididstring
endpointendpointOpenAIEndpoint
modelmodelstring
atatstring
lastUserTextlast_user_textstring | undefined
toolstoolsstring[]
sinceMssince_msnumber
messagemessagestring

This page is generated from the control API's routes by codegen/src/emit/docs.ts: suggest changes there.