runs.d.ts 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. import { APIResource } from "../../../../resource.js";
  2. import { APIPromise } from "../../../../core.js";
  3. import * as Core from "../../../../core.js";
  4. import { AssistantStream, RunCreateParamsBaseStream } from "../../../../lib/AssistantStream.js";
  5. import { RunSubmitToolOutputsParamsStream } from "../../../../lib/AssistantStream.js";
  6. import * as RunsAPI from "./runs.js";
  7. import * as Shared from "../../../shared.js";
  8. import * as AssistantsAPI from "../../assistants.js";
  9. import * as MessagesAPI from "../messages.js";
  10. import * as ThreadsAPI from "../threads.js";
  11. import * as StepsAPI from "./steps.js";
  12. import { CodeInterpreterLogs, CodeInterpreterOutputImage, CodeInterpreterToolCall, CodeInterpreterToolCallDelta, FileSearchToolCall, FileSearchToolCallDelta, FunctionToolCall, FunctionToolCallDelta, MessageCreationStepDetails, RunStep, RunStepDelta, RunStepDeltaEvent, RunStepDeltaMessageDelta, RunStepInclude, RunStepsPage, StepListParams, StepRetrieveParams, Steps, ToolCall, ToolCallDelta, ToolCallDeltaObject, ToolCallsStepDetails } from "./steps.js";
  13. import { CursorPage, type CursorPageParams } from "../../../../pagination.js";
  14. import { Stream } from "../../../../streaming.js";
  15. /**
  16. * @deprecated The Assistants API is deprecated in favor of the Responses API
  17. */
  18. export declare class Runs extends APIResource {
  19. steps: StepsAPI.Steps;
  20. /**
  21. * Create a run.
  22. *
  23. * @deprecated The Assistants API is deprecated in favor of the Responses API
  24. */
  25. create(threadId: string, params: RunCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Run>;
  26. create(threadId: string, params: RunCreateParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;
  27. create(threadId: string, params: RunCreateParamsBase, options?: Core.RequestOptions): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | Run>;
  28. /**
  29. * Retrieves a run.
  30. *
  31. * @deprecated The Assistants API is deprecated in favor of the Responses API
  32. */
  33. retrieve(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise<Run>;
  34. /**
  35. * Modifies a run.
  36. *
  37. * @deprecated The Assistants API is deprecated in favor of the Responses API
  38. */
  39. update(threadId: string, runId: string, body: RunUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Run>;
  40. /**
  41. * Returns a list of runs belonging to a thread.
  42. *
  43. * @deprecated The Assistants API is deprecated in favor of the Responses API
  44. */
  45. list(threadId: string, query?: RunListParams, options?: Core.RequestOptions): Core.PagePromise<RunsPage, Run>;
  46. list(threadId: string, options?: Core.RequestOptions): Core.PagePromise<RunsPage, Run>;
  47. /**
  48. * Cancels a run that is `in_progress`.
  49. *
  50. * @deprecated The Assistants API is deprecated in favor of the Responses API
  51. */
  52. cancel(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise<Run>;
  53. /**
  54. * A helper to create a run an poll for a terminal state. More information on Run
  55. * lifecycles can be found here:
  56. * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
  57. */
  58. createAndPoll(threadId: string, body: RunCreateParamsNonStreaming, options?: Core.RequestOptions & {
  59. pollIntervalMs?: number;
  60. }): Promise<Run>;
  61. /**
  62. * Create a Run stream
  63. *
  64. * @deprecated use `stream` instead
  65. */
  66. createAndStream(threadId: string, body: RunCreateParamsBaseStream, options?: Core.RequestOptions): AssistantStream;
  67. /**
  68. * A helper to poll a run status until it reaches a terminal state. More
  69. * information on Run lifecycles can be found here:
  70. * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
  71. */
  72. poll(threadId: string, runId: string, options?: Core.RequestOptions & {
  73. pollIntervalMs?: number;
  74. }): Promise<Run>;
  75. /**
  76. * Create a Run stream
  77. */
  78. stream(threadId: string, body: RunCreateParamsBaseStream, options?: Core.RequestOptions): AssistantStream;
  79. /**
  80. * When a run has the `status: "requires_action"` and `required_action.type` is
  81. * `submit_tool_outputs`, this endpoint can be used to submit the outputs from the
  82. * tool calls once they're all completed. All outputs must be submitted in a single
  83. * request.
  84. *
  85. * @deprecated The Assistants API is deprecated in favor of the Responses API
  86. */
  87. submitToolOutputs(threadId: string, runId: string, body: RunSubmitToolOutputsParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Run>;
  88. submitToolOutputs(threadId: string, runId: string, body: RunSubmitToolOutputsParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;
  89. submitToolOutputs(threadId: string, runId: string, body: RunSubmitToolOutputsParamsBase, options?: Core.RequestOptions): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | Run>;
  90. /**
  91. * A helper to submit a tool output to a run and poll for a terminal run state.
  92. * More information on Run lifecycles can be found here:
  93. * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
  94. */
  95. submitToolOutputsAndPoll(threadId: string, runId: string, body: RunSubmitToolOutputsParamsNonStreaming, options?: Core.RequestOptions & {
  96. pollIntervalMs?: number;
  97. }): Promise<Run>;
  98. /**
  99. * Submit the tool outputs from a previous run and stream the run to a terminal
  100. * state. More information on Run lifecycles can be found here:
  101. * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
  102. */
  103. submitToolOutputsStream(threadId: string, runId: string, body: RunSubmitToolOutputsParamsStream, options?: Core.RequestOptions): AssistantStream;
  104. }
  105. export declare class RunsPage extends CursorPage<Run> {
  106. }
  107. /**
  108. * Tool call objects
  109. */
  110. export interface RequiredActionFunctionToolCall {
  111. /**
  112. * The ID of the tool call. This ID must be referenced when you submit the tool
  113. * outputs in using the
  114. * [Submit tool outputs to run](https://platform.openai.com/docs/api-reference/runs/submitToolOutputs)
  115. * endpoint.
  116. */
  117. id: string;
  118. /**
  119. * The function definition.
  120. */
  121. function: RequiredActionFunctionToolCall.Function;
  122. /**
  123. * The type of tool call the output is required for. For now, this is always
  124. * `function`.
  125. */
  126. type: 'function';
  127. }
  128. export declare namespace RequiredActionFunctionToolCall {
  129. /**
  130. * The function definition.
  131. */
  132. interface Function {
  133. /**
  134. * The arguments that the model expects you to pass to the function.
  135. */
  136. arguments: string;
  137. /**
  138. * The name of the function.
  139. */
  140. name: string;
  141. }
  142. }
  143. /**
  144. * Represents an execution run on a
  145. * [thread](https://platform.openai.com/docs/api-reference/threads).
  146. */
  147. export interface Run {
  148. /**
  149. * The identifier, which can be referenced in API endpoints.
  150. */
  151. id: string;
  152. /**
  153. * The ID of the
  154. * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
  155. * execution of this run.
  156. */
  157. assistant_id: string;
  158. /**
  159. * The Unix timestamp (in seconds) for when the run was cancelled.
  160. */
  161. cancelled_at: number | null;
  162. /**
  163. * The Unix timestamp (in seconds) for when the run was completed.
  164. */
  165. completed_at: number | null;
  166. /**
  167. * The Unix timestamp (in seconds) for when the run was created.
  168. */
  169. created_at: number;
  170. /**
  171. * The Unix timestamp (in seconds) for when the run will expire.
  172. */
  173. expires_at: number | null;
  174. /**
  175. * The Unix timestamp (in seconds) for when the run failed.
  176. */
  177. failed_at: number | null;
  178. /**
  179. * Details on why the run is incomplete. Will be `null` if the run is not
  180. * incomplete.
  181. */
  182. incomplete_details: Run.IncompleteDetails | null;
  183. /**
  184. * The instructions that the
  185. * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
  186. * this run.
  187. */
  188. instructions: string;
  189. /**
  190. * The last error associated with this run. Will be `null` if there are no errors.
  191. */
  192. last_error: Run.LastError | null;
  193. /**
  194. * The maximum number of completion tokens specified to have been used over the
  195. * course of the run.
  196. */
  197. max_completion_tokens: number | null;
  198. /**
  199. * The maximum number of prompt tokens specified to have been used over the course
  200. * of the run.
  201. */
  202. max_prompt_tokens: number | null;
  203. /**
  204. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  205. * for storing additional information about the object in a structured format, and
  206. * querying for objects via API or the dashboard.
  207. *
  208. * Keys are strings with a maximum length of 64 characters. Values are strings with
  209. * a maximum length of 512 characters.
  210. */
  211. metadata: Shared.Metadata | null;
  212. /**
  213. * The model that the
  214. * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
  215. * this run.
  216. */
  217. model: string;
  218. /**
  219. * The object type, which is always `thread.run`.
  220. */
  221. object: 'thread.run';
  222. /**
  223. * Whether to enable
  224. * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
  225. * during tool use.
  226. */
  227. parallel_tool_calls: boolean;
  228. /**
  229. * Details on the action required to continue the run. Will be `null` if no action
  230. * is required.
  231. */
  232. required_action: Run.RequiredAction | null;
  233. /**
  234. * Specifies the format that the model must output. Compatible with
  235. * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
  236. * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
  237. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  238. *
  239. * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
  240. * Outputs which ensures the model will match your supplied JSON schema. Learn more
  241. * in the
  242. * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
  243. *
  244. * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
  245. * message the model generates is valid JSON.
  246. *
  247. * **Important:** when using JSON mode, you **must** also instruct the model to
  248. * produce JSON yourself via a system or user message. Without this, the model may
  249. * generate an unending stream of whitespace until the generation reaches the token
  250. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  251. * the message content may be partially cut off if `finish_reason="length"`, which
  252. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  253. * max context length.
  254. */
  255. response_format: ThreadsAPI.AssistantResponseFormatOption | null;
  256. /**
  257. * The Unix timestamp (in seconds) for when the run was started.
  258. */
  259. started_at: number | null;
  260. /**
  261. * The status of the run, which can be either `queued`, `in_progress`,
  262. * `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,
  263. * `incomplete`, or `expired`.
  264. */
  265. status: RunStatus;
  266. /**
  267. * The ID of the [thread](https://platform.openai.com/docs/api-reference/threads)
  268. * that was executed on as a part of this run.
  269. */
  270. thread_id: string;
  271. /**
  272. * Controls which (if any) tool is called by the model. `none` means the model will
  273. * not call any tools and instead generates a message. `auto` is the default value
  274. * and means the model can pick between generating a message or calling one or more
  275. * tools. `required` means the model must call one or more tools before responding
  276. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  277. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  278. * call that tool.
  279. */
  280. tool_choice: ThreadsAPI.AssistantToolChoiceOption | null;
  281. /**
  282. * The list of tools that the
  283. * [assistant](https://platform.openai.com/docs/api-reference/assistants) used for
  284. * this run.
  285. */
  286. tools: Array<AssistantsAPI.AssistantTool>;
  287. /**
  288. * Controls for how a thread will be truncated prior to the run. Use this to
  289. * control the intial context window of the run.
  290. */
  291. truncation_strategy: Run.TruncationStrategy | null;
  292. /**
  293. * Usage statistics related to the run. This value will be `null` if the run is not
  294. * in a terminal state (i.e. `in_progress`, `queued`, etc.).
  295. */
  296. usage: Run.Usage | null;
  297. /**
  298. * The sampling temperature used for this run. If not set, defaults to 1.
  299. */
  300. temperature?: number | null;
  301. /**
  302. * The nucleus sampling value used for this run. If not set, defaults to 1.
  303. */
  304. top_p?: number | null;
  305. }
  306. export declare namespace Run {
  307. /**
  308. * Details on why the run is incomplete. Will be `null` if the run is not
  309. * incomplete.
  310. */
  311. interface IncompleteDetails {
  312. /**
  313. * The reason why the run is incomplete. This will point to which specific token
  314. * limit was reached over the course of the run.
  315. */
  316. reason?: 'max_completion_tokens' | 'max_prompt_tokens';
  317. }
  318. /**
  319. * The last error associated with this run. Will be `null` if there are no errors.
  320. */
  321. interface LastError {
  322. /**
  323. * One of `server_error`, `rate_limit_exceeded`, or `invalid_prompt`.
  324. */
  325. code: 'server_error' | 'rate_limit_exceeded' | 'invalid_prompt';
  326. /**
  327. * A human-readable description of the error.
  328. */
  329. message: string;
  330. }
  331. /**
  332. * Details on the action required to continue the run. Will be `null` if no action
  333. * is required.
  334. */
  335. interface RequiredAction {
  336. /**
  337. * Details on the tool outputs needed for this run to continue.
  338. */
  339. submit_tool_outputs: RequiredAction.SubmitToolOutputs;
  340. /**
  341. * For now, this is always `submit_tool_outputs`.
  342. */
  343. type: 'submit_tool_outputs';
  344. }
  345. namespace RequiredAction {
  346. /**
  347. * Details on the tool outputs needed for this run to continue.
  348. */
  349. interface SubmitToolOutputs {
  350. /**
  351. * A list of the relevant tool calls.
  352. */
  353. tool_calls: Array<RunsAPI.RequiredActionFunctionToolCall>;
  354. }
  355. }
  356. /**
  357. * Controls for how a thread will be truncated prior to the run. Use this to
  358. * control the intial context window of the run.
  359. */
  360. interface TruncationStrategy {
  361. /**
  362. * The truncation strategy to use for the thread. The default is `auto`. If set to
  363. * `last_messages`, the thread will be truncated to the n most recent messages in
  364. * the thread. When set to `auto`, messages in the middle of the thread will be
  365. * dropped to fit the context length of the model, `max_prompt_tokens`.
  366. */
  367. type: 'auto' | 'last_messages';
  368. /**
  369. * The number of most recent messages from the thread when constructing the context
  370. * for the run.
  371. */
  372. last_messages?: number | null;
  373. }
  374. /**
  375. * Usage statistics related to the run. This value will be `null` if the run is not
  376. * in a terminal state (i.e. `in_progress`, `queued`, etc.).
  377. */
  378. interface Usage {
  379. /**
  380. * Number of completion tokens used over the course of the run.
  381. */
  382. completion_tokens: number;
  383. /**
  384. * Number of prompt tokens used over the course of the run.
  385. */
  386. prompt_tokens: number;
  387. /**
  388. * Total number of tokens used (prompt + completion).
  389. */
  390. total_tokens: number;
  391. }
  392. }
  393. /**
  394. * The status of the run, which can be either `queued`, `in_progress`,
  395. * `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`,
  396. * `incomplete`, or `expired`.
  397. */
  398. export type RunStatus = 'queued' | 'in_progress' | 'requires_action' | 'cancelling' | 'cancelled' | 'failed' | 'completed' | 'incomplete' | 'expired';
  399. export type RunCreateParams = RunCreateParamsNonStreaming | RunCreateParamsStreaming;
  400. export interface RunCreateParamsBase {
  401. /**
  402. * Body param: The ID of the
  403. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  404. * execute this run.
  405. */
  406. assistant_id: string;
  407. /**
  408. * Query param: A list of additional fields to include in the response. Currently
  409. * the only supported value is
  410. * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file
  411. * search result content.
  412. *
  413. * See the
  414. * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
  415. * for more information.
  416. */
  417. include?: Array<StepsAPI.RunStepInclude>;
  418. /**
  419. * Body param: Appends additional instructions at the end of the instructions for
  420. * the run. This is useful for modifying the behavior on a per-run basis without
  421. * overriding other instructions.
  422. */
  423. additional_instructions?: string | null;
  424. /**
  425. * Body param: Adds additional messages to the thread before creating the run.
  426. */
  427. additional_messages?: Array<RunCreateParams.AdditionalMessage> | null;
  428. /**
  429. * Body param: Overrides the
  430. * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
  431. * of the assistant. This is useful for modifying the behavior on a per-run basis.
  432. */
  433. instructions?: string | null;
  434. /**
  435. * Body param: The maximum number of completion tokens that may be used over the
  436. * course of the run. The run will make a best effort to use only the number of
  437. * completion tokens specified, across multiple turns of the run. If the run
  438. * exceeds the number of completion tokens specified, the run will end with status
  439. * `incomplete`. See `incomplete_details` for more info.
  440. */
  441. max_completion_tokens?: number | null;
  442. /**
  443. * Body param: The maximum number of prompt tokens that may be used over the course
  444. * of the run. The run will make a best effort to use only the number of prompt
  445. * tokens specified, across multiple turns of the run. If the run exceeds the
  446. * number of prompt tokens specified, the run will end with status `incomplete`.
  447. * See `incomplete_details` for more info.
  448. */
  449. max_prompt_tokens?: number | null;
  450. /**
  451. * Body param: Set of 16 key-value pairs that can be attached to an object. This
  452. * can be useful for storing additional information about the object in a
  453. * structured format, and querying for objects via API or the dashboard.
  454. *
  455. * Keys are strings with a maximum length of 64 characters. Values are strings with
  456. * a maximum length of 512 characters.
  457. */
  458. metadata?: Shared.Metadata | null;
  459. /**
  460. * Body param: The ID of the
  461. * [Model](https://platform.openai.com/docs/api-reference/models) to be used to
  462. * execute this run. If a value is provided here, it will override the model
  463. * associated with the assistant. If not, the model associated with the assistant
  464. * will be used.
  465. */
  466. model?: (string & {}) | Shared.ChatModel | null;
  467. /**
  468. * Body param: Whether to enable
  469. * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
  470. * during tool use.
  471. */
  472. parallel_tool_calls?: boolean;
  473. /**
  474. * Body param: **o-series models only**
  475. *
  476. * Constrains effort on reasoning for
  477. * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
  478. * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
  479. * result in faster responses and fewer tokens used on reasoning in a response.
  480. */
  481. reasoning_effort?: Shared.ReasoningEffort | null;
  482. /**
  483. * Body param: Specifies the format that the model must output. Compatible with
  484. * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
  485. * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
  486. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  487. *
  488. * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
  489. * Outputs which ensures the model will match your supplied JSON schema. Learn more
  490. * in the
  491. * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
  492. *
  493. * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
  494. * message the model generates is valid JSON.
  495. *
  496. * **Important:** when using JSON mode, you **must** also instruct the model to
  497. * produce JSON yourself via a system or user message. Without this, the model may
  498. * generate an unending stream of whitespace until the generation reaches the token
  499. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  500. * the message content may be partially cut off if `finish_reason="length"`, which
  501. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  502. * max context length.
  503. */
  504. response_format?: ThreadsAPI.AssistantResponseFormatOption | null;
  505. /**
  506. * Body param: If `true`, returns a stream of events that happen during the Run as
  507. * server-sent events, terminating when the Run enters a terminal state with a
  508. * `data: [DONE]` message.
  509. */
  510. stream?: boolean | null;
  511. /**
  512. * Body param: What sampling temperature to use, between 0 and 2. Higher values
  513. * like 0.8 will make the output more random, while lower values like 0.2 will make
  514. * it more focused and deterministic.
  515. */
  516. temperature?: number | null;
  517. /**
  518. * Body param: Controls which (if any) tool is called by the model. `none` means
  519. * the model will not call any tools and instead generates a message. `auto` is the
  520. * default value and means the model can pick between generating a message or
  521. * calling one or more tools. `required` means the model must call one or more
  522. * tools before responding to the user. Specifying a particular tool like
  523. * `{"type": "file_search"}` or
  524. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  525. * call that tool.
  526. */
  527. tool_choice?: ThreadsAPI.AssistantToolChoiceOption | null;
  528. /**
  529. * Body param: Override the tools the assistant can use for this run. This is
  530. * useful for modifying the behavior on a per-run basis.
  531. */
  532. tools?: Array<AssistantsAPI.AssistantTool> | null;
  533. /**
  534. * Body param: An alternative to sampling with temperature, called nucleus
  535. * sampling, where the model considers the results of the tokens with top_p
  536. * probability mass. So 0.1 means only the tokens comprising the top 10%
  537. * probability mass are considered.
  538. *
  539. * We generally recommend altering this or temperature but not both.
  540. */
  541. top_p?: number | null;
  542. /**
  543. * Body param: Controls for how a thread will be truncated prior to the run. Use
  544. * this to control the intial context window of the run.
  545. */
  546. truncation_strategy?: RunCreateParams.TruncationStrategy | null;
  547. }
  548. export declare namespace RunCreateParams {
  549. interface AdditionalMessage {
  550. /**
  551. * The text contents of the message.
  552. */
  553. content: string | Array<MessagesAPI.MessageContentPartParam>;
  554. /**
  555. * The role of the entity that is creating the message. Allowed values include:
  556. *
  557. * - `user`: Indicates the message is sent by an actual user and should be used in
  558. * most cases to represent user-generated messages.
  559. * - `assistant`: Indicates the message is generated by the assistant. Use this
  560. * value to insert messages from the assistant into the conversation.
  561. */
  562. role: 'user' | 'assistant';
  563. /**
  564. * A list of files attached to the message, and the tools they should be added to.
  565. */
  566. attachments?: Array<AdditionalMessage.Attachment> | null;
  567. /**
  568. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  569. * for storing additional information about the object in a structured format, and
  570. * querying for objects via API or the dashboard.
  571. *
  572. * Keys are strings with a maximum length of 64 characters. Values are strings with
  573. * a maximum length of 512 characters.
  574. */
  575. metadata?: Shared.Metadata | null;
  576. }
  577. namespace AdditionalMessage {
  578. interface Attachment {
  579. /**
  580. * The ID of the file to attach to the message.
  581. */
  582. file_id?: string;
  583. /**
  584. * The tools to add this file to.
  585. */
  586. tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;
  587. }
  588. namespace Attachment {
  589. interface FileSearch {
  590. /**
  591. * The type of tool being defined: `file_search`
  592. */
  593. type: 'file_search';
  594. }
  595. }
  596. }
  597. /**
  598. * Controls for how a thread will be truncated prior to the run. Use this to
  599. * control the intial context window of the run.
  600. */
  601. interface TruncationStrategy {
  602. /**
  603. * The truncation strategy to use for the thread. The default is `auto`. If set to
  604. * `last_messages`, the thread will be truncated to the n most recent messages in
  605. * the thread. When set to `auto`, messages in the middle of the thread will be
  606. * dropped to fit the context length of the model, `max_prompt_tokens`.
  607. */
  608. type: 'auto' | 'last_messages';
  609. /**
  610. * The number of most recent messages from the thread when constructing the context
  611. * for the run.
  612. */
  613. last_messages?: number | null;
  614. }
  615. type RunCreateParamsNonStreaming = RunsAPI.RunCreateParamsNonStreaming;
  616. type RunCreateParamsStreaming = RunsAPI.RunCreateParamsStreaming;
  617. }
  618. export interface RunCreateParamsNonStreaming extends RunCreateParamsBase {
  619. /**
  620. * Body param: If `true`, returns a stream of events that happen during the Run as
  621. * server-sent events, terminating when the Run enters a terminal state with a
  622. * `data: [DONE]` message.
  623. */
  624. stream?: false | null;
  625. }
  626. export interface RunCreateParamsStreaming extends RunCreateParamsBase {
  627. /**
  628. * Body param: If `true`, returns a stream of events that happen during the Run as
  629. * server-sent events, terminating when the Run enters a terminal state with a
  630. * `data: [DONE]` message.
  631. */
  632. stream: true;
  633. }
  634. export interface RunUpdateParams {
  635. /**
  636. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  637. * for storing additional information about the object in a structured format, and
  638. * querying for objects via API or the dashboard.
  639. *
  640. * Keys are strings with a maximum length of 64 characters. Values are strings with
  641. * a maximum length of 512 characters.
  642. */
  643. metadata?: Shared.Metadata | null;
  644. }
  645. export interface RunListParams extends CursorPageParams {
  646. /**
  647. * A cursor for use in pagination. `before` is an object ID that defines your place
  648. * in the list. For instance, if you make a list request and receive 100 objects,
  649. * starting with obj_foo, your subsequent call can include before=obj_foo in order
  650. * to fetch the previous page of the list.
  651. */
  652. before?: string;
  653. /**
  654. * Sort order by the `created_at` timestamp of the objects. `asc` for ascending
  655. * order and `desc` for descending order.
  656. */
  657. order?: 'asc' | 'desc';
  658. }
  659. export interface RunCreateAndPollParams {
  660. /**
  661. * The ID of the
  662. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  663. * execute this run.
  664. */
  665. assistant_id: string;
  666. /**
  667. * Appends additional instructions at the end of the instructions for the run. This
  668. * is useful for modifying the behavior on a per-run basis without overriding other
  669. * instructions.
  670. */
  671. additional_instructions?: string | null;
  672. /**
  673. * Adds additional messages to the thread before creating the run.
  674. */
  675. additional_messages?: Array<RunCreateAndPollParams.AdditionalMessage> | null;
  676. /**
  677. * Overrides the
  678. * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
  679. * of the assistant. This is useful for modifying the behavior on a per-run basis.
  680. */
  681. instructions?: string | null;
  682. /**
  683. * The maximum number of completion tokens that may be used over the course of the
  684. * run. The run will make a best effort to use only the number of completion tokens
  685. * specified, across multiple turns of the run. If the run exceeds the number of
  686. * completion tokens specified, the run will end with status `incomplete`. See
  687. * `incomplete_details` for more info.
  688. */
  689. max_completion_tokens?: number | null;
  690. /**
  691. * The maximum number of prompt tokens that may be used over the course of the run.
  692. * The run will make a best effort to use only the number of prompt tokens
  693. * specified, across multiple turns of the run. If the run exceeds the number of
  694. * prompt tokens specified, the run will end with status `incomplete`. See
  695. * `incomplete_details` for more info.
  696. */
  697. max_prompt_tokens?: number | null;
  698. /**
  699. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  700. * for storing additional information about the object in a structured format. Keys
  701. * can be a maximum of 64 characters long and values can be a maxium of 512
  702. * characters long.
  703. */
  704. metadata?: unknown | null;
  705. /**
  706. * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
  707. * be used to execute this run. If a value is provided here, it will override the
  708. * model associated with the assistant. If not, the model associated with the
  709. * assistant will be used.
  710. */
  711. model?: (string & {}) | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613' | null;
  712. /**
  713. * Specifies the format that the model must output. Compatible with
  714. * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),
  715. * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),
  716. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  717. *
  718. * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
  719. * message the model generates is valid JSON.
  720. *
  721. * **Important:** when using JSON mode, you **must** also instruct the model to
  722. * produce JSON yourself via a system or user message. Without this, the model may
  723. * generate an unending stream of whitespace until the generation reaches the token
  724. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  725. * the message content may be partially cut off if `finish_reason="length"`, which
  726. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  727. * max context length.
  728. */
  729. response_format?: ThreadsAPI.AssistantResponseFormatOption | null;
  730. /**
  731. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  732. * make the output more random, while lower values like 0.2 will make it more
  733. * focused and deterministic.
  734. */
  735. temperature?: number | null;
  736. /**
  737. * Controls which (if any) tool is called by the model. `none` means the model will
  738. * not call any tools and instead generates a message. `auto` is the default value
  739. * and means the model can pick between generating a message or calling one or more
  740. * tools. `required` means the model must call one or more tools before responding
  741. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  742. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  743. * call that tool.
  744. */
  745. tool_choice?: ThreadsAPI.AssistantToolChoiceOption | null;
  746. /**
  747. * Override the tools the assistant can use for this run. This is useful for
  748. * modifying the behavior on a per-run basis.
  749. */
  750. tools?: Array<AssistantsAPI.AssistantTool> | null;
  751. /**
  752. * An alternative to sampling with temperature, called nucleus sampling, where the
  753. * model considers the results of the tokens with top_p probability mass. So 0.1
  754. * means only the tokens comprising the top 10% probability mass are considered.
  755. *
  756. * We generally recommend altering this or temperature but not both.
  757. */
  758. top_p?: number | null;
  759. /**
  760. * Controls for how a thread will be truncated prior to the run. Use this to
  761. * control the intial context window of the run.
  762. */
  763. truncation_strategy?: RunCreateAndPollParams.TruncationStrategy | null;
  764. }
  765. export declare namespace RunCreateAndPollParams {
  766. interface AdditionalMessage {
  767. /**
  768. * The text contents of the message.
  769. */
  770. content: string | Array<MessagesAPI.MessageContentPartParam>;
  771. /**
  772. * The role of the entity that is creating the message. Allowed values include:
  773. *
  774. * - `user`: Indicates the message is sent by an actual user and should be used in
  775. * most cases to represent user-generated messages.
  776. * - `assistant`: Indicates the message is generated by the assistant. Use this
  777. * value to insert messages from the assistant into the conversation.
  778. */
  779. role: 'user' | 'assistant';
  780. /**
  781. * A list of files attached to the message, and the tools they should be added to.
  782. */
  783. attachments?: Array<AdditionalMessage.Attachment> | null;
  784. /**
  785. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  786. * for storing additional information about the object in a structured format. Keys
  787. * can be a maximum of 64 characters long and values can be a maxium of 512
  788. * characters long.
  789. */
  790. metadata?: unknown | null;
  791. }
  792. namespace AdditionalMessage {
  793. interface Attachment {
  794. /**
  795. * The ID of the file to attach to the message.
  796. */
  797. file_id?: string;
  798. /**
  799. * The tools to add this file to.
  800. */
  801. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;
  802. }
  803. }
  804. /**
  805. * Controls for how a thread will be truncated prior to the run. Use this to
  806. * control the intial context window of the run.
  807. */
  808. interface TruncationStrategy {
  809. /**
  810. * The truncation strategy to use for the thread. The default is `auto`. If set to
  811. * `last_messages`, the thread will be truncated to the n most recent messages in
  812. * the thread. When set to `auto`, messages in the middle of the thread will be
  813. * dropped to fit the context length of the model, `max_prompt_tokens`.
  814. */
  815. type: 'auto' | 'last_messages';
  816. /**
  817. * The number of most recent messages from the thread when constructing the context
  818. * for the run.
  819. */
  820. last_messages?: number | null;
  821. }
  822. }
  823. export interface RunCreateAndStreamParams {
  824. /**
  825. * The ID of the
  826. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  827. * execute this run.
  828. */
  829. assistant_id: string;
  830. /**
  831. * Appends additional instructions at the end of the instructions for the run. This
  832. * is useful for modifying the behavior on a per-run basis without overriding other
  833. * instructions.
  834. */
  835. additional_instructions?: string | null;
  836. /**
  837. * Adds additional messages to the thread before creating the run.
  838. */
  839. additional_messages?: Array<RunCreateAndStreamParams.AdditionalMessage> | null;
  840. /**
  841. * Overrides the
  842. * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
  843. * of the assistant. This is useful for modifying the behavior on a per-run basis.
  844. */
  845. instructions?: string | null;
  846. /**
  847. * The maximum number of completion tokens that may be used over the course of the
  848. * run. The run will make a best effort to use only the number of completion tokens
  849. * specified, across multiple turns of the run. If the run exceeds the number of
  850. * completion tokens specified, the run will end with status `incomplete`. See
  851. * `incomplete_details` for more info.
  852. */
  853. max_completion_tokens?: number | null;
  854. /**
  855. * The maximum number of prompt tokens that may be used over the course of the run.
  856. * The run will make a best effort to use only the number of prompt tokens
  857. * specified, across multiple turns of the run. If the run exceeds the number of
  858. * prompt tokens specified, the run will end with status `incomplete`. See
  859. * `incomplete_details` for more info.
  860. */
  861. max_prompt_tokens?: number | null;
  862. /**
  863. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  864. * for storing additional information about the object in a structured format. Keys
  865. * can be a maximum of 64 characters long and values can be a maxium of 512
  866. * characters long.
  867. */
  868. metadata?: unknown | null;
  869. /**
  870. * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
  871. * be used to execute this run. If a value is provided here, it will override the
  872. * model associated with the assistant. If not, the model associated with the
  873. * assistant will be used.
  874. */
  875. model?: (string & {}) | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613' | null;
  876. /**
  877. * Specifies the format that the model must output. Compatible with
  878. * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),
  879. * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),
  880. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  881. *
  882. * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
  883. * message the model generates is valid JSON.
  884. *
  885. * **Important:** when using JSON mode, you **must** also instruct the model to
  886. * produce JSON yourself via a system or user message. Without this, the model may
  887. * generate an unending stream of whitespace until the generation reaches the token
  888. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  889. * the message content may be partially cut off if `finish_reason="length"`, which
  890. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  891. * max context length.
  892. */
  893. response_format?: ThreadsAPI.AssistantResponseFormatOption | null;
  894. /**
  895. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  896. * make the output more random, while lower values like 0.2 will make it more
  897. * focused and deterministic.
  898. */
  899. temperature?: number | null;
  900. /**
  901. * Controls which (if any) tool is called by the model. `none` means the model will
  902. * not call any tools and instead generates a message. `auto` is the default value
  903. * and means the model can pick between generating a message or calling one or more
  904. * tools. `required` means the model must call one or more tools before responding
  905. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  906. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  907. * call that tool.
  908. */
  909. tool_choice?: ThreadsAPI.AssistantToolChoiceOption | null;
  910. /**
  911. * Override the tools the assistant can use for this run. This is useful for
  912. * modifying the behavior on a per-run basis.
  913. */
  914. tools?: Array<AssistantsAPI.AssistantTool> | null;
  915. /**
  916. * An alternative to sampling with temperature, called nucleus sampling, where the
  917. * model considers the results of the tokens with top_p probability mass. So 0.1
  918. * means only the tokens comprising the top 10% probability mass are considered.
  919. *
  920. * We generally recommend altering this or temperature but not both.
  921. */
  922. top_p?: number | null;
  923. /**
  924. * Controls for how a thread will be truncated prior to the run. Use this to
  925. * control the intial context window of the run.
  926. */
  927. truncation_strategy?: RunCreateAndStreamParams.TruncationStrategy | null;
  928. }
  929. export declare namespace RunCreateAndStreamParams {
  930. interface AdditionalMessage {
  931. /**
  932. * The text contents of the message.
  933. */
  934. content: string | Array<MessagesAPI.MessageContentPartParam>;
  935. /**
  936. * The role of the entity that is creating the message. Allowed values include:
  937. *
  938. * - `user`: Indicates the message is sent by an actual user and should be used in
  939. * most cases to represent user-generated messages.
  940. * - `assistant`: Indicates the message is generated by the assistant. Use this
  941. * value to insert messages from the assistant into the conversation.
  942. */
  943. role: 'user' | 'assistant';
  944. /**
  945. * A list of files attached to the message, and the tools they should be added to.
  946. */
  947. attachments?: Array<AdditionalMessage.Attachment> | null;
  948. /**
  949. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  950. * for storing additional information about the object in a structured format. Keys
  951. * can be a maximum of 64 characters long and values can be a maxium of 512
  952. * characters long.
  953. */
  954. metadata?: unknown | null;
  955. }
  956. namespace AdditionalMessage {
  957. interface Attachment {
  958. /**
  959. * The ID of the file to attach to the message.
  960. */
  961. file_id?: string;
  962. /**
  963. * The tools to add this file to.
  964. */
  965. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;
  966. }
  967. }
  968. /**
  969. * Controls for how a thread will be truncated prior to the run. Use this to
  970. * control the intial context window of the run.
  971. */
  972. interface TruncationStrategy {
  973. /**
  974. * The truncation strategy to use for the thread. The default is `auto`. If set to
  975. * `last_messages`, the thread will be truncated to the n most recent messages in
  976. * the thread. When set to `auto`, messages in the middle of the thread will be
  977. * dropped to fit the context length of the model, `max_prompt_tokens`.
  978. */
  979. type: 'auto' | 'last_messages';
  980. /**
  981. * The number of most recent messages from the thread when constructing the context
  982. * for the run.
  983. */
  984. last_messages?: number | null;
  985. }
  986. }
  987. export interface RunStreamParams {
  988. /**
  989. * The ID of the
  990. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  991. * execute this run.
  992. */
  993. assistant_id: string;
  994. /**
  995. * Appends additional instructions at the end of the instructions for the run. This
  996. * is useful for modifying the behavior on a per-run basis without overriding other
  997. * instructions.
  998. */
  999. additional_instructions?: string | null;
  1000. /**
  1001. * Adds additional messages to the thread before creating the run.
  1002. */
  1003. additional_messages?: Array<RunStreamParams.AdditionalMessage> | null;
  1004. /**
  1005. * Overrides the
  1006. * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
  1007. * of the assistant. This is useful for modifying the behavior on a per-run basis.
  1008. */
  1009. instructions?: string | null;
  1010. /**
  1011. * The maximum number of completion tokens that may be used over the course of the
  1012. * run. The run will make a best effort to use only the number of completion tokens
  1013. * specified, across multiple turns of the run. If the run exceeds the number of
  1014. * completion tokens specified, the run will end with status `incomplete`. See
  1015. * `incomplete_details` for more info.
  1016. */
  1017. max_completion_tokens?: number | null;
  1018. /**
  1019. * The maximum number of prompt tokens that may be used over the course of the run.
  1020. * The run will make a best effort to use only the number of prompt tokens
  1021. * specified, across multiple turns of the run. If the run exceeds the number of
  1022. * prompt tokens specified, the run will end with status `incomplete`. See
  1023. * `incomplete_details` for more info.
  1024. */
  1025. max_prompt_tokens?: number | null;
  1026. /**
  1027. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1028. * for storing additional information about the object in a structured format. Keys
  1029. * can be a maximum of 64 characters long and values can be a maxium of 512
  1030. * characters long.
  1031. */
  1032. metadata?: unknown | null;
  1033. /**
  1034. * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
  1035. * be used to execute this run. If a value is provided here, it will override the
  1036. * model associated with the assistant. If not, the model associated with the
  1037. * assistant will be used.
  1038. */
  1039. model?: (string & {}) | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613' | null;
  1040. /**
  1041. * Specifies the format that the model must output. Compatible with
  1042. * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),
  1043. * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),
  1044. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  1045. *
  1046. * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
  1047. * message the model generates is valid JSON.
  1048. *
  1049. * **Important:** when using JSON mode, you **must** also instruct the model to
  1050. * produce JSON yourself via a system or user message. Without this, the model may
  1051. * generate an unending stream of whitespace until the generation reaches the token
  1052. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  1053. * the message content may be partially cut off if `finish_reason="length"`, which
  1054. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  1055. * max context length.
  1056. */
  1057. response_format?: ThreadsAPI.AssistantResponseFormatOption | null;
  1058. /**
  1059. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  1060. * make the output more random, while lower values like 0.2 will make it more
  1061. * focused and deterministic.
  1062. */
  1063. temperature?: number | null;
  1064. /**
  1065. * Controls which (if any) tool is called by the model. `none` means the model will
  1066. * not call any tools and instead generates a message. `auto` is the default value
  1067. * and means the model can pick between generating a message or calling one or more
  1068. * tools. `required` means the model must call one or more tools before responding
  1069. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  1070. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  1071. * call that tool.
  1072. */
  1073. tool_choice?: ThreadsAPI.AssistantToolChoiceOption | null;
  1074. /**
  1075. * Override the tools the assistant can use for this run. This is useful for
  1076. * modifying the behavior on a per-run basis.
  1077. */
  1078. tools?: Array<AssistantsAPI.AssistantTool> | null;
  1079. /**
  1080. * An alternative to sampling with temperature, called nucleus sampling, where the
  1081. * model considers the results of the tokens with top_p probability mass. So 0.1
  1082. * means only the tokens comprising the top 10% probability mass are considered.
  1083. *
  1084. * We generally recommend altering this or temperature but not both.
  1085. */
  1086. top_p?: number | null;
  1087. /**
  1088. * Controls for how a thread will be truncated prior to the run. Use this to
  1089. * control the intial context window of the run.
  1090. */
  1091. truncation_strategy?: RunStreamParams.TruncationStrategy | null;
  1092. }
  1093. export declare namespace RunStreamParams {
  1094. interface AdditionalMessage {
  1095. /**
  1096. * The text contents of the message.
  1097. */
  1098. content: string | Array<MessagesAPI.MessageContentPartParam>;
  1099. /**
  1100. * The role of the entity that is creating the message. Allowed values include:
  1101. *
  1102. * - `user`: Indicates the message is sent by an actual user and should be used in
  1103. * most cases to represent user-generated messages.
  1104. * - `assistant`: Indicates the message is generated by the assistant. Use this
  1105. * value to insert messages from the assistant into the conversation.
  1106. */
  1107. role: 'user' | 'assistant';
  1108. /**
  1109. * A list of files attached to the message, and the tools they should be added to.
  1110. */
  1111. attachments?: Array<AdditionalMessage.Attachment> | null;
  1112. /**
  1113. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1114. * for storing additional information about the object in a structured format. Keys
  1115. * can be a maximum of 64 characters long and values can be a maxium of 512
  1116. * characters long.
  1117. */
  1118. metadata?: unknown | null;
  1119. }
  1120. namespace AdditionalMessage {
  1121. interface Attachment {
  1122. /**
  1123. * The ID of the file to attach to the message.
  1124. */
  1125. file_id?: string;
  1126. /**
  1127. * The tools to add this file to.
  1128. */
  1129. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;
  1130. }
  1131. }
  1132. /**
  1133. * Controls for how a thread will be truncated prior to the run. Use this to
  1134. * control the intial context window of the run.
  1135. */
  1136. interface TruncationStrategy {
  1137. /**
  1138. * The truncation strategy to use for the thread. The default is `auto`. If set to
  1139. * `last_messages`, the thread will be truncated to the n most recent messages in
  1140. * the thread. When set to `auto`, messages in the middle of the thread will be
  1141. * dropped to fit the context length of the model, `max_prompt_tokens`.
  1142. */
  1143. type: 'auto' | 'last_messages';
  1144. /**
  1145. * The number of most recent messages from the thread when constructing the context
  1146. * for the run.
  1147. */
  1148. last_messages?: number | null;
  1149. }
  1150. }
  1151. export type RunSubmitToolOutputsParams = RunSubmitToolOutputsParamsNonStreaming | RunSubmitToolOutputsParamsStreaming;
  1152. export interface RunSubmitToolOutputsParamsBase {
  1153. /**
  1154. * A list of tools for which the outputs are being submitted.
  1155. */
  1156. tool_outputs: Array<RunSubmitToolOutputsParams.ToolOutput>;
  1157. /**
  1158. * If `true`, returns a stream of events that happen during the Run as server-sent
  1159. * events, terminating when the Run enters a terminal state with a `data: [DONE]`
  1160. * message.
  1161. */
  1162. stream?: boolean | null;
  1163. }
  1164. export declare namespace RunSubmitToolOutputsParams {
  1165. interface ToolOutput {
  1166. /**
  1167. * The output of the tool call to be submitted to continue the run.
  1168. */
  1169. output?: string;
  1170. /**
  1171. * The ID of the tool call in the `required_action` object within the run object
  1172. * the output is being submitted for.
  1173. */
  1174. tool_call_id?: string;
  1175. }
  1176. type RunSubmitToolOutputsParamsNonStreaming = RunsAPI.RunSubmitToolOutputsParamsNonStreaming;
  1177. type RunSubmitToolOutputsParamsStreaming = RunsAPI.RunSubmitToolOutputsParamsStreaming;
  1178. }
  1179. export interface RunSubmitToolOutputsParamsNonStreaming extends RunSubmitToolOutputsParamsBase {
  1180. /**
  1181. * If `true`, returns a stream of events that happen during the Run as server-sent
  1182. * events, terminating when the Run enters a terminal state with a `data: [DONE]`
  1183. * message.
  1184. */
  1185. stream?: false | null;
  1186. }
  1187. export interface RunSubmitToolOutputsParamsStreaming extends RunSubmitToolOutputsParamsBase {
  1188. /**
  1189. * If `true`, returns a stream of events that happen during the Run as server-sent
  1190. * events, terminating when the Run enters a terminal state with a `data: [DONE]`
  1191. * message.
  1192. */
  1193. stream: true;
  1194. }
  1195. export interface RunSubmitToolOutputsAndPollParams {
  1196. /**
  1197. * A list of tools for which the outputs are being submitted.
  1198. */
  1199. tool_outputs: Array<RunSubmitToolOutputsAndPollParams.ToolOutput>;
  1200. }
  1201. export declare namespace RunSubmitToolOutputsAndPollParams {
  1202. interface ToolOutput {
  1203. /**
  1204. * The output of the tool call to be submitted to continue the run.
  1205. */
  1206. output?: string;
  1207. /**
  1208. * The ID of the tool call in the `required_action` object within the run object
  1209. * the output is being submitted for.
  1210. */
  1211. tool_call_id?: string;
  1212. }
  1213. }
  1214. export interface RunSubmitToolOutputsStreamParams {
  1215. /**
  1216. * A list of tools for which the outputs are being submitted.
  1217. */
  1218. tool_outputs: Array<RunSubmitToolOutputsStreamParams.ToolOutput>;
  1219. }
  1220. export declare namespace RunSubmitToolOutputsStreamParams {
  1221. interface ToolOutput {
  1222. /**
  1223. * The output of the tool call to be submitted to continue the run.
  1224. */
  1225. output?: string;
  1226. /**
  1227. * The ID of the tool call in the `required_action` object within the run object
  1228. * the output is being submitted for.
  1229. */
  1230. tool_call_id?: string;
  1231. }
  1232. }
  1233. export declare namespace Runs {
  1234. export { type RequiredActionFunctionToolCall as RequiredActionFunctionToolCall, type Run as Run, type RunStatus as RunStatus, RunsPage as RunsPage, type RunCreateParams as RunCreateParams, type RunCreateParamsNonStreaming as RunCreateParamsNonStreaming, type RunCreateParamsStreaming as RunCreateParamsStreaming, type RunUpdateParams as RunUpdateParams, type RunListParams as RunListParams, type RunCreateAndPollParams, type RunCreateAndStreamParams, type RunStreamParams, type RunSubmitToolOutputsParams as RunSubmitToolOutputsParams, type RunSubmitToolOutputsParamsNonStreaming as RunSubmitToolOutputsParamsNonStreaming, type RunSubmitToolOutputsParamsStreaming as RunSubmitToolOutputsParamsStreaming, type RunSubmitToolOutputsAndPollParams, type RunSubmitToolOutputsStreamParams, };
  1235. export { Steps as Steps, type CodeInterpreterLogs as CodeInterpreterLogs, type CodeInterpreterOutputImage as CodeInterpreterOutputImage, type CodeInterpreterToolCall as CodeInterpreterToolCall, type CodeInterpreterToolCallDelta as CodeInterpreterToolCallDelta, type FileSearchToolCall as FileSearchToolCall, type FileSearchToolCallDelta as FileSearchToolCallDelta, type FunctionToolCall as FunctionToolCall, type FunctionToolCallDelta as FunctionToolCallDelta, type MessageCreationStepDetails as MessageCreationStepDetails, type RunStep as RunStep, type RunStepDelta as RunStepDelta, type RunStepDeltaEvent as RunStepDeltaEvent, type RunStepDeltaMessageDelta as RunStepDeltaMessageDelta, type RunStepInclude as RunStepInclude, type ToolCall as ToolCall, type ToolCallDelta as ToolCallDelta, type ToolCallDeltaObject as ToolCallDeltaObject, type ToolCallsStepDetails as ToolCallsStepDetails, RunStepsPage as RunStepsPage, type StepRetrieveParams as StepRetrieveParams, type StepListParams as StepListParams, };
  1236. }
  1237. //# sourceMappingURL=runs.d.ts.map