completions.d.ts 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. import { APIResource } from "../../../resource.js";
  2. import { APIPromise } from "../../../core.js";
  3. import * as Core from "../../../core.js";
  4. import * as CompletionsCompletionsAPI from "./completions.js";
  5. import * as CompletionsAPI from "../../completions.js";
  6. import * as Shared from "../../shared.js";
  7. import * as MessagesAPI from "./messages.js";
  8. import { MessageListParams, Messages } from "./messages.js";
  9. import { CursorPage, type CursorPageParams } from "../../../pagination.js";
  10. import { Stream } from "../../../streaming.js";
  11. export declare class Completions extends APIResource {
  12. messages: MessagesAPI.Messages;
  13. /**
  14. * **Starting a new project?** We recommend trying
  15. * [Responses](https://platform.openai.com/docs/api-reference/responses) to take
  16. * advantage of the latest OpenAI platform features. Compare
  17. * [Chat Completions with Responses](https://platform.openai.com/docs/guides/responses-vs-chat-completions?api-mode=responses).
  18. *
  19. * ---
  20. *
  21. * Creates a model response for the given chat conversation. Learn more in the
  22. * [text generation](https://platform.openai.com/docs/guides/text-generation),
  23. * [vision](https://platform.openai.com/docs/guides/vision), and
  24. * [audio](https://platform.openai.com/docs/guides/audio) guides.
  25. *
  26. * Parameter support can differ depending on the model used to generate the
  27. * response, particularly for newer reasoning models. Parameters that are only
  28. * supported for reasoning models are noted below. For the current state of
  29. * unsupported parameters in reasoning models,
  30. * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
  31. *
  32. * @example
  33. * ```ts
  34. * const chatCompletion = await client.chat.completions.create(
  35. * {
  36. * messages: [{ content: 'string', role: 'developer' }],
  37. * model: 'gpt-4o',
  38. * },
  39. * );
  40. * ```
  41. */
  42. create(body: ChatCompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<ChatCompletion>;
  43. create(body: ChatCompletionCreateParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<ChatCompletionChunk>>;
  44. create(body: ChatCompletionCreateParamsBase, options?: Core.RequestOptions): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
  45. /**
  46. * Get a stored chat completion. Only Chat Completions that have been created with
  47. * the `store` parameter set to `true` will be returned.
  48. *
  49. * @example
  50. * ```ts
  51. * const chatCompletion =
  52. * await client.chat.completions.retrieve('completion_id');
  53. * ```
  54. */
  55. retrieve(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletion>;
  56. /**
  57. * Modify a stored chat completion. Only Chat Completions that have been created
  58. * with the `store` parameter set to `true` can be modified. Currently, the only
  59. * supported modification is to update the `metadata` field.
  60. *
  61. * @example
  62. * ```ts
  63. * const chatCompletion = await client.chat.completions.update(
  64. * 'completion_id',
  65. * { metadata: { foo: 'string' } },
  66. * );
  67. * ```
  68. */
  69. update(completionId: string, body: ChatCompletionUpdateParams, options?: Core.RequestOptions): Core.APIPromise<ChatCompletion>;
  70. /**
  71. * List stored Chat Completions. Only Chat Completions that have been stored with
  72. * the `store` parameter set to `true` will be returned.
  73. *
  74. * @example
  75. * ```ts
  76. * // Automatically fetches more pages as needed.
  77. * for await (const chatCompletion of client.chat.completions.list()) {
  78. * // ...
  79. * }
  80. * ```
  81. */
  82. list(query?: ChatCompletionListParams, options?: Core.RequestOptions): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
  83. list(options?: Core.RequestOptions): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
  84. /**
  85. * Delete a stored chat completion. Only Chat Completions that have been created
  86. * with the `store` parameter set to `true` can be deleted.
  87. *
  88. * @example
  89. * ```ts
  90. * const chatCompletionDeleted =
  91. * await client.chat.completions.del('completion_id');
  92. * ```
  93. */
  94. del(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletionDeleted>;
  95. }
  96. export declare class ChatCompletionsPage extends CursorPage<ChatCompletion> {
  97. }
  98. export declare class ChatCompletionStoreMessagesPage extends CursorPage<ChatCompletionStoreMessage> {
  99. }
  100. /**
  101. * Represents a chat completion response returned by model, based on the provided
  102. * input.
  103. */
  104. export interface ChatCompletion {
  105. /**
  106. * A unique identifier for the chat completion.
  107. */
  108. id: string;
  109. /**
  110. * A list of chat completion choices. Can be more than one if `n` is greater
  111. * than 1.
  112. */
  113. choices: Array<ChatCompletion.Choice>;
  114. /**
  115. * The Unix timestamp (in seconds) of when the chat completion was created.
  116. */
  117. created: number;
  118. /**
  119. * The model used for the chat completion.
  120. */
  121. model: string;
  122. /**
  123. * The object type, which is always `chat.completion`.
  124. */
  125. object: 'chat.completion';
  126. /**
  127. * Specifies the latency tier to use for processing the request. This parameter is
  128. * relevant for customers subscribed to the scale tier service:
  129. *
  130. * - If set to 'auto', and the Project is Scale tier enabled, the system will
  131. * utilize scale tier credits until they are exhausted.
  132. * - If set to 'auto', and the Project is not Scale tier enabled, the request will
  133. * be processed using the default service tier with a lower uptime SLA and no
  134. * latency guarentee.
  135. * - If set to 'default', the request will be processed using the default service
  136. * tier with a lower uptime SLA and no latency guarentee.
  137. * - If set to 'flex', the request will be processed with the Flex Processing
  138. * service tier.
  139. * [Learn more](https://platform.openai.com/docs/guides/flex-processing).
  140. * - When not set, the default behavior is 'auto'.
  141. *
  142. * When this parameter is set, the response body will include the `service_tier`
  143. * utilized.
  144. */
  145. service_tier?: 'auto' | 'default' | 'flex' | null;
  146. /**
  147. * This fingerprint represents the backend configuration that the model runs with.
  148. *
  149. * Can be used in conjunction with the `seed` request parameter to understand when
  150. * backend changes have been made that might impact determinism.
  151. */
  152. system_fingerprint?: string;
  153. /**
  154. * Usage statistics for the completion request.
  155. */
  156. usage?: CompletionsAPI.CompletionUsage;
  157. }
  158. export declare namespace ChatCompletion {
  159. interface Choice {
  160. /**
  161. * The reason the model stopped generating tokens. This will be `stop` if the model
  162. * hit a natural stop point or a provided stop sequence, `length` if the maximum
  163. * number of tokens specified in the request was reached, `content_filter` if
  164. * content was omitted due to a flag from our content filters, `tool_calls` if the
  165. * model called a tool, or `function_call` (deprecated) if the model called a
  166. * function.
  167. */
  168. finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
  169. /**
  170. * The index of the choice in the list of choices.
  171. */
  172. index: number;
  173. /**
  174. * Log probability information for the choice.
  175. */
  176. logprobs: Choice.Logprobs | null;
  177. /**
  178. * A chat completion message generated by the model.
  179. */
  180. message: CompletionsCompletionsAPI.ChatCompletionMessage;
  181. }
  182. namespace Choice {
  183. /**
  184. * Log probability information for the choice.
  185. */
  186. interface Logprobs {
  187. /**
  188. * A list of message content tokens with log probability information.
  189. */
  190. content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
  191. /**
  192. * A list of message refusal tokens with log probability information.
  193. */
  194. refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
  195. }
  196. }
  197. }
  198. /**
  199. * Messages sent by the model in response to user messages.
  200. */
  201. export interface ChatCompletionAssistantMessageParam {
  202. /**
  203. * The role of the messages author, in this case `assistant`.
  204. */
  205. role: 'assistant';
  206. /**
  207. * Data about a previous audio response from the model.
  208. * [Learn more](https://platform.openai.com/docs/guides/audio).
  209. */
  210. audio?: ChatCompletionAssistantMessageParam.Audio | null;
  211. /**
  212. * The contents of the assistant message. Required unless `tool_calls` or
  213. * `function_call` is specified.
  214. */
  215. content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
  216. /**
  217. * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
  218. * function that should be called, as generated by the model.
  219. */
  220. function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
  221. /**
  222. * An optional name for the participant. Provides the model information to
  223. * differentiate between participants of the same role.
  224. */
  225. name?: string;
  226. /**
  227. * The refusal message by the assistant.
  228. */
  229. refusal?: string | null;
  230. /**
  231. * The tool calls generated by the model, such as function calls.
  232. */
  233. tool_calls?: Array<ChatCompletionMessageToolCall>;
  234. }
  235. export declare namespace ChatCompletionAssistantMessageParam {
  236. /**
  237. * Data about a previous audio response from the model.
  238. * [Learn more](https://platform.openai.com/docs/guides/audio).
  239. */
  240. interface Audio {
  241. /**
  242. * Unique identifier for a previous audio response from the model.
  243. */
  244. id: string;
  245. }
  246. /**
  247. * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
  248. * function that should be called, as generated by the model.
  249. */
  250. interface FunctionCall {
  251. /**
  252. * The arguments to call the function with, as generated by the model in JSON
  253. * format. Note that the model does not always generate valid JSON, and may
  254. * hallucinate parameters not defined by your function schema. Validate the
  255. * arguments in your code before calling your function.
  256. */
  257. arguments: string;
  258. /**
  259. * The name of the function to call.
  260. */
  261. name: string;
  262. }
  263. }
  264. /**
  265. * If the audio output modality is requested, this object contains data about the
  266. * audio response from the model.
  267. * [Learn more](https://platform.openai.com/docs/guides/audio).
  268. */
  269. export interface ChatCompletionAudio {
  270. /**
  271. * Unique identifier for this audio response.
  272. */
  273. id: string;
  274. /**
  275. * Base64 encoded audio bytes generated by the model, in the format specified in
  276. * the request.
  277. */
  278. data: string;
  279. /**
  280. * The Unix timestamp (in seconds) for when this audio response will no longer be
  281. * accessible on the server for use in multi-turn conversations.
  282. */
  283. expires_at: number;
  284. /**
  285. * Transcript of the audio generated by the model.
  286. */
  287. transcript: string;
  288. }
  289. /**
  290. * Parameters for audio output. Required when audio output is requested with
  291. * `modalities: ["audio"]`.
  292. * [Learn more](https://platform.openai.com/docs/guides/audio).
  293. */
  294. export interface ChatCompletionAudioParam {
  295. /**
  296. * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
  297. * or `pcm16`.
  298. */
  299. format: 'wav' | 'aac' | 'mp3' | 'flac' | 'opus' | 'pcm16';
  300. /**
  301. * The voice the model uses to respond. Supported voices are `alloy`, `ash`,
  302. * `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`.
  303. */
  304. voice: (string & {}) | 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'fable' | 'onyx' | 'nova' | 'sage' | 'shimmer' | 'verse';
  305. }
  306. /**
  307. * Represents a streamed chunk of a chat completion response returned by the model,
  308. * based on the provided input.
  309. * [Learn more](https://platform.openai.com/docs/guides/streaming-responses).
  310. */
  311. export interface ChatCompletionChunk {
  312. /**
  313. * A unique identifier for the chat completion. Each chunk has the same ID.
  314. */
  315. id: string;
  316. /**
  317. * A list of chat completion choices. Can contain more than one elements if `n` is
  318. * greater than 1. Can also be empty for the last chunk if you set
  319. * `stream_options: {"include_usage": true}`.
  320. */
  321. choices: Array<ChatCompletionChunk.Choice>;
  322. /**
  323. * The Unix timestamp (in seconds) of when the chat completion was created. Each
  324. * chunk has the same timestamp.
  325. */
  326. created: number;
  327. /**
  328. * The model to generate the completion.
  329. */
  330. model: string;
  331. /**
  332. * The object type, which is always `chat.completion.chunk`.
  333. */
  334. object: 'chat.completion.chunk';
  335. /**
  336. * Specifies the latency tier to use for processing the request. This parameter is
  337. * relevant for customers subscribed to the scale tier service:
  338. *
  339. * - If set to 'auto', and the Project is Scale tier enabled, the system will
  340. * utilize scale tier credits until they are exhausted.
  341. * - If set to 'auto', and the Project is not Scale tier enabled, the request will
  342. * be processed using the default service tier with a lower uptime SLA and no
  343. * latency guarentee.
  344. * - If set to 'default', the request will be processed using the default service
  345. * tier with a lower uptime SLA and no latency guarentee.
  346. * - If set to 'flex', the request will be processed with the Flex Processing
  347. * service tier.
  348. * [Learn more](https://platform.openai.com/docs/guides/flex-processing).
  349. * - When not set, the default behavior is 'auto'.
  350. *
  351. * When this parameter is set, the response body will include the `service_tier`
  352. * utilized.
  353. */
  354. service_tier?: 'auto' | 'default' | 'flex' | null;
  355. /**
  356. * This fingerprint represents the backend configuration that the model runs with.
  357. * Can be used in conjunction with the `seed` request parameter to understand when
  358. * backend changes have been made that might impact determinism.
  359. */
  360. system_fingerprint?: string;
  361. /**
  362. * An optional field that will only be present when you set
  363. * `stream_options: {"include_usage": true}` in your request. When present, it
  364. * contains a null value **except for the last chunk** which contains the token
  365. * usage statistics for the entire request.
  366. *
  367. * **NOTE:** If the stream is interrupted or cancelled, you may not receive the
  368. * final usage chunk which contains the total token usage for the request.
  369. */
  370. usage?: CompletionsAPI.CompletionUsage | null;
  371. }
  372. export declare namespace ChatCompletionChunk {
  373. interface Choice {
  374. /**
  375. * A chat completion delta generated by streamed model responses.
  376. */
  377. delta: Choice.Delta;
  378. /**
  379. * The reason the model stopped generating tokens. This will be `stop` if the model
  380. * hit a natural stop point or a provided stop sequence, `length` if the maximum
  381. * number of tokens specified in the request was reached, `content_filter` if
  382. * content was omitted due to a flag from our content filters, `tool_calls` if the
  383. * model called a tool, or `function_call` (deprecated) if the model called a
  384. * function.
  385. */
  386. finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
  387. /**
  388. * The index of the choice in the list of choices.
  389. */
  390. index: number;
  391. /**
  392. * Log probability information for the choice.
  393. */
  394. logprobs?: Choice.Logprobs | null;
  395. }
  396. namespace Choice {
  397. /**
  398. * A chat completion delta generated by streamed model responses.
  399. */
  400. interface Delta {
  401. /**
  402. * The contents of the chunk message.
  403. */
  404. content?: string | null;
  405. /**
  406. * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
  407. * function that should be called, as generated by the model.
  408. */
  409. function_call?: Delta.FunctionCall;
  410. /**
  411. * The refusal message generated by the model.
  412. */
  413. refusal?: string | null;
  414. /**
  415. * The role of the author of this message.
  416. */
  417. role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
  418. tool_calls?: Array<Delta.ToolCall>;
  419. }
  420. namespace Delta {
  421. /**
  422. * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
  423. * function that should be called, as generated by the model.
  424. */
  425. interface FunctionCall {
  426. /**
  427. * The arguments to call the function with, as generated by the model in JSON
  428. * format. Note that the model does not always generate valid JSON, and may
  429. * hallucinate parameters not defined by your function schema. Validate the
  430. * arguments in your code before calling your function.
  431. */
  432. arguments?: string;
  433. /**
  434. * The name of the function to call.
  435. */
  436. name?: string;
  437. }
  438. interface ToolCall {
  439. index: number;
  440. /**
  441. * The ID of the tool call.
  442. */
  443. id?: string;
  444. function?: ToolCall.Function;
  445. /**
  446. * The type of the tool. Currently, only `function` is supported.
  447. */
  448. type?: 'function';
  449. }
  450. namespace ToolCall {
  451. interface Function {
  452. /**
  453. * The arguments to call the function with, as generated by the model in JSON
  454. * format. Note that the model does not always generate valid JSON, and may
  455. * hallucinate parameters not defined by your function schema. Validate the
  456. * arguments in your code before calling your function.
  457. */
  458. arguments?: string;
  459. /**
  460. * The name of the function to call.
  461. */
  462. name?: string;
  463. }
  464. }
  465. }
  466. /**
  467. * Log probability information for the choice.
  468. */
  469. interface Logprobs {
  470. /**
  471. * A list of message content tokens with log probability information.
  472. */
  473. content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
  474. /**
  475. * A list of message refusal tokens with log probability information.
  476. */
  477. refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
  478. }
  479. }
  480. }
  481. /**
  482. * Learn about
  483. * [text inputs](https://platform.openai.com/docs/guides/text-generation).
  484. */
  485. export type ChatCompletionContentPart = ChatCompletionContentPartText | ChatCompletionContentPartImage | ChatCompletionContentPartInputAudio | ChatCompletionContentPart.File;
  486. export declare namespace ChatCompletionContentPart {
  487. /**
  488. * Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
  489. * generation.
  490. */
  491. interface File {
  492. file: File.File;
  493. /**
  494. * The type of the content part. Always `file`.
  495. */
  496. type: 'file';
  497. }
  498. namespace File {
  499. interface File {
  500. /**
  501. * The base64 encoded file data, used when passing the file to the model as a
  502. * string.
  503. */
  504. file_data?: string;
  505. /**
  506. * The ID of an uploaded file to use as input.
  507. */
  508. file_id?: string;
  509. /**
  510. * The name of the file, used when passing the file to the model as a string.
  511. */
  512. filename?: string;
  513. }
  514. }
  515. }
  516. /**
  517. * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
  518. */
  519. export interface ChatCompletionContentPartImage {
  520. image_url: ChatCompletionContentPartImage.ImageURL;
  521. /**
  522. * The type of the content part.
  523. */
  524. type: 'image_url';
  525. }
  526. export declare namespace ChatCompletionContentPartImage {
  527. interface ImageURL {
  528. /**
  529. * Either a URL of the image or the base64 encoded image data.
  530. */
  531. url: string;
  532. /**
  533. * Specifies the detail level of the image. Learn more in the
  534. * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
  535. */
  536. detail?: 'auto' | 'low' | 'high';
  537. }
  538. }
  539. /**
  540. * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
  541. */
  542. export interface ChatCompletionContentPartInputAudio {
  543. input_audio: ChatCompletionContentPartInputAudio.InputAudio;
  544. /**
  545. * The type of the content part. Always `input_audio`.
  546. */
  547. type: 'input_audio';
  548. }
  549. export declare namespace ChatCompletionContentPartInputAudio {
  550. interface InputAudio {
  551. /**
  552. * Base64 encoded audio data.
  553. */
  554. data: string;
  555. /**
  556. * The format of the encoded audio data. Currently supports "wav" and "mp3".
  557. */
  558. format: 'wav' | 'mp3';
  559. }
  560. }
  561. export interface ChatCompletionContentPartRefusal {
  562. /**
  563. * The refusal message generated by the model.
  564. */
  565. refusal: string;
  566. /**
  567. * The type of the content part.
  568. */
  569. type: 'refusal';
  570. }
  571. /**
  572. * Learn about
  573. * [text inputs](https://platform.openai.com/docs/guides/text-generation).
  574. */
  575. export interface ChatCompletionContentPartText {
  576. /**
  577. * The text content.
  578. */
  579. text: string;
  580. /**
  581. * The type of the content part.
  582. */
  583. type: 'text';
  584. }
  585. export interface ChatCompletionDeleted {
  586. /**
  587. * The ID of the chat completion that was deleted.
  588. */
  589. id: string;
  590. /**
  591. * Whether the chat completion was deleted.
  592. */
  593. deleted: boolean;
  594. /**
  595. * The type of object being deleted.
  596. */
  597. object: 'chat.completion.deleted';
  598. }
  599. /**
  600. * Developer-provided instructions that the model should follow, regardless of
  601. * messages sent by the user. With o1 models and newer, `developer` messages
  602. * replace the previous `system` messages.
  603. */
  604. export interface ChatCompletionDeveloperMessageParam {
  605. /**
  606. * The contents of the developer message.
  607. */
  608. content: string | Array<ChatCompletionContentPartText>;
  609. /**
  610. * The role of the messages author, in this case `developer`.
  611. */
  612. role: 'developer';
  613. /**
  614. * An optional name for the participant. Provides the model information to
  615. * differentiate between participants of the same role.
  616. */
  617. name?: string;
  618. }
  619. /**
  620. * Specifying a particular function via `{"name": "my_function"}` forces the model
  621. * to call that function.
  622. */
  623. export interface ChatCompletionFunctionCallOption {
  624. /**
  625. * The name of the function to call.
  626. */
  627. name: string;
  628. }
  629. /**
  630. * @deprecated
  631. */
  632. export interface ChatCompletionFunctionMessageParam {
  633. /**
  634. * The contents of the function message.
  635. */
  636. content: string | null;
  637. /**
  638. * The name of the function to call.
  639. */
  640. name: string;
  641. /**
  642. * The role of the messages author, in this case `function`.
  643. */
  644. role: 'function';
  645. }
  646. /**
  647. * A chat completion message generated by the model.
  648. */
  649. export interface ChatCompletionMessage {
  650. /**
  651. * The contents of the message.
  652. */
  653. content: string | null;
  654. /**
  655. * The refusal message generated by the model.
  656. */
  657. refusal: string | null;
  658. /**
  659. * The role of the author of this message.
  660. */
  661. role: 'assistant';
  662. /**
  663. * Annotations for the message, when applicable, as when using the
  664. * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
  665. */
  666. annotations?: Array<ChatCompletionMessage.Annotation>;
  667. /**
  668. * If the audio output modality is requested, this object contains data about the
  669. * audio response from the model.
  670. * [Learn more](https://platform.openai.com/docs/guides/audio).
  671. */
  672. audio?: ChatCompletionAudio | null;
  673. /**
  674. * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
  675. * function that should be called, as generated by the model.
  676. */
  677. function_call?: ChatCompletionMessage.FunctionCall | null;
  678. /**
  679. * The tool calls generated by the model, such as function calls.
  680. */
  681. tool_calls?: Array<ChatCompletionMessageToolCall>;
  682. }
  683. export declare namespace ChatCompletionMessage {
  684. /**
  685. * A URL citation when using web search.
  686. */
  687. interface Annotation {
  688. /**
  689. * The type of the URL citation. Always `url_citation`.
  690. */
  691. type: 'url_citation';
  692. /**
  693. * A URL citation when using web search.
  694. */
  695. url_citation: Annotation.URLCitation;
  696. }
  697. namespace Annotation {
  698. /**
  699. * A URL citation when using web search.
  700. */
  701. interface URLCitation {
  702. /**
  703. * The index of the last character of the URL citation in the message.
  704. */
  705. end_index: number;
  706. /**
  707. * The index of the first character of the URL citation in the message.
  708. */
  709. start_index: number;
  710. /**
  711. * The title of the web resource.
  712. */
  713. title: string;
  714. /**
  715. * The URL of the web resource.
  716. */
  717. url: string;
  718. }
  719. }
  720. /**
  721. * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
  722. * function that should be called, as generated by the model.
  723. */
  724. interface FunctionCall {
  725. /**
  726. * The arguments to call the function with, as generated by the model in JSON
  727. * format. Note that the model does not always generate valid JSON, and may
  728. * hallucinate parameters not defined by your function schema. Validate the
  729. * arguments in your code before calling your function.
  730. */
  731. arguments: string;
  732. /**
  733. * The name of the function to call.
  734. */
  735. name: string;
  736. }
  737. }
  738. /**
  739. * Developer-provided instructions that the model should follow, regardless of
  740. * messages sent by the user. With o1 models and newer, `developer` messages
  741. * replace the previous `system` messages.
  742. */
  743. export type ChatCompletionMessageParam = ChatCompletionDeveloperMessageParam | ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam;
  744. export interface ChatCompletionMessageToolCall {
  745. /**
  746. * The ID of the tool call.
  747. */
  748. id: string;
  749. /**
  750. * The function that the model called.
  751. */
  752. function: ChatCompletionMessageToolCall.Function;
  753. /**
  754. * The type of the tool. Currently, only `function` is supported.
  755. */
  756. type: 'function';
  757. }
  758. export declare namespace ChatCompletionMessageToolCall {
  759. /**
  760. * The function that the model called.
  761. */
  762. interface Function {
  763. /**
  764. * The arguments to call the function with, as generated by the model in JSON
  765. * format. Note that the model does not always generate valid JSON, and may
  766. * hallucinate parameters not defined by your function schema. Validate the
  767. * arguments in your code before calling your function.
  768. */
  769. arguments: string;
  770. /**
  771. * The name of the function to call.
  772. */
  773. name: string;
  774. }
  775. }
  776. export type ChatCompletionModality = 'text' | 'audio';
  777. /**
  778. * Specifies a tool the model should use. Use to force the model to call a specific
  779. * function.
  780. */
  781. export interface ChatCompletionNamedToolChoice {
  782. function: ChatCompletionNamedToolChoice.Function;
  783. /**
  784. * The type of the tool. Currently, only `function` is supported.
  785. */
  786. type: 'function';
  787. }
  788. export declare namespace ChatCompletionNamedToolChoice {
  789. interface Function {
  790. /**
  791. * The name of the function to call.
  792. */
  793. name: string;
  794. }
  795. }
  796. /**
  797. * Static predicted output content, such as the content of a text file that is
  798. * being regenerated.
  799. */
  800. export interface ChatCompletionPredictionContent {
  801. /**
  802. * The content that should be matched when generating a model response. If
  803. * generated tokens would match this content, the entire model response can be
  804. * returned much more quickly.
  805. */
  806. content: string | Array<ChatCompletionContentPartText>;
  807. /**
  808. * The type of the predicted content you want to provide. This type is currently
  809. * always `content`.
  810. */
  811. type: 'content';
  812. }
  813. /**
  814. * The role of the author of a message
  815. */
  816. export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
  817. /**
  818. * A chat completion message generated by the model.
  819. */
  820. export interface ChatCompletionStoreMessage extends ChatCompletionMessage {
  821. /**
  822. * The identifier of the chat message.
  823. */
  824. id: string;
  825. }
  826. /**
  827. * Options for streaming response. Only set this when you set `stream: true`.
  828. */
  829. export interface ChatCompletionStreamOptions {
  830. /**
  831. * If set, an additional chunk will be streamed before the `data: [DONE]` message.
  832. * The `usage` field on this chunk shows the token usage statistics for the entire
  833. * request, and the `choices` field will always be an empty array.
  834. *
  835. * All other chunks will also include a `usage` field, but with a null value.
  836. * **NOTE:** If the stream is interrupted, you may not receive the final usage
  837. * chunk which contains the total token usage for the request.
  838. */
  839. include_usage?: boolean;
  840. }
  841. /**
  842. * Developer-provided instructions that the model should follow, regardless of
  843. * messages sent by the user. With o1 models and newer, use `developer` messages
  844. * for this purpose instead.
  845. */
  846. export interface ChatCompletionSystemMessageParam {
  847. /**
  848. * The contents of the system message.
  849. */
  850. content: string | Array<ChatCompletionContentPartText>;
  851. /**
  852. * The role of the messages author, in this case `system`.
  853. */
  854. role: 'system';
  855. /**
  856. * An optional name for the participant. Provides the model information to
  857. * differentiate between participants of the same role.
  858. */
  859. name?: string;
  860. }
  861. export interface ChatCompletionTokenLogprob {
  862. /**
  863. * The token.
  864. */
  865. token: string;
  866. /**
  867. * A list of integers representing the UTF-8 bytes representation of the token.
  868. * Useful in instances where characters are represented by multiple tokens and
  869. * their byte representations must be combined to generate the correct text
  870. * representation. Can be `null` if there is no bytes representation for the token.
  871. */
  872. bytes: Array<number> | null;
  873. /**
  874. * The log probability of this token, if it is within the top 20 most likely
  875. * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
  876. * unlikely.
  877. */
  878. logprob: number;
  879. /**
  880. * List of the most likely tokens and their log probability, at this token
  881. * position. In rare cases, there may be fewer than the number of requested
  882. * `top_logprobs` returned.
  883. */
  884. top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
  885. }
  886. export declare namespace ChatCompletionTokenLogprob {
  887. interface TopLogprob {
  888. /**
  889. * The token.
  890. */
  891. token: string;
  892. /**
  893. * A list of integers representing the UTF-8 bytes representation of the token.
  894. * Useful in instances where characters are represented by multiple tokens and
  895. * their byte representations must be combined to generate the correct text
  896. * representation. Can be `null` if there is no bytes representation for the token.
  897. */
  898. bytes: Array<number> | null;
  899. /**
  900. * The log probability of this token, if it is within the top 20 most likely
  901. * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
  902. * unlikely.
  903. */
  904. logprob: number;
  905. }
  906. }
  907. export interface ChatCompletionTool {
  908. function: Shared.FunctionDefinition;
  909. /**
  910. * The type of the tool. Currently, only `function` is supported.
  911. */
  912. type: 'function';
  913. }
  914. /**
  915. * Controls which (if any) tool is called by the model. `none` means the model will
  916. * not call any tool and instead generates a message. `auto` means the model can
  917. * pick between generating a message or calling one or more tools. `required` means
  918. * the model must call one or more tools. Specifying a particular tool via
  919. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  920. * call that tool.
  921. *
  922. * `none` is the default when no tools are present. `auto` is the default if tools
  923. * are present.
  924. */
  925. export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
  926. export interface ChatCompletionToolMessageParam {
  927. /**
  928. * The contents of the tool message.
  929. */
  930. content: string | Array<ChatCompletionContentPartText>;
  931. /**
  932. * The role of the messages author, in this case `tool`.
  933. */
  934. role: 'tool';
  935. /**
  936. * Tool call that this message is responding to.
  937. */
  938. tool_call_id: string;
  939. }
  940. /**
  941. * Messages sent by an end user, containing prompts or additional context
  942. * information.
  943. */
  944. export interface ChatCompletionUserMessageParam {
  945. /**
  946. * The contents of the user message.
  947. */
  948. content: string | Array<ChatCompletionContentPart>;
  949. /**
  950. * The role of the messages author, in this case `user`.
  951. */
  952. role: 'user';
  953. /**
  954. * An optional name for the participant. Provides the model information to
  955. * differentiate between participants of the same role.
  956. */
  957. name?: string;
  958. }
  959. /**
  960. * @deprecated ChatCompletionMessageParam should be used instead
  961. */
  962. export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
  963. export type ChatCompletionReasoningEffort = Shared.ReasoningEffort | null;
  964. export type ChatCompletionCreateParams = ChatCompletionCreateParamsNonStreaming | ChatCompletionCreateParamsStreaming;
  965. export interface ChatCompletionCreateParamsBase {
  966. /**
  967. * A list of messages comprising the conversation so far. Depending on the
  968. * [model](https://platform.openai.com/docs/models) you use, different message
  969. * types (modalities) are supported, like
  970. * [text](https://platform.openai.com/docs/guides/text-generation),
  971. * [images](https://platform.openai.com/docs/guides/vision), and
  972. * [audio](https://platform.openai.com/docs/guides/audio).
  973. */
  974. messages: Array<ChatCompletionMessageParam>;
  975. /**
  976. * Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
  977. * wide range of models with different capabilities, performance characteristics,
  978. * and price points. Refer to the
  979. * [model guide](https://platform.openai.com/docs/models) to browse and compare
  980. * available models.
  981. */
  982. model: (string & {}) | Shared.ChatModel;
  983. /**
  984. * Parameters for audio output. Required when audio output is requested with
  985. * `modalities: ["audio"]`.
  986. * [Learn more](https://platform.openai.com/docs/guides/audio).
  987. */
  988. audio?: ChatCompletionAudioParam | null;
  989. /**
  990. * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
  991. * existing frequency in the text so far, decreasing the model's likelihood to
  992. * repeat the same line verbatim.
  993. */
  994. frequency_penalty?: number | null;
  995. /**
  996. * @deprecated Deprecated in favor of `tool_choice`.
  997. *
  998. * Controls which (if any) function is called by the model.
  999. *
  1000. * `none` means the model will not call a function and instead generates a message.
  1001. *
  1002. * `auto` means the model can pick between generating a message or calling a
  1003. * function.
  1004. *
  1005. * Specifying a particular function via `{"name": "my_function"}` forces the model
  1006. * to call that function.
  1007. *
  1008. * `none` is the default when no functions are present. `auto` is the default if
  1009. * functions are present.
  1010. */
  1011. function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
  1012. /**
  1013. * @deprecated Deprecated in favor of `tools`.
  1014. *
  1015. * A list of functions the model may generate JSON inputs for.
  1016. */
  1017. functions?: Array<ChatCompletionCreateParams.Function>;
  1018. /**
  1019. * Modify the likelihood of specified tokens appearing in the completion.
  1020. *
  1021. * Accepts a JSON object that maps tokens (specified by their token ID in the
  1022. * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
  1023. * bias is added to the logits generated by the model prior to sampling. The exact
  1024. * effect will vary per model, but values between -1 and 1 should decrease or
  1025. * increase likelihood of selection; values like -100 or 100 should result in a ban
  1026. * or exclusive selection of the relevant token.
  1027. */
  1028. logit_bias?: Record<string, number> | null;
  1029. /**
  1030. * Whether to return log probabilities of the output tokens or not. If true,
  1031. * returns the log probabilities of each output token returned in the `content` of
  1032. * `message`.
  1033. */
  1034. logprobs?: boolean | null;
  1035. /**
  1036. * An upper bound for the number of tokens that can be generated for a completion,
  1037. * including visible output tokens and
  1038. * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
  1039. */
  1040. max_completion_tokens?: number | null;
  1041. /**
  1042. * @deprecated The maximum number of [tokens](/tokenizer) that can be generated in
  1043. * the chat completion. This value can be used to control
  1044. * [costs](https://openai.com/api/pricing/) for text generated via API.
  1045. *
  1046. * This value is now deprecated in favor of `max_completion_tokens`, and is not
  1047. * compatible with
  1048. * [o-series models](https://platform.openai.com/docs/guides/reasoning).
  1049. */
  1050. max_tokens?: number | null;
  1051. /**
  1052. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1053. * for storing additional information about the object in a structured format, and
  1054. * querying for objects via API or the dashboard.
  1055. *
  1056. * Keys are strings with a maximum length of 64 characters. Values are strings with
  1057. * a maximum length of 512 characters.
  1058. */
  1059. metadata?: Shared.Metadata | null;
  1060. /**
  1061. * Output types that you would like the model to generate. Most models are capable
  1062. * of generating text, which is the default:
  1063. *
  1064. * `["text"]`
  1065. *
  1066. * The `gpt-4o-audio-preview` model can also be used to
  1067. * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
  1068. * this model generate both text and audio responses, you can use:
  1069. *
  1070. * `["text", "audio"]`
  1071. */
  1072. modalities?: Array<'text' | 'audio'> | null;
  1073. /**
  1074. * How many chat completion choices to generate for each input message. Note that
  1075. * you will be charged based on the number of generated tokens across all of the
  1076. * choices. Keep `n` as `1` to minimize costs.
  1077. */
  1078. n?: number | null;
  1079. /**
  1080. * Whether to enable
  1081. * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
  1082. * during tool use.
  1083. */
  1084. parallel_tool_calls?: boolean;
  1085. /**
  1086. * Static predicted output content, such as the content of a text file that is
  1087. * being regenerated.
  1088. */
  1089. prediction?: ChatCompletionPredictionContent | null;
  1090. /**
  1091. * Number between -2.0 and 2.0. Positive values penalize new tokens based on
  1092. * whether they appear in the text so far, increasing the model's likelihood to
  1093. * talk about new topics.
  1094. */
  1095. presence_penalty?: number | null;
  1096. /**
  1097. * **o-series models only**
  1098. *
  1099. * Constrains effort on reasoning for
  1100. * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
  1101. * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
  1102. * result in faster responses and fewer tokens used on reasoning in a response.
  1103. */
  1104. reasoning_effort?: Shared.ReasoningEffort | null;
  1105. /**
  1106. * An object specifying the format that the model must output.
  1107. *
  1108. * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
  1109. * Outputs which ensures the model will match your supplied JSON schema. Learn more
  1110. * in the
  1111. * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
  1112. *
  1113. * Setting to `{ "type": "json_object" }` enables the older JSON mode, which
  1114. * ensures the message the model generates is valid JSON. Using `json_schema` is
  1115. * preferred for models that support it.
  1116. */
  1117. response_format?: Shared.ResponseFormatText | Shared.ResponseFormatJSONSchema | Shared.ResponseFormatJSONObject;
  1118. /**
  1119. * This feature is in Beta. If specified, our system will make a best effort to
  1120. * sample deterministically, such that repeated requests with the same `seed` and
  1121. * parameters should return the same result. Determinism is not guaranteed, and you
  1122. * should refer to the `system_fingerprint` response parameter to monitor changes
  1123. * in the backend.
  1124. */
  1125. seed?: number | null;
  1126. /**
  1127. * Specifies the latency tier to use for processing the request. This parameter is
  1128. * relevant for customers subscribed to the scale tier service:
  1129. *
  1130. * - If set to 'auto', and the Project is Scale tier enabled, the system will
  1131. * utilize scale tier credits until they are exhausted.
  1132. * - If set to 'auto', and the Project is not Scale tier enabled, the request will
  1133. * be processed using the default service tier with a lower uptime SLA and no
  1134. * latency guarentee.
  1135. * - If set to 'default', the request will be processed using the default service
  1136. * tier with a lower uptime SLA and no latency guarentee.
  1137. * - If set to 'flex', the request will be processed with the Flex Processing
  1138. * service tier.
  1139. * [Learn more](https://platform.openai.com/docs/guides/flex-processing).
  1140. * - When not set, the default behavior is 'auto'.
  1141. *
  1142. * When this parameter is set, the response body will include the `service_tier`
  1143. * utilized.
  1144. */
  1145. service_tier?: 'auto' | 'default' | 'flex' | null;
  1146. /**
  1147. * Not supported with latest reasoning models `o3` and `o4-mini`.
  1148. *
  1149. * Up to 4 sequences where the API will stop generating further tokens. The
  1150. * returned text will not contain the stop sequence.
  1151. */
  1152. stop?: string | null | Array<string>;
  1153. /**
  1154. * Whether or not to store the output of this chat completion request for use in
  1155. * our [model distillation](https://platform.openai.com/docs/guides/distillation)
  1156. * or [evals](https://platform.openai.com/docs/guides/evals) products.
  1157. */
  1158. store?: boolean | null;
  1159. /**
  1160. * If set to true, the model response data will be streamed to the client as it is
  1161. * generated using
  1162. * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  1163. * See the
  1164. * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)
  1165. * for more information, along with the
  1166. * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)
  1167. * guide for more information on how to handle the streaming events.
  1168. */
  1169. stream?: boolean | null;
  1170. /**
  1171. * Options for streaming response. Only set this when you set `stream: true`.
  1172. */
  1173. stream_options?: ChatCompletionStreamOptions | null;
  1174. /**
  1175. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  1176. * make the output more random, while lower values like 0.2 will make it more
  1177. * focused and deterministic. We generally recommend altering this or `top_p` but
  1178. * not both.
  1179. */
  1180. temperature?: number | null;
  1181. /**
  1182. * Controls which (if any) tool is called by the model. `none` means the model will
  1183. * not call any tool and instead generates a message. `auto` means the model can
  1184. * pick between generating a message or calling one or more tools. `required` means
  1185. * the model must call one or more tools. Specifying a particular tool via
  1186. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  1187. * call that tool.
  1188. *
  1189. * `none` is the default when no tools are present. `auto` is the default if tools
  1190. * are present.
  1191. */
  1192. tool_choice?: ChatCompletionToolChoiceOption;
  1193. /**
  1194. * A list of tools the model may call. Currently, only functions are supported as a
  1195. * tool. Use this to provide a list of functions the model may generate JSON inputs
  1196. * for. A max of 128 functions are supported.
  1197. */
  1198. tools?: Array<ChatCompletionTool>;
  1199. /**
  1200. * An integer between 0 and 20 specifying the number of most likely tokens to
  1201. * return at each token position, each with an associated log probability.
  1202. * `logprobs` must be set to `true` if this parameter is used.
  1203. */
  1204. top_logprobs?: number | null;
  1205. /**
  1206. * An alternative to sampling with temperature, called nucleus sampling, where the
  1207. * model considers the results of the tokens with top_p probability mass. So 0.1
  1208. * means only the tokens comprising the top 10% probability mass are considered.
  1209. *
  1210. * We generally recommend altering this or `temperature` but not both.
  1211. */
  1212. top_p?: number | null;
  1213. /**
  1214. * A stable identifier for your end-users. Used to boost cache hit rates by better
  1215. * bucketing similar requests and to help OpenAI detect and prevent abuse.
  1216. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
  1217. */
  1218. user?: string;
  1219. /**
  1220. * This tool searches the web for relevant results to use in a response. Learn more
  1221. * about the
  1222. * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
  1223. */
  1224. web_search_options?: ChatCompletionCreateParams.WebSearchOptions;
  1225. }
  1226. export declare namespace ChatCompletionCreateParams {
  1227. /**
  1228. * @deprecated
  1229. */
  1230. interface Function {
  1231. /**
  1232. * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
  1233. * underscores and dashes, with a maximum length of 64.
  1234. */
  1235. name: string;
  1236. /**
  1237. * A description of what the function does, used by the model to choose when and
  1238. * how to call the function.
  1239. */
  1240. description?: string;
  1241. /**
  1242. * The parameters the functions accepts, described as a JSON Schema object. See the
  1243. * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
  1244. * and the
  1245. * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
  1246. * documentation about the format.
  1247. *
  1248. * Omitting `parameters` defines a function with an empty parameter list.
  1249. */
  1250. parameters?: Shared.FunctionParameters;
  1251. }
  1252. /**
  1253. * This tool searches the web for relevant results to use in a response. Learn more
  1254. * about the
  1255. * [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
  1256. */
  1257. interface WebSearchOptions {
  1258. /**
  1259. * High level guidance for the amount of context window space to use for the
  1260. * search. One of `low`, `medium`, or `high`. `medium` is the default.
  1261. */
  1262. search_context_size?: 'low' | 'medium' | 'high';
  1263. /**
  1264. * Approximate location parameters for the search.
  1265. */
  1266. user_location?: WebSearchOptions.UserLocation | null;
  1267. }
  1268. namespace WebSearchOptions {
  1269. /**
  1270. * Approximate location parameters for the search.
  1271. */
  1272. interface UserLocation {
  1273. /**
  1274. * Approximate location parameters for the search.
  1275. */
  1276. approximate: UserLocation.Approximate;
  1277. /**
  1278. * The type of location approximation. Always `approximate`.
  1279. */
  1280. type: 'approximate';
  1281. }
  1282. namespace UserLocation {
  1283. /**
  1284. * Approximate location parameters for the search.
  1285. */
  1286. interface Approximate {
  1287. /**
  1288. * Free text input for the city of the user, e.g. `San Francisco`.
  1289. */
  1290. city?: string;
  1291. /**
  1292. * The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of
  1293. * the user, e.g. `US`.
  1294. */
  1295. country?: string;
  1296. /**
  1297. * Free text input for the region of the user, e.g. `California`.
  1298. */
  1299. region?: string;
  1300. /**
  1301. * The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the
  1302. * user, e.g. `America/Los_Angeles`.
  1303. */
  1304. timezone?: string;
  1305. }
  1306. }
  1307. }
  1308. type ChatCompletionCreateParamsNonStreaming = CompletionsCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
  1309. type ChatCompletionCreateParamsStreaming = CompletionsCompletionsAPI.ChatCompletionCreateParamsStreaming;
  1310. }
  1311. /**
  1312. * @deprecated Use ChatCompletionCreateParams instead
  1313. */
  1314. export type CompletionCreateParams = ChatCompletionCreateParams;
  1315. export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
  1316. /**
  1317. * If set to true, the model response data will be streamed to the client as it is
  1318. * generated using
  1319. * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  1320. * See the
  1321. * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)
  1322. * for more information, along with the
  1323. * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)
  1324. * guide for more information on how to handle the streaming events.
  1325. */
  1326. stream?: false | null;
  1327. }
  1328. /**
  1329. * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
  1330. */
  1331. export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
  1332. export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
  1333. /**
  1334. * If set to true, the model response data will be streamed to the client as it is
  1335. * generated using
  1336. * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
  1337. * See the
  1338. * [Streaming section below](https://platform.openai.com/docs/api-reference/chat/streaming)
  1339. * for more information, along with the
  1340. * [streaming responses](https://platform.openai.com/docs/guides/streaming-responses)
  1341. * guide for more information on how to handle the streaming events.
  1342. */
  1343. stream: true;
  1344. }
  1345. /**
  1346. * @deprecated Use ChatCompletionCreateParamsStreaming instead
  1347. */
  1348. export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
  1349. export interface ChatCompletionUpdateParams {
  1350. /**
  1351. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1352. * for storing additional information about the object in a structured format, and
  1353. * querying for objects via API or the dashboard.
  1354. *
  1355. * Keys are strings with a maximum length of 64 characters. Values are strings with
  1356. * a maximum length of 512 characters.
  1357. */
  1358. metadata: Shared.Metadata | null;
  1359. }
  1360. /**
  1361. * @deprecated Use ChatCompletionUpdateParams instead
  1362. */
  1363. export type CompletionUpdateParams = ChatCompletionUpdateParams;
  1364. export interface ChatCompletionListParams extends CursorPageParams {
  1365. /**
  1366. * A list of metadata keys to filter the Chat Completions by. Example:
  1367. *
  1368. * `metadata[key1]=value1&metadata[key2]=value2`
  1369. */
  1370. metadata?: Shared.Metadata | null;
  1371. /**
  1372. * The model used to generate the Chat Completions.
  1373. */
  1374. model?: string;
  1375. /**
  1376. * Sort order for Chat Completions by timestamp. Use `asc` for ascending order or
  1377. * `desc` for descending order. Defaults to `asc`.
  1378. */
  1379. order?: 'asc' | 'desc';
  1380. }
  1381. /**
  1382. * @deprecated Use ChatCompletionListParams instead
  1383. */
  1384. export type CompletionListParams = ChatCompletionListParams;
  1385. export declare namespace Completions {
  1386. export { type ChatCompletion as ChatCompletion, type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam, type ChatCompletionAudio as ChatCompletionAudio, type ChatCompletionAudioParam as ChatCompletionAudioParam, type ChatCompletionChunk as ChatCompletionChunk, type ChatCompletionContentPart as ChatCompletionContentPart, type ChatCompletionContentPartImage as ChatCompletionContentPartImage, type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio, type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal, type ChatCompletionContentPartText as ChatCompletionContentPartText, type ChatCompletionDeleted as ChatCompletionDeleted, type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam, type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption, type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam, type ChatCompletionMessage as ChatCompletionMessage, type ChatCompletionMessageParam as ChatCompletionMessageParam, type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall, type ChatCompletionModality as ChatCompletionModality, type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice, type ChatCompletionPredictionContent as ChatCompletionPredictionContent, type ChatCompletionRole as ChatCompletionRole, type ChatCompletionStoreMessage as ChatCompletionStoreMessage, type ChatCompletionStreamOptions as ChatCompletionStreamOptions, type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam, type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob, type ChatCompletionTool as ChatCompletionTool, type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption, type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam, type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam, type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage, type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort, ChatCompletionsPage as ChatCompletionsPage, type ChatCompletionCreateParams as ChatCompletionCreateParams, type CompletionCreateParams as CompletionCreateParams, type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming, type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming, type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming, type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming, type ChatCompletionUpdateParams as ChatCompletionUpdateParams, type CompletionUpdateParams as CompletionUpdateParams, type ChatCompletionListParams as ChatCompletionListParams, type CompletionListParams as CompletionListParams, };
  1387. export { Messages as Messages, type MessageListParams as MessageListParams };
  1388. }
  1389. //# sourceMappingURL=completions.d.ts.map