SpyBara
Go Premium

Documentation 2026-07-31 21:03 UTC to 2026-08-03 18:01 UTC

29 files changed +567 −555. View all changes and history on the product overview
2026
Wed 5 18:01 Tue 4 22:59 Mon 3 18:01
Details

59```javascript59```javascript

60const assistant = await openai.beta.assistants.create({60const assistant = await openai.beta.assistants.create({

61 name: "Data visualizer",61 name: "Data visualizer",

62 description: "You are great at creating beautiful data visualizations. You analyze data present in .csv files, understand trends, and come up with data visualizations relevant to those trends. You also share a brief text summary of the trends observed.",62 description:

63 "You are great at creating beautiful data visualizations. You analyze data present in .csv files, understand trends, and come up with data visualizations relevant to those trends. You also share a brief text summary of the trends observed.",

63 model: "gpt-4o",64 model: "gpt-4o",

64 tools: [{"type": "code_interpreter"}],65 tools: [{ type: "code_interpreter" }],

65 tool_resources: {66 tool_resources: {

66 "code_interpreter": {67 code_interpreter: {

67 "file_ids": [file.id]68 file_ids: [file.id],

68 }69 },

69 }70 },

70});71});

71```72```

72 73 


117const thread = await openai.beta.threads.create({118const thread = await openai.beta.threads.create({

118 messages: [119 messages: [

119 {120 {

120 "role": "user",121 role: "user",

121 "content": "Create 3 data visualizations based on the trends in this file.",122 content: "Create 3 data visualizations based on the trends in this file.",

122 "attachments": [123 attachments: [

123 {124 {

124 file_id: file.id,125 file_id: file.id,

125 tools: [{type: "code_interpreter"}]126 tools: [{ type: "code_interpreter" }],

126 }127 },

127 ]128 ],

128 }129 },

129 ]130 ],

130});131});

131```132```

132 133 


194const thread = await openai.beta.threads.create({195const thread = await openai.beta.threads.create({

195 messages: [196 messages: [

196 {197 {

197 "role": "user",198 role: "user",

198 "content": [199 content: [

199 {200 {

200 "type": "text",201 type: "text",

201 "text": "What is the difference between these images?"202 text: "What is the difference between these images?",

202 },203 },

203 {204 {

204 "type": "image_url",205 type: "image_url",

205 "image_url": {"url": "https://openai-documentation.vercel.app/images/cat_and_otter.png"}206 image_url: {

207 url: "https://openai-documentation.vercel.app/images/cat_and_otter.png",

208 },

206 },209 },

207 {210 {

208 "type": "image_file",211 type: "image_file",

209 "image_file": {"file_id": file.id}212 image_file: { file_id: file.id },

210 },213 },

211 ]214 ],

212 }215 },

213 ]216 ],

214});217});

215```218```

216 219 


282const thread = await openai.beta.threads.create({285const thread = await openai.beta.threads.create({

283 messages: [286 messages: [

284 {287 {

285 "role": "user",288 role: "user",

286 "content": [289 content: [

287 {290 {

288 "type": "text",291 type: "text",

289 "text": "What is this an image of?"292 text: "What is this an image of?",

290 },293 },

291 {294 {

292 "type": "image_url",295 type: "image_url",

293 "image_url": {296 image_url: {

294 "url": "https://openai-documentation.vercel.app/images/cat_and_otter.png",297 url: "https://openai-documentation.vercel.app/images/cat_and_otter.png",

295 "detail": "high"298 detail: "high",

296 }

297 },299 },

298 ]300 },

299 }301 ],

300 ]302 },

303 ],

301});304});

302```305```

303 306 


420```423```

421 424 

422```javascript425```javascript

423const run = await openai.beta.threads.runs.create(426const run = await openai.beta.threads.runs.create(thread.id, {

424 thread.id,427 assistant_id: assistant.id,

425 { assistant_id: assistant.id }428});

426);

427```429```

428 430 

429```bash431```bash


450```452```

451 453 

452```javascript454```javascript

453const run = await openai.beta.threads.runs.create(455const run = await openai.beta.threads.runs.create(thread.id, {

454 thread.id,

455 {

456 assistant_id: assistant.id,456 assistant_id: assistant.id,

457 model: "gpt-4o",457 model: "gpt-4o",

458 instructions: "New instructions that override the Assistant instructions",458 instructions: "New instructions that override the Assistant instructions",

459 tools: [{"type": "code_interpreter"}, {"type": "file_search"}]459 tools: [{ type: "code_interpreter" }, { type: "file_search" }],

460 }460});

461);

462```461```

463 462 

464```bash463```bash

Details

28 28 

29```javascript29```javascript

30const assistant = await openai.beta.assistants.create({30const assistant = await openai.beta.assistants.create({

31 instructions: "You are a personal math tutor. When asked a math question, write and run code to answer the question.",31 instructions:

32 "You are a personal math tutor. When asked a math question, write and run code to answer the question.",

32 model: "gpt-4o",33 model: "gpt-4o",

33 tools: [{"type": "code_interpreter"}]34 tools: [{ type: "code_interpreter" }],

34});35});

35```36```

36 37 


77 78 

78// Create an assistant using the file ID79// Create an assistant using the file ID

79const assistant = await openai.beta.assistants.create({80const assistant = await openai.beta.assistants.create({

80 instructions: "You are a personal math tutor. When asked a math question, write and run code to answer the question.",81 instructions:

82 "You are a personal math tutor. When asked a math question, write and run code to answer the question.",

81 model: "gpt-4o",83 model: "gpt-4o",

82 tools: [{"type": "code_interpreter"}],84 tools: [{ type: "code_interpreter" }],

83 tool_resources: {85 tool_resources: {

84 "code_interpreter": {86 code_interpreter: {

85 "file_ids": [file.id]87 file_ids: [file.id],

86 }88 },

87 }89 },

88});90});

89```91```

90 92 


133const thread = await openai.beta.threads.create({135const thread = await openai.beta.threads.create({

134 messages: [136 messages: [

135 {137 {

136 "role": "user",138 role: "user",

137 "content": "I need to solve the equation `3x + 11 = 14`. Can you help me?",139 content: "I need to solve the equation `3x + 11 = 14`. Can you help me?",

138 "attachments": [140 attachments: [

139 {141 {

140 file_id: file.id,142 file_id: file.id,

141 tools: [{type: "code_interpreter"}]143 tools: [{ type: "code_interpreter" }],

142 }144 },

143 ]145 ],

144 }146 },

145 ]147 ],

146});148});

147```149```

148 150 


284```286```

285 287 

286```javascript288```javascript

287const runSteps = await openai.beta.threads.runs.steps.list(289const runSteps = await openai.beta.threads.runs.steps.list(run.id, {

288 thread.id,290 thread_id: thread.id,

289 run.id291});

290);

291```292```

292 293 

293```bash294```bash

Details

82 82 

83```javascript83```javascript

84const assistant = await client.beta.assistants.create({84const assistant = await client.beta.assistants.create({

85model: "gpt-4o",85 model: "gpt-4o",

86instructions:86 instructions:

87"You are a weather bot. Use the provided functions to answer questions.",87 "You are a weather bot. Use the provided functions to answer questions.",

88tools: [88 tools: [

89{89 {

90type: "function",90 type: "function",

91function: {91 function: {

92name: "getCurrentTemperature",92 name: "getCurrentTemperature",

93description: "Get the current temperature for a specific location",93 description: "Get the current temperature for a specific location",

94parameters: {94 parameters: {

95type: "object",95 type: "object",

96properties: {96 properties: {

97location: {97 location: {

98type: "string",98 type: "string",

99description: "The city and state, e.g., San Francisco, CA",99 description: "The city and state, e.g., San Francisco, CA",

100},100 },

101unit: {101 unit: {

102type: "string",102 type: "string",

103enum: ["Celsius", "Fahrenheit"],103 enum: ["Celsius", "Fahrenheit"],

104description:104 description:

105"The temperature unit to use. Infer this from the user's location.",105 "The temperature unit to use. Infer this from the user's location.",

106},106 },

107},107 },

108required: ["location", "unit"],108 required: ["location", "unit"],

109},109 },

110},110 },

111},111 },

112{112 {

113type: "function",113 type: "function",

114function: {114 function: {

115name: "getRainProbability",115 name: "getRainProbability",

116description: "Get the probability of rain for a specific location",116 description: "Get the probability of rain for a specific location",

117parameters: {117 parameters: {

118type: "object",118 type: "object",

119properties: {119 properties: {

120location: {120 location: {

121type: "string",121 type: "string",

122description: "The city and state, e.g., San Francisco, CA",122 description: "The city and state, e.g., San Francisco, CA",

123},123 },

124},124 },

125required: ["location"],125 required: ["location"],

126},126 },

127},127 },

128},128 },

129],129 ],

130});130});

131```131```

132 132 


148const thread = await client.beta.threads.create();148const thread = await client.beta.threads.create();

149const message = client.beta.threads.messages.create(thread.id, {149const message = client.beta.threads.messages.create(thread.id, {

150 role: "user",150 role: "user",

151 content: "What's the weather in San Francisco today and the likelihood it'll rain?",151 content:

152 "What's the weather in San Francisco today and the likelihood it'll rain?",

152});153});

153```154```

154 155 


267 this.client = client;268 this.client = client;

268 }269 }

269 270 

270async onEvent(event) {271 async onEvent(event) {

271try {272 try {

272console.log(event);273 console.log(event);

273// Retrieve events that are denoted with 'requires_action'274 // Retrieve events that are denoted with 'requires_action'

274// since these will have our tool_calls275 // since these will have our tool_calls

275if (event.event === "thread.run.requires_action") {276 if (event.event === "thread.run.requires_action") {

276await this.handleRequiresAction(277 await this.handleRequiresAction(

277event.data,278 event.data,

278event.data.id,279 event.data.id,

279event.data.thread_id,280 event.data.thread_id

280);281 );

281}282 }

282} catch (error) {283 } catch (error) {

283console.error("Error handling event:", error);284 console.error("Error handling event:", error);

284}285 }

285}286 }

286 287 

287async handleRequiresAction(data, runId, threadId) {288 async handleRequiresAction(data, runId, threadId) {

288try {289 try {

289const toolOutputs =290 const toolOutputs =

290data.required_action.submit_tool_outputs.tool_calls.map((toolCall) => {291 data.required_action.submit_tool_outputs.tool_calls.map((toolCall) => {

291if (toolCall.function.name === "getCurrentTemperature") {292 if (toolCall.function.name === "getCurrentTemperature") {

292return {293 return {

293tool_call_id: toolCall.id,294 tool_call_id: toolCall.id,

294output: "57",295 output: "57",

295};296 };

296} else if (toolCall.function.name === "getRainProbability") {297 } else if (toolCall.function.name === "getRainProbability") {

297return {298 return {

298tool_call_id: toolCall.id,299 tool_call_id: toolCall.id,

299output: "0.06",300 output: "0.06",

300};301 };

301}302 }

302});303 });

303// Submit all the tool outputs at the same time304 // Submit all the tool outputs at the same time

304await this.submitToolOutputs(toolOutputs, runId, threadId);305 await this.submitToolOutputs(toolOutputs, runId, threadId);

305} catch (error) {306 } catch (error) {

306console.error("Error processing required action:", error);307 console.error("Error processing required action:", error);

307}308 }

308}309 }

309 310 

310async submitToolOutputs(toolOutputs, runId, threadId) {311 async submitToolOutputs(toolOutputs, runId, threadId) {

311try {312 try {

312// Use the submitToolOutputsStream helper313 // Use the submitToolOutputsStream helper

313const stream = this.client.beta.threads.runs.submitToolOutputsStream(314 const stream = this.client.beta.threads.runs.submitToolOutputsStream(

314threadId,315 runId,

315runId,316 { thread_id: threadId, tool_outputs: toolOutputs }

316{ tool_outputs: toolOutputs },317 );

317);318 for await (const event of stream) {

318for await (const event of stream) {319 this.emit("event", event);

319this.emit("event", event);320 }

320}321 } catch (error) {

321} catch (error) {322 console.error("Error submitting tool outputs:", error);

322console.error("Error submitting tool outputs:", error);323 }

323}324 }

324}

325}325}

326 326 

327const eventHandler = new EventHandler(client);327const eventHandler = new EventHandler(client);

328eventHandler.on("event", eventHandler.onEvent.bind(eventHandler));328eventHandler.on("event", eventHandler.onEvent.bind(eventHandler));

329 329 

330const stream = await client.beta.threads.runs.stream(330const stream = await client.beta.threads.runs.stream(threadId, {

331threadId,331 assistant_id: assistantId,

332{ assistant_id: assistantId },332});

333eventHandler,

334);

335 333 

336for await (const event of stream) {334for await (const event of stream) {

337eventHandler.emit("event", event);335 eventHandler.emit("event", event);

338}336}

339```337```

340 338 


418 output: "0.06",416 output: "0.06",

419 };417 };

420 }418 }

421 },419 }

422 );420 );

423 421 

424 // Submit all tool outputs at once after collecting them in a list422 // Submit all tool outputs at once after collecting them in a list

425 if (toolOutputs.length > 0) {423 if (toolOutputs.length > 0) {

426 run = await client.beta.threads.runs.submitToolOutputsAndPoll(424 run = await client.beta.threads.runs.submitToolOutputsAndPoll(run.id, {

427 thread.id,425 thread_id: thread.id,

428 run.id,426 tool_outputs: toolOutputs,

429 { tool_outputs: toolOutputs },427 });

430 );

431 console.log("Tool outputs submitted successfully.");428 console.log("Tool outputs submitted successfully.");

432 } else {429 } else {

433 console.log("No tool outputs to submit.");430 console.log("No tool outputs to submit.");


435 432 

436 // Check status after submitting tool outputs433 // Check status after submitting tool outputs

437 return handleRunStatus(run);434 return handleRunStatus(run);

438 435 }

439}

440};436};

441 437 

442const handleRunStatus = async (run) => {438const handleRunStatus = async (run) => {

443// Check if the run is completed439 // Check if the run is completed

444if (run.status === "completed") {440 if (run.status === "completed") {

445let messages = await client.beta.threads.messages.list(thread.id);441 let messages = await client.beta.threads.messages.list(thread.id);

446console.log(messages.data);442 console.log(messages.data);

447return messages.data;443 return messages.data;

448} else if (run.status === "requires_action") {444 } else if (run.status === "requires_action") {

449console.log(run.status);445 console.log(run.status);

450return await handleRequiresAction(run);446 return await handleRequiresAction(run);

451} else {447 } else {

452console.error("Run did not complete:", run);448 console.error("Run did not complete:", run);

453}449 }

454};450};

455 451 

456// Create and poll run452// Create and poll run

457let run = await client.beta.threads.runs.createAndPoll(thread.id, {453let run = await client.beta.threads.runs.createAndPoll(thread.id, {

458assistant_id: assistant.id,454 assistant_id: assistant.id,

459});455});

460 456 

461handleRunStatus(run);457handleRunStatus(run);


533 529 

534```javascript530```javascript

535const assistant = await client.beta.assistants.create({531const assistant = await client.beta.assistants.create({

536model: "gpt-4o-2024-08-06",532 model: "gpt-4o-2024-08-06",

537instructions:533 instructions:

538"You are a weather bot. Use the provided functions to answer questions.",534 "You are a weather bot. Use the provided functions to answer questions.",

539tools: [535 tools: [

540{536 {

541type: "function",537 type: "function",

542function: {538 function: {

543name: "getCurrentTemperature",539 name: "getCurrentTemperature",

544description: "Get the current temperature for a specific location",540 description: "Get the current temperature for a specific location",

545parameters: {541 parameters: {

546type: "object",542 type: "object",

547properties: {543 properties: {

548location: {544 location: {

549type: "string",545 type: "string",

550description: "The city and state, e.g., San Francisco, CA",546 description: "The city and state, e.g., San Francisco, CA",

551},547 },

552unit: {548 unit: {

553type: "string",549 type: "string",

554enum: ["Celsius", "Fahrenheit"],550 enum: ["Celsius", "Fahrenheit"],

555description:551 description:

556"The temperature unit to use. Infer this from the user's location.",552 "The temperature unit to use. Infer this from the user's location.",

557},553 },

558},554 },

559required: ["location", "unit"],555 required: ["location", "unit"],

560// highlight-start556 // highlight-start

561additionalProperties: false557 additionalProperties: false,

562// highlight-end558 // highlight-end

563},559 },

564// highlight-start560 // highlight-start

565strict: true561 strict: true,

566// highlight-end562 // highlight-end

567},563 },

568},564 },

569{565 {

570type: "function",566 type: "function",

571function: {567 function: {

572name: "getRainProbability",568 name: "getRainProbability",

573description: "Get the probability of rain for a specific location",569 description: "Get the probability of rain for a specific location",

574parameters: {570 parameters: {

575type: "object",571 type: "object",

576properties: {572 properties: {

577location: {573 location: {

578type: "string",574 type: "string",

579description: "The city and state, e.g., San Francisco, CA",575 description: "The city and state, e.g., San Francisco, CA",

580},576 },

581},577 },

582required: ["location"],578 required: ["location"],

583// highlight-start579 // highlight-start

584additionalProperties: false580 additionalProperties: false,

585// highlight-end581 // highlight-end

586},582 },

587// highlight-start583 // highlight-start

588strict: true584 strict: true,

589// highlight-end585 // highlight-end

590},586 },

591},587 },

592],588 ],

593});589});

594```590```

guides/audio.md +3 −3

Details

47 47 

48Models such as [`gpt-realtime-2.1`](https://developers.openai.com/api/docs/models/gpt-realtime-2.1) and [`gpt-audio-1.5`](https://developers.openai.com/api/docs/models/gpt-audio-1.5) are natively multimodal, meaning they can understand and generate audio and text as input and output.48Models such as [`gpt-realtime-2.1`](https://developers.openai.com/api/docs/models/gpt-realtime-2.1) and [`gpt-audio-1.5`](https://developers.openai.com/api/docs/models/gpt-audio-1.5) are natively multimodal, meaning they can understand and generate audio and text as input and output.

49 49 

50For live browser speech-to-speech interactions, start with a realtime session in the JavaScript SDK:50For live browser speech-to-speech interactions, start with a realtime session in the TypeScript Agents SDK:

51 51 

52Start a realtime voice session52Start a realtime voice session

53 53 

54```javascript54```typescript

55import { RealtimeAgent, RealtimeSession } from "@openai/agents/realtime";55import { RealtimeAgent, RealtimeSession } from "@openai/agents/realtime";

56 56 

57const agent = new RealtimeAgent({57const agent = new RealtimeAgent({


69```69```

70 70 

71 71 

72This example uses JavaScript because browser voice agents connect with WebRTC from the client. For Python voice workflows, use the [Voice agents guide](https://developers.openai.com/api/docs/guides/voice-agents), which covers chained voice pipelines.72This TypeScript example uses the Agents SDK to connect browser voice agents with WebRTC from the client. For Python voice workflows, use the [Voice agents guide](https://developers.openai.com/api/docs/guides/voice-agents), which covers chained voice pipelines.

73 73 

74If you already have a text-based LLM application with the [Chat Completions endpoint](https://developers.openai.com/api/reference/resources/chat), you may want to add audio capabilities. For example, if your chat application supports text input, you can add audio input and output: include `audio` in the `modalities` array and use an audio model, like [`gpt-audio-1.5`](https://developers.openai.com/api/docs/models/gpt-audio-1.5).74If you already have a text-based LLM application with the [Chat Completions endpoint](https://developers.openai.com/api/reference/resources/chat), you may want to add audio capabilities. For example, if your chat application supports text input, you can add audio input and output: include `audio` in the `modalities` array and use an audio model, like [`gpt-audio-1.5`](https://developers.openai.com/api/docs/models/gpt-audio-1.5).

75 75 

guides/batch.md +6 −6

Details

137 -F file="@batchinput.jsonl"137 -F file="@batchinput.jsonl"

138```138```

139 139 

140```cli140```bash

141openai files create \141openai files create \

142 --file batchinput.jsonl \142 --file batchinput.jsonl \

143 --purpose batch143 --purpose batch


184 }'184 }'

185```185```

186 186 

187```cli187```bash

188openai batches create \188openai batches create \

189 --input-file-id file-abc123 \189 --input-file-id file-abc123 \

190 --endpoint /v1/chat/completions \190 --endpoint /v1/chat/completions \


245 -H "Content-Type: application/json"245 -H "Content-Type: application/json"

246```246```

247 247 

248```cli248```bash

249openai batches retrieve \249openai batches retrieve \

250 --batch-id batch_abc123250 --batch-id batch_abc123

251```251```


297 -H "Authorization: Bearer $OPENAI_API_KEY" > batch_output.jsonl297 -H "Authorization: Bearer $OPENAI_API_KEY" > batch_output.jsonl

298```298```

299 299 

300```cli300```bash

301openai files content \301openai files content \

302 --file-id file-xyz123 \302 --file-id file-xyz123 \

303 --output batch_output.jsonl303 --output batch_output.jsonl


352 -X POST352 -X POST

353```353```

354 354 

355```cli355```bash

356openai batches cancel \356openai batches cancel \

357 --batch-id batch_abc123357 --batch-id batch_abc123

358```358```


389 -H "Content-Type: application/json"389 -H "Content-Type: application/json"

390```390```

391 391 

392```cli392```bash

393openai batches list \393openai batches list \

394 --limit 10394 --limit 10

395```395```

Details

23 23 

24Actions can also be sent imperatively by your frontend with `sendAction()`. This is probably most useful when you need ChatKit to respond to interaction happening outside ChatKit, but it can also be used to chain actions when you need to respond on both the client and the server (more on that below).24Actions can also be sent imperatively by your frontend with `sendAction()`. This is probably most useful when you need ChatKit to respond to interaction happening outside ChatKit, but it can also be used to chain actions when you need to respond on both the client and the server (more on that below).

25 25 

26```tsx26```typescript

27await chatKit.sendAction({27await chatKit.sendAction({

28 type: "example",28 type: "example",

29 payload: { id: 123 },29 payload: { id: 123 },


83 84 

84Then, when the action is triggered, it will then be passed to a callback that you provide when instantiating ChatKit.85Then, when the action is triggered, it will then be passed to a callback that you provide when instantiating ChatKit.

85 86 

86```ts87```typescript

87async function handleWidgetAction(action: {type: string, Record<string, unknown>}) {88async function handleWidgetAction(action: WidgetAction) {

88 if (action.type === "example") {89 if (action.type === "example") {

89 const res = await doSomething(action)90 const res = await doSomething(action);

90 91 

91 // You can fire off actions to your server from here as well.92 // You can fire off actions to your server from here as well.

92 // e.g. if you want to stream new thread items or update a widget.93 // For example, stream new thread items or update a widget.

93 await chatKit.sendAction({94 await chatKit.sendAction({

94 type: "example_complete",95 type: "example_complete",

95 payload: res96 payload: res,

96 })97 });

97 }98 }

98}99}

99 100 

100chatKit.setOptions({101chatKit.setOptions({

101 // other options...102 // Other options...

102 widgets: { onAction: handleWidgetAction }103 widgets: { onAction: handleWidgetAction },

103})104});

104```105```

105 106 

107 

106## Strongly typed actions108## Strongly typed actions

107 109 

108By default `Action` and `ActionConfig` are not strongly typed. However, we do expose a `create` helper on `Action` that generates `ActionConfig`s from a set of strongly-typed actions.110By default `Action` and `ActionConfig` are not strongly typed. However, we do expose a `create` helper on `Action` that generates `ActionConfig`s from a set of strongly-typed actions.

Details

57 57 

58For all theming options, see the [API reference](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/themeoption/).58For all theming options, see the [API reference](https://openai.github.io/chatkit-js/api/openai/chatkit/type-aliases/themeoption/).

59 59 

60```jsx60```typescript

61const options: Partial<ChatKitOptions> = {61const options: Partial<ChatKitOptions> = {

62 theme: {62 theme: {

63 colorScheme: "dark",63 colorScheme: "dark",

64 color: {64 color: {

65 accent: {65 accent: {

66 primary: "#2D8CFF",66 primary: "#2D8CFF",

67 level: 267 level: 2,

68 }68 },

69 },69 },

70 radius: "round",70 radius: "round",

71 density: "compact",71 density: "compact",


78 79 

79Let users know what to ask or guide their first input by changing the composer’s placeholder text.80Let users know what to ask or guide their first input by changing the composer’s placeholder text.

80 81 

81```jsx82```typescript

82const options: Partial<ChatKitOptions> = {83const options: Partial<ChatKitOptions> = {

83 composer: {84 composer: {

84 placeholder: "Ask anything about your data…",85 placeholder: "Ask anything about your data…",


93 95 

94Guide users on what to ask or do by suggesting prompt ideas when starting a conversation.96Guide users on what to ask or do by suggesting prompt ideas when starting a conversation.

95 97 

96```js98```typescript

97const options: Partial<ChatKitOptions> = {99const options: Partial<ChatKitOptions> = {

98 startScreen: {100 startScreen: {

99 greeting: "What can I help you build today?",101 greeting: "What can I help you build today?",


101 {103 {

102 name: "Check on the status of a ticket",104 name: "Check on the status of a ticket",

103 prompt: "Can you help me check on the status of a ticket?",105 prompt: "Can you help me check on the status of a ticket?",

104 icon: "search"106 icon: "search",

105 },107 },

106 {108 {

107 name: "Create Ticket",109 name: "Create Ticket",

108 prompt: "Can you help me create a new support ticket?",110 prompt: "Can you help me create a new support ticket?",

109 icon: "write"111 icon: "write",

110 },112 },

111 ],113 ],

112 },114 },


117 120 

118Custom header buttons help you add navigation, context, or actions relevant to your integration.121Custom header buttons help you add navigation, context, or actions relevant to your integration.

119 122 

120```jsx123```typescript

121const options: Partial<ChatKitOptions> = {124const options: Partial<ChatKitOptions> = {

122 header: {125 header: {

123 customButtonLeft: {126 customButtonLeft: {


140 144 

141You can also control the number, size, and types of files that users can attach to messages.145You can also control the number, size, and types of files that users can attach to messages.

142 146 

143```jsx147```typescript

144const options: Partial<ChatKitOptions> = {148const options: Partial<ChatKitOptions> = {

145 composer: {149 composer: {

146 attachments: {150 attachments: {

147 uploadStrategy: { type: 'hosted' },151 uploadStrategy: { type: "hosted" },

148 maxSize: 20 * 1024 * 1024, // 20MB per file152 maxSize: 20 * 1024 * 1024, // 20 MB per file

149 maxCount: 3,153 maxCount: 3,

150 accept: { "application/pdf": [".pdf"], "image/*": [".png", ".jpg"] },154 accept: { "application/pdf": [".pdf"], "image/*": [".png", ".jpg"] },

151 },155 },

152 },156 },

153}157};

154```158```

155 159 

160 

156## Enable @mentions in the composer with entity tags161## Enable @mentions in the composer with entity tags

157 162 

158Let users tag custom “entities” with @-mentions. This enables richer conversation context and interactivity.163Let users tag custom “entities” with @-mentions. This enables richer conversation context and interactivity.


160- Use `onTagSearch` to return a list of entities based on the input query.165- Use `onTagSearch` to return a list of entities based on the input query.

161- Use `onClick` to handle the click event of an entity.166- Use `onClick` to handle the click event of an entity.

162 167 

163```jsx168```typescript

164const options: Partial<ChatKitOptions> = {169const options: Partial<ChatKitOptions> = {

165 entities: {170 entities: {

166 async onTagSearch(query) {171 async onTagSearch(query: string) {

172 void query;

167 return [173 return [

168 {174 {

169 id: "user_123",175 id: "user_123",


177 group: "Documents",183 group: "Documents",

178 interactive: true,184 interactive: true,

179 },185 },

180 ]186 ];

181 },187 },

182 onClick: (entity) => {188 onClick: (entity: { id: string }) => {

183 navigateToEntity(entity.id);189 navigateToEntity(entity.id);

184 },190 },

185 },191 },


196 203 

197 Browse available widgets.](https://widgets.chatkit.studio)204 Browse available widgets.](https://widgets.chatkit.studio)

198 205 

199```jsx206```typescript

200const options: Partial<ChatKitOptions> = {207const options: Partial<ChatKitOptions> = {

201 entities: {208 entities: {

202 async onTagSearch() { /* ... */ },209 async onTagSearch() {

203 onRequestPreview: async (entity) => ({210 return [];

211 },

212 onRequestPreview: async (entity: { title: string }) => ({

204 preview: {213 preview: {

205 type: "Card",214 type: "Card",

206 children: [215 children: [


218Enhance productivity by letting users trigger app-specific actions from the composer bar. The selected tool228Enhance productivity by letting users trigger app-specific actions from the composer bar. The selected tool

219will be sent to the model as a tool preference.229will be sent to the model as a tool preference.

220 230 

221```jsx231```typescript

222const options: Partial<ChatKitOptions> = {232const options: Partial<ChatKitOptions> = {

223 composer: {233 composer: {

224 tools: [234 tools: [

225 {235 {

226 id: 'add-note',236 id: "add-note",

227 label: 'Add Note',237 label: "Add Note",

228 icon: 'write',238 icon: "write",

229 pinned: true,239 pinned: true,

230 },240 },

231 ],241 ],


237 248 

238Disable major UI regions and features if you need more customization over the options available in the header and want to implement your own instead. Disabling history can be useful when the concept of threads and history doesn't make sense for your use case—e.g., in a support chatbot.249Disable major UI regions and features if you need more customization over the options available in the header and want to implement your own instead. Disabling history can be useful when the concept of threads and history doesn't make sense for your use case—e.g., in a support chatbot.

239 250 

240```jsx251```typescript

241const options: Partial<ChatKitOptions> = {252const options: Partial<ChatKitOptions> = {

242 history: { enabled: false },253 history: { enabled: false },

243 header: { enabled: false },254 header: { enabled: false },


248 260 

249Override the default locale if you have an app-wide language setting. By default, the locale is set to the browser's locale.261Override the default locale if you have an app-wide language setting. By default, the locale is set to the browser's locale.

250 262 

251```jsx263```typescript

252const options: Partial<ChatKitOptions> = {264const options: Partial<ChatKitOptions> = {

253 locale: 'de-DE',265 locale: "de-DE",

254};266};

255```267```

Details

22 22 

23Capture widget events with the `onAction` callback from `WidgetsOption` or equivalent React hook. Forward the action payload to your backend to handle actions.23Capture widget events with the `onAction` callback from `WidgetsOption` or equivalent React hook. Forward the action payload to your backend to handle actions.

24 24 

25```ts25```typescript

26chatkit.setOptions({26chatkit.setOptions({

27 widgets: {27 widgets: {

28 async onAction(action, item) {28 async onAction(action, item) {

Details

325 .join("|");325 .join("|");

326 326 

327 const tokenRe = new RegExp(327 const tokenRe = new RegExp(

328 `\uE200(?<family>${familyPattern})\uE202(?<body>[\\s\\S]*?)\uE201`,328 `${CITATION_START}(?<family>${familyPattern})${CITATION_DELIMITER}(?<body>[\\s\\S]*?)${CITATION_STOP}`,

329 "g"329 "g"

330 );330 );

331 331 


378 );378 );

379 379 

380 for (const citation of sortedCitations) {380 for (const citation of sortedCitations) {

381 cleanText = cleanText.slice(0, citation.start) + cleanText.slice(citation.end);381 cleanText =

382 cleanText.slice(0, citation.start) + cleanText.slice(citation.end);

382 }383 }

383 384 

384 return cleanText;385 return cleanText;

Details

18 18 

19```javascript19```javascript

20const completion = await openai.completions.create({20const completion = await openai.completions.create({

21model: 'gpt-3.5-turbo-instruct',21 model: "gpt-3.5-turbo-instruct",

22prompt: 'Write a tagline for an ice cream shop.'22 prompt: "Write a tagline for an ice cream shop.",

23});23});

24```24```

25 25 

Details

206 206 

207ChatKit emits `CustomEvent` instances from the Web Component. The payload shapes are:207ChatKit emits `CustomEvent` instances from the Web Component. The payload shapes are:

208 208 

209```ts209```typescript

210type Events = {210type Events = {

211 "chatkit.error": CustomEvent<{ error: Error }>;211 "chatkit.error": CustomEvent<{ error: Error }>;

212 "chatkit.response.start": CustomEvent<void>;212 "chatkit.response.start": CustomEvent<void>;

Details

120 }' | jq -r '.data[0].b64_json' | base64 --decode > otter.png120 }' | jq -r '.data[0].b64_json' | base64 --decode > otter.png

121```121```

122 122 

123```cli123```bash

124openai images generate \124openai images generate \

125 --model gpt-image-2 \125 --model gpt-image-2 \

126 --prompt "A children's book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter." \126 --prompt "A children's book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter." \


1002 -F 'prompt=Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting-like font, containing all the items in the reference pictures'1002 -F 'prompt=Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting-like font, containing all the items in the reference pictures'

1003```1003```

1004 1004 

1005```cli1005```bash

1006openai images edit \1006openai images edit \

1007 --model gpt-image-2 \1007 --model gpt-image-2 \

1008 --image body-lotion.png \1008 --image body-lotion.png \


1209 -F 'prompt=A sunlit indoor lounge area with a pool containing a flamingo'1209 -F 'prompt=A sunlit indoor lounge area with a pool containing a flamingo'

1210```1210```

1211 1211 

1212```cli1212```bash

1213openai images edit \1213openai images edit \

1214 --model gpt-image-2 \1214 --model gpt-image-2 \

1215 --image sunlit_lounge.png \1215 --image sunlit_lounge.png \

Details

86 f.write(base64.b64decode(image_base64))86 f.write(base64.b64decode(image_base64))

87```87```

88 88 

89```cli89```bash

90openai responses create \90openai responses create \

91 --model gpt-5.6 \91 --model gpt-5.6 \

92 --raw-output \92 --raw-output \


230 }'230 }'

231```231```

232 232 

233```cli233```bash

234openai responses create \234openai responses create \

235 --model gpt-5.6 \235 --model gpt-5.6 \

236 --raw-output \236 --raw-output \

Details

236 236 

237**What changed?** Before, we had one prompt to re-write the query and one to determine whether this requires doing a retrieval lookup. Now, this combined prompt does both. Specifically, notice the updated instruction in the first line of the prompt, and the updated output JSON:237**What changed?** Before, we had one prompt to re-write the query and one to determine whether this requires doing a retrieval lookup. Now, this combined prompt does both. Specifically, notice the updated instruction in the first line of the prompt, and the updated output JSON:

238 238 

239```jsx239```javascript

240{240{

241 query:"[contextualized query]",241 query: "[contextualized query]",

242 retrieval:"[true/false - whether retrieval is required]"242 retrieval: "[true/false - whether retrieval is required]",

243}243}

244```244```

245 245 


289 290 

290**Could we use a fine-tuned GPT-3.5 instead of GPT-4?** Maybe – but in general, open-ended responses from assistants are best left to GPT-4 so it can better handle a greater range of cases. That being said, looking at the reasoning steps themselves, they may not all require GPT-4 level reasoning to produce. The well defined, limited scope nature makes them and **good potential candidates for fine-tuning**.291**Could we use a fine-tuned GPT-3.5 instead of GPT-4?** Maybe – but in general, open-ended responses from assistants are best left to GPT-4 so it can better handle a greater range of cases. That being said, looking at the reasoning steps themselves, they may not all require GPT-4 level reasoning to produce. The well defined, limited scope nature makes them and **good potential candidates for fine-tuning**.

291 292 

292```jsx293```javascript

293{294{

294 "message_is_conversation_continuation": "True", // <-295 message_is_conversation_continuation: "True", // <-

295 "number_of_messages_in_conversation_so_far": "1", // <-296 number_of_messages_in_conversation_so_far: "1", // <-

296 "user_sentiment": "Aggravated", // <-297 user_sentiment: "Aggravated", // <-

297 "query_type": "Hardware Issue", // <-298 query_type: "Hardware Issue", // <-

298 "response_tone": "Validating and solution-oriented", // <-299 response_tone: "Validating and solution-oriented", // <-

299 "response_requirements": "Propose options for repair or replacement.", // <-300 response_requirements: "Propose options for repair or replacement.", // <-

300 "user_requesting_to_talk_to_human": "False", // <-301 user_requesting_to_talk_to_human: "False", // <-

301 "enough_information_in_context": "True", // <-302 enough_information_in_context: "True", // <-

302 "response": "..." // X -- benefits from GPT-4303 response: "...", // X -- benefits from GPT-4

303}304}

304```305```

305 306 


392 394 

393Taking a closer look at the reasoning JSON you may notice the field names themselves are quite long.395Taking a closer look at the reasoning JSON you may notice the field names themselves are quite long.

394 396 

395```jsx397```javascript

396{398{

397 "message_is_conversation_continuation": "True", // <-399 message_is_conversation_continuation: "True", // <-

398 "number_of_messages_in_conversation_so_far": "1", // <-400 number_of_messages_in_conversation_so_far: "1", // <-

399 "user_sentiment": "Aggravated", // <-401 user_sentiment: "Aggravated", // <-

400 "query_type": "Hardware Issue", // <-402 query_type: "Hardware Issue", // <-

401 "response_tone": "Validating and solution-oriented", // <-403 response_tone: "Validating and solution-oriented", // <-

402 "response_requirements": "Propose options for repair or replacement.", // <-404 response_requirements: "Propose options for repair or replacement.", // <-

403 "user_requesting_to_talk_to_human": "False", // <-405 user_requesting_to_talk_to_human: "False", // <-

404}406}

405```407```

406 408 

409 

407By making them shorter and moving explanations to the comments we can [generate fewer tokens](#generate-fewer-tokens).410By making them shorter and moving explanations to the comments we can [generate fewer tokens](#generate-fewer-tokens).

408 411 

409```jsx412```javascript

410{413{

411 "cont": "True", // whether last message is a continuation414 cont: "True", // whether last message is a continuation

412 "n_msg": "1", // number of messages in the continued conversation415 n_msg: "1", // number of messages in the continued conversation

413 "tone_in": "Aggravated", // sentiment of user query416 tone_in: "Aggravated", // sentiment of user query

414 "type": "Hardware Issue", // type of the user query417 type: "Hardware Issue", // type of the user query

415 "tone_out": "Validating and solution-oriented", // desired tone for response418 tone_out: "Validating and solution-oriented", // desired tone for response

416 "reqs": "Propose options for repair or replacement.", // response requirements419 reqs: "Propose options for repair or replacement.", // response requirements

417 "human": "False", // whether user is expressing want to talk to human420 human: "False", // whether user is expressing want to talk to human

418}421}

419```422```

420 423 

Details

483 483 

484#### Chat Completions API484#### Chat Completions API

485 485 

486```javascript486```json

487{487{

488 "type": "function",488 "type": "function",

489 "function": {489 "function": {


494 "type": "object",494 "type": "object",

495 "properties": {495 "properties": {

496 "location": {496 "location": {

497 "type": "string",497 "type": "string"

498 },498 }

499 },499 },

500 "additionalProperties": false,500 "additionalProperties": false,

501 "required": [501 "required": [


508 508 

509#### Responses API509#### Responses API

510 510 

511```javascript511```json

512{512{

513 "type": "function",513 "type": "function",

514 "name": "get_weather",514 "name": "get_weather",


517 "type": "object",517 "type": "object",

518 "properties": {518 "properties": {

519 "location": {519 "location": {

520 "type": "string",520 "type": "string"

521 },521 }

522 },522 },

523 "additionalProperties": false,523 "additionalProperties": false,

524 "required": [524 "required": [

Details

127```128```

128 129 

129 130 

130In addition to the refactored code, the model response will contain data that looks something like this:131In addition to the refactored code, an abridged model response without the `choices` field contains usage data like this:

131 132 

132```javascript133```json

133{134{

134 id: 'chatcmpl-xxx',135 "id": "chatcmpl-xxx",

135 object: 'chat.completion',136 "object": "chat.completion",

136 created: 1730918466,137 "created": 1730918466,

137 model: 'gpt-4o-2024-08-06',138 "model": "gpt-4o-2024-08-06",

138 choices: [ /* ...actual text response here... */],139 "usage": {

139 usage: {140 "prompt_tokens": 81,

140 prompt_tokens: 81,141 "completion_tokens": 39,

141 completion_tokens: 39,142 "total_tokens": 120,

142 total_tokens: 120,143 "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 },

143 prompt_tokens_details: { cached_tokens: 0, audio_tokens: 0 },144 "completion_tokens_details": {

144 completion_tokens_details: {145 "reasoning_tokens": 0,

145 reasoning_tokens: 0,146 "audio_tokens": 0,

146 audio_tokens: 0,147 "accepted_prediction_tokens": 18,

147 accepted_prediction_tokens: 18,148 "rejected_prediction_tokens": 10

148 rejected_prediction_tokens: 10

149 }149 }

150 },150 },

151 system_fingerprint: 'fp_159d8341cc'151 "system_fingerprint": "fp_159d8341cc"

152}152}

153```153```

154 154 


251When providing prediction text, your prediction can appear anywhere within the generated response, and still provide latency reduction for the response. Let's say your predicted text is the simple [Hono](https://hono.dev/) server shown below:251When providing prediction text, your prediction can appear anywhere within the generated response, and still provide latency reduction for the response. Let's say your predicted text is the simple [Hono](https://hono.dev/) server shown below:

252 252 

253```typescript253```typescript

254 254import { serve } from "@hono/node-server";

255 255import { serveStatic } from "@hono/node-server/serve-static";

256 256import { Hono } from "hono";

257 257 

258const app = new Hono();258const app = new Hono();

259 259 


261 return c.text("Hello Hono!");261 return c.text("Hello Hono!");

262});262});

263 263 

264// You will need to build the client code first `pnpm run ui:build`264// You will need to build the client code first: `pnpm run ui:build`.

265app.use(265app.use(

266 "/*",266 "/*",

267 serveStatic({267 serveStatic({


290The response to the prompt might look something like this:291The response to the prompt might look something like this:

291 292 

292```typescript293```typescript

293 294import { serve } from "@hono/node-server";

294 295import { serveStatic } from "@hono/node-server/serve-static";

295 296import { Hono } from "hono";

296 297 

297const app = new Hono();298const app = new Hono();

298 299 


304 return c.text("hello world");305 return c.text("hello world");

305});306});

306 307 

307// You will need to build the client code first `pnpm run ui:build`308// You will need to build the client code first: `pnpm run ui:build`.

308app.use(309app.use(

309 "/*",310 "/*",

310 serveStatic({311 serveStatic({


321});322});

322```323```

323 324 

324You would still see accepted prediction tokens in the response, even though the prediction text appeared both before and after the new content added to the response:

325 325 

326```javascript326An abridged model response without the `choices` field would still show accepted prediction tokens, even though the prediction text appeared both before and after the new content added to the response:

327 

328```json

327{329{

328 id: 'chatcmpl-xxx',330 "id": "chatcmpl-xxx",

329 object: 'chat.completion',331 "object": "chat.completion",

330 created: 1731014771,332 "created": 1731014771,

331 model: 'gpt-4o-2024-08-06',333 "model": "gpt-4o-2024-08-06",

332 choices: [ /* completion here... */],334 "usage": {

333 usage: {335 "prompt_tokens": 203,

334 prompt_tokens: 203,336 "completion_tokens": 159,

335 completion_tokens: 159,337 "total_tokens": 362,

336 total_tokens: 362,338 "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 },

337 prompt_tokens_details: { cached_tokens: 0, audio_tokens: 0 },339 "completion_tokens_details": {

338 completion_tokens_details: {340 "reasoning_tokens": 0,

339 reasoning_tokens: 0,341 "audio_tokens": 0,

340 audio_tokens: 0,342 "accepted_prediction_tokens": 60,

341 accepted_prediction_tokens: 60,343 "rejected_prediction_tokens": 0

342 rejected_prediction_tokens: 0

343 }344 }

344 },345 },

345 system_fingerprint: 'fp_9ee9e968ea'346 "system_fingerprint": "fp_9ee9e968ea"

346}347}

347```348```

348 349 

Details

35print(response.output_text)35print(response.output_text)

36```36```

37 37 

38```cli38```bash

39openai responses create \39openai responses create \

40 --model "gpt-5.6" \40 --model "gpt-5.6" \

41 --input "Write a one-sentence bedtime story about a unicorn." \41 --input "Write a one-sentence bedtime story about a unicorn." \

Details

35import OpenAI from "openai";35import OpenAI from "openai";

36const client = new OpenAI();36const client = new OpenAI();

37 37 

38const vector_store = await client.vectorStores.create({ // Create vector store38const vector_store = await client.vectorStores.create({

39 // Create vector store

39 name: "Support FAQ",40 name: "Support FAQ",

40});41});

41 42 

42await client.vector_stores.files.upload_and_poll({ // Upload file43await client.vectorStores.files.uploadAndPoll(

43 vector_store_id: vector_store.id,44 vector_store.id,

44 file: fs.createReadStream("customer_policies.txt"),45 // Upload file

45});46 fs.createReadStream("customer_policies.txt")

47);

46```48```

47 49 

48 50 


64```javascript66```javascript

65const userQuery = "What is the return policy?";67const userQuery = "What is the return policy?";

66 68 

67const results = await client.vectorStores.search({69const results = await client.vectorStores.search(vector_store.id, {

68 vector_store_id: vector_store.id,

69 query: userQuery,70 query: userQuery,

70});71});

71```72```


106```107```

107 108 

108```javascript109```javascript

109const results = await client.vectorStores.search({110const results = await client.vectorStores.search(vector_store.id, {

110 vector_store_id: vector_store.id,

111 query: "How many woodchucks are allowed per passenger?",111 query: "How many woodchucks are allowed per passenger?",

112});112});

113```113```


371```371```

372 372 

373```javascript373```javascript

374await client.vector_stores.create({374await client.vectorStores.create({

375 name: "Support FAQ",375 name: "Support FAQ",

376 file_ids: ["file_123"]376 file_ids: ["file_123"],

377});377});

378```378```

379 379 


393```393```

394 394 

395```javascript395```javascript

396await client.vector_stores.retrieve({396await client.vectorStores.retrieve("vs_123");

397 vector_store_id: "vs_123"

398});

399```397```

400 398 

401 399


415```413```

416 414 

417```javascript415```javascript

418await client.vector_stores.update({416await client.vectorStores.update("vs_123", {

419 vector_store_id: "vs_123",417 name: "Support FAQ Updated",

420 name: "Support FAQ Updated"

421});418});

422```419```

423 420 


437```434```

438 435 

439```javascript436```javascript

440await client.vector_stores.delete({437await client.vectorStores.delete("vs_123");

441 vector_store_id: "vs_123"

442});

443```438```

444 439 

445 440


456```451```

457 452 

458```javascript453```javascript

459await client.vector_stores.list();454await client.vectorStores.list();

460```455```

461 456 

462 457 


481```476```

482 477 

483```javascript478```javascript

484await client.vector_stores.files.create_and_poll({479await client.vectorStores.files.createAndPoll("vs_123", {

485 vector_store_id: "vs_123",480 file_id: "file_123",

486 file_id: "file_123"

487});481});

488```482```

489 483 


504```498```

505 499 

506```javascript500```javascript

507await client.vector_stores.files.upload_and_poll({501await client.vectorStores.files.uploadAndPoll(

508 vector_store_id: "vs_123",502 "vs_123",

509 file: fs.createReadStream("customer_policies.txt"),503 fs.createReadStream("customer_policies.txt")

510});504);

511```505```

512 506 

513 507


527```521```

528 522 

529```javascript523```javascript

530await client.vector_stores.files.retrieve({524await client.vectorStores.files.retrieve("file_123", {

531 vector_store_id: "vs_123",525 vector_store_id: "vs_123",

532 file_id: "file_123"

533});526});

534```527```

535 528 


551```544```

552 545 

553```javascript546```javascript

554await client.vector_stores.files.update({547await client.vectorStores.files.update("file_123", {

555 vector_store_id: "vs_123",548 vector_store_id: "vs_123",

556 file_id: "file_123",549 attributes: { key: "value" },

557 attributes: { key: "value" }

558});550});

559```551```

560 552 


575```567```

576 568 

577```javascript569```javascript

578await client.vector_stores.files.delete({570await client.vectorStores.files.delete("file_123", {

579 vector_store_id: "vs_123",571 vector_store_id: "vs_123",

580 file_id: "file_123"

581});572});

582```573```

583 574 


597```588```

598 589 

599```javascript590```javascript

600await client.vector_stores.files.list({591await client.vectorStores.files.list("vs_123");

601 vector_store_id: "vs_123"

602});

603```592```

604 593 

605 594 


633```622```

634 623 

635```javascript624```javascript

636await client.vector_stores.file_batches.create_and_poll({625await client.vectorStores.fileBatches.createAndPoll("vs_123", {

637 vector_store_id: "vs_123",

638 files: [626 files: [

639 {627 {

640 file_id: "file_123",628 file_id: "file_123",

641 attributes: { department: "finance" }629 attributes: { department: "finance" },

642 },630 },

643 {631 {

644 file_id: "file_456",632 file_id: "file_456",

645 chunking_strategy: {633 chunking_strategy: {

646 type: "static",634 type: "static",

635 static: {

647 max_chunk_size_tokens: 1200,636 max_chunk_size_tokens: 1200,

648 chunk_overlap_tokens: 200637 chunk_overlap_tokens: 200,

649 }638 },

650 }639 },

651 ]640 },

641 ],

652});642});

653```643```

654 644 


669```659```

670 660 

671```javascript661```javascript

672await client.vector_stores.file_batches.retrieve({662await client.vectorStores.fileBatches.retrieve("vsfb_123", {

673 vector_store_id: "vs_123",663 vector_store_id: "vs_123",

674 batch_id: "vsfb_123"

675});664});

676```665```

677 666 


692```681```

693 682 

694```javascript683```javascript

695await client.vector_stores.file_batches.cancel({684await client.vectorStores.fileBatches.cancel("vsfb_123", {

696 vector_store_id: "vs_123",685 vector_store_id: "vs_123",

697 batch_id: "vsfb_123"

698});686});

699```687```

700 688 


716 704 

717```javascript705```javascript

718await client.vectorStores.fileBatches.listFiles("vsfb_123", {706await client.vectorStores.fileBatches.listFiles("vsfb_123", {

719 vector_store_id: "vs_123"707 vector_store_id: "vs_123",

720});708});

721```709```

722 710 


745```733```

746 734 

747```javascript735```javascript

748await client.vector_stores.files.create(<vector_store_id>, {736await client.vectorStores.files.create("<vector_store_id>", {

749 file_id: "file_123",737 file_id: "file_123",

750 attributes: {738 attributes: {

751 region: "US",739 region: "US",


773```761```

774 762 

775```javascript763```javascript

776await client.vector_stores.update({764await client.vectorStores.update("vs_123", {

777 vector_store_id: "vs_123",

778 expires_after: {765 expires_after: {

779 anchor: "last_active_at",766 anchor: "last_active_at",

780 days: 7,767 days: 7,


853 840 

854const userQuery = "What is the return policy?";841const userQuery = "What is the return policy?";

855 842 

856const results = await client.vectorStores.search({843const results = await client.vectorStores.search(vector_store.id, {

857 vector_store_id: vector_store.id,

858 query: userQuery,844 query: userQuery,

859});845});

860```846```


887```javascript873```javascript

888const formattedResults = formatResults(results.data);874const formattedResults = formatResults(results.data);

889// Join the text content of all results875// Join the text content of all results

890const textSources = results.data.map(result => result.content.map(c => c.text).join('\n')).join('\n');876const textSources = results.data

877 .map((result) => result.content.map((c) => c.text).join("\n"))

878 .join("\n");

891 879 

892const completion = await client.chat.completions.create({880const completion = await client.chat.completions.create({

893 model: "gpt-5.6",881 model: "gpt-5.6",

894 messages: [882 messages: [

895 {883 {

896 role: "developer",884 role: "developer",

897 content: "Produce a concise answer to the query based on the provided sources."885 content:

886 "Produce a concise answer to the query based on the provided sources.",

898 },887 },

899 {888 {

900 role: "user",889 role: "user",

901 content: `Sources: ${formattedResults}\n\nQuery: 'What is the return policy?'`890 content: `Sources: ${formattedResults}\n\nQuery: '${userQuery}'`,

902 }891 },

903 ],892 ],

904});893});

905 894 


931 920 

932```javascript921```javascript

933function formatResults(results) {922function formatResults(results) {

934 let formattedResults = '';923 let formattedResults = "";

935 for (const result of results.data) {924 for (const result of results.data) {

936 let formattedResult = `<result file_id='${result.file_id}' file_name='${result.file_name}'>`;925 let formattedResult = `<result file_id='${result.file_id}' file_name='${result.file_name}'>`;

937 for (const part of result.content) {926 for (const part of result.content) {

Details

46print(transcription.text)46print(transcription.text)

47```47```

48 48 

49```cli49```bash

50openai audio:transcriptions create \50openai audio:transcriptions create \

51 --model gpt-transcribe \51 --model gpt-transcribe \

52 --file /path/to/file/audio.mp3 \52 --file /path/to/file/audio.mp3 \

guides/text.md +1 −1

Details

33print(response.output_text)33print(response.output_text)

34```34```

35 35 

36```cli36```bash

37openai responses create \37openai responses create \

38 --model "gpt-5.6" \38 --model "gpt-5.6" \

39 --input "Write a one-sentence bedtime story about a unicorn." \39 --input "Write a one-sentence bedtime story about a unicorn." \

Details

74 --output speech.mp374 --output speech.mp3

75```75```

76 76 

77```cli77```bash

78openai audio:speech create \78openai audio:speech create \

79 --model gpt-4o-mini-tts \79 --model gpt-4o-mini-tts \

80 --voice coral \80 --voice coral \

Details

61 }'61 }'

62```62```

63 63 

64```cli64```bash

65openai responses:input-tokens count \65openai responses:input-tokens count \

66 --model gpt-5.6 \66 --model gpt-5.6 \

67 --input "Tell me a joke." \67 --input "Tell me a joke." \


121 }'121 }'

122```122```

123 123 

124```cli124```bash

125openai responses:input-tokens count \125openai responses:input-tokens count \

126 --raw-output \126 --raw-output \

127 --transform input_tokens <<'YAML'127 --transform input_tokens <<'YAML'


179 }'179 }'

180```180```

181 181 

182```cli182```bash

183openai responses:input-tokens count \183openai responses:input-tokens count \

184 --raw-output \184 --raw-output \

185 --transform input_tokens <<'YAML'185 --transform input_tokens <<'YAML'


261 }'261 }'

262```262```

263 263 

264```cli264```bash

265openai responses:input-tokens count \265openai responses:input-tokens count \

266 --raw-output \266 --raw-output \

267 --transform input_tokens <<'YAML'267 --transform input_tokens <<'YAML'


356 }'356 }'

357```357```

358 358 

359```cli359```bash

360openai responses:input-tokens count \360openai responses:input-tokens count \

361 --raw-output \361 --raw-output \

362 --transform input_tokens <<'YAML'362 --transform input_tokens <<'YAML'

guides/tools.md +1 −1

Details

48}'48}'

49```49```

50 50 

51```cli51```bash

52openai responses create \52openai responses create \

53 --model gpt-5.6 \53 --model gpt-5.6 \

54 --raw-output \54 --raw-output \

Details

199 199 

200Use the apply patch tool with the Agents SDK200Use the apply patch tool with the Agents SDK

201 201 

202```javascript202```typescript

203import {203import {

204 applyDiff,204 applyDiff,

205 Agent,205 Agent,

Details

1775 1775 

1776### Code-execution harness examples1776### Code-execution harness examples

1777 1777 

1778These minimal JavaScript and Python implementations demonstrate a code-execution harness. They give the model a code-execution tool, keep Playwright objects available to the runtime, return text and screenshots back to the model, and let the model ask the user clarifying questions when it gets blocked.1778These minimal TypeScript and Python implementations demonstrate a code-execution harness. They give the model a code-execution tool, keep Playwright objects available to the runtime, return text and screenshots back to the model, and let the model ask the user clarifying questions when it gets blocked.

1779 1779 

1780Run model-generated code only inside a disposable, least-privilege container or VM with resource and network limits. Language-level sandboxes such as Node.js `vm` and restricted Python global variables are not security boundaries. Keep the sandbox in a separate process and security boundary from the API client, with no shared credentials or host mounts. Enforce time and resource limits inside the sandbox, and terminate the runtime when it exceeds them.1780Run model-generated code only inside a disposable, least-privilege container or VM with resource and network limits. Language-level sandboxes such as Node.js `vm` and restricted Python global variables are not security boundaries. Keep the sandbox in a separate process and security boundary from the API client, with no shared credentials or host mounts. Enforce time and resource limits inside the sandbox, and terminate the runtime when it exceeds them.

1781 1781 


1783 1783 

1784 1784 

1785 1785 

1786JavaScript1786TypeScript

1787 1787 

1788 Code-execution harness1788 Code-execution harness

1789 1789 

1790```javascript1790```typescript

1791// Run with:1791// Run with:

1792// pnpm example -- tools/cua/015-code-execution-harness-example.ts1792// pnpm example -- tools/cua/015-code-execution-harness-example.ts

1793// Override the user prompt with:1793// Override the user prompt with:

Details

1036 1036 

1037Use local shell with Agents SDK1037Use local shell with Agents SDK

1038 1038 

1039```javascript1039```typescript

1040import {1040import {

1041 Agent,1041 Agent,

1042 run,1042 run,

quickstart.md +2 −2

Details

449}'449}'

450```450```

451 451 

452```cli452```bash

453openai responses create \453openai responses create \

454 --model gpt-5.6 \454 --model gpt-5.6 \

455 --raw-output \455 --raw-output \


1005}'1005}'

1006```1006```

1007 1007 

1008```cli1008```bash

1009openai responses create \1009openai responses create \

1010 --model gpt-5.6 \1010 --model gpt-5.6 \

1011 --raw-output \1011 --raw-output \