1# Developer quickstart1# Developer quickstart
2 2
3The OpenAI API provides a simple interface to state-of-the-art AI [models](https://developers.openai.com/api/docs/models) for text generation, natural language processing, computer vision, and more. Get started by creating an API Key and running your first API call. Discover how to generate text, analyze images, build agents, and more.3The OpenAI API provides a consistent interface to state-of-the-art AI [models](https://developers.openai.com/api/docs/models) for text generation, natural language processing, computer vision, and more. Get started by creating an API Key and running your first API call. Discover how to generate text, analyze images, build agents, and more.
4 4
5## Create and export an API key5## Create and export an API key
6 6
25 25
26<div data-content-switcher-pane data-value="macOS">26<div data-content-switcher-pane data-value="macOS">
27 <div class="hidden">macOS / Linux</div>27 <div class="hidden">macOS / Linux</div>
28 Export an environment variable on macOS or Linux systems
29
30```bash
31export OPENAI_API_KEY="your_api_key_here"
32```
33
28 </div>34 </div>
29 <div data-content-switcher-pane data-value="windows" hidden>35 <div data-content-switcher-pane data-value="windows" hidden>
30 <div class="hidden">Windows</div>36 <div class="hidden">Windows</div>
37 Export an environment variable in PowerShell
38
39```bash
40setx OPENAI_API_KEY "your_api_key_here"
41```
42
31 </div>43 </div>
32 44
33 45
34 46
35OpenAI SDKs are configured to automatically read your API key from the system environment.47Each OpenAI SDK automatically reads your API key from the system environment.
36 48
37## Install the OpenAI SDK and Run an API Call49## Install the OpenAI SDK and Run an API Call
38 50
53 <div data-content-switcher-pane data-value="golang" hidden>65 <div data-content-switcher-pane data-value="golang" hidden>
54 <div class="hidden">Go</div>66 <div class="hidden">Go</div>
55 </div>67 </div>
68 <div data-content-switcher-pane data-value="ruby" hidden>
69 <div class="hidden">Ruby</div>
70 </div>
56 71
57 72
58<a73<a
129 144
130<div data-content-switcher-pane data-value="image-url">145<div data-content-switcher-pane data-value="image-url">
131 <div class="hidden">Image URL</div>146 <div class="hidden">Image URL</div>
147 Analyze the content of an image
148
149```javascript
150import OpenAI from "openai";
151const client = new OpenAI();
152
153const response = await client.responses.create({
154 model: "gpt-5.6",
155 input: [
156 {
157 role: "user",
158 content: [
159 {
160 type: "input_text",
161 text: "What is in this image?",
162 },
163 {
164 type: "input_image",
165 image_url: "https://openai-documentation.vercel.app/images/cat_and_otter.png",
166 },
167 ],
168 },
169 ],
170});
171
172console.log(response.output_text);
173```
174
175```bash
176curl "https://api.openai.com/v1/responses" \
177 -H "Content-Type: application/json" \
178 -H "Authorization: Bearer $OPENAI_API_KEY" \
179 -d '{
180 "model": "gpt-5.6",
181 "input": [
182 {
183 "role": "user",
184 "content": [
185 {
186 "type": "input_text",
187 "text": "What is in this image?"
188 },
189 {
190 "type": "input_image",
191 "image_url": "https://openai-documentation.vercel.app/images/cat_and_otter.png"
192 }
193 ]
194 }
195 ]
196}'
197```
198
199```cli
200openai responses create \
201 --model gpt-5.6 \
202 --raw-output \
203 --transform 'output.#(type=="message").content.0.text' <<'YAML'
204input:
205 - role: user
206 content:
207 - type: input_text
208 text: What is in this image?
209 - type: input_image
210 image_url: https://openai-documentation.vercel.app/images/cat_and_otter.png
211YAML
212```
213
214```python
215from openai import OpenAI
216client = OpenAI()
217
218response = client.responses.create(
219 model="gpt-5.6",
220 input=[
221 {
222 "role": "user",
223 "content": [
224 {
225 "type": "input_text",
226 "text": "What teams are playing in this image?",
227 },
228 {
229 "type": "input_image",
230 "image_url": "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg"
231 }
232 ]
233 }
234 ]
235)
236
237print(response.output_text)
238```
239
240```csharp
241using OpenAI.Responses;
242
243string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
244OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
245
246OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
247 ResponseItem.CreateUserMessageItem([
248 ResponseContentPart.CreateInputTextPart("What is in this image?"),
249 ResponseContentPart.CreateInputImagePart(new Uri("https://openai-documentation.vercel.app/images/cat_and_otter.png")),
250 ]),
251]);
252
253Console.WriteLine(response.GetOutputText());
254```
255
256```ruby
257require "openai"
258
259openai = OpenAI::Client.new
260
261response = openai.responses.create(
262 model: "gpt-5.6",
263 input: [
264 {
265 role: "user",
266 content: [
267 {
268 type: "input_text",
269 text: "What teams are playing in this image?"
270 },
271 {
272 type: "input_image",
273 image_url: "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg"
274 }
275 ]
276 }
277 ]
278)
279
280puts(response.output_text)
281```
282
132 </div>283 </div>
133 <div data-content-switcher-pane data-value="file-url" hidden>284 <div data-content-switcher-pane data-value="file-url" hidden>
134 <div class="hidden">File URL</div>285 <div class="hidden">File URL</div>
286 Use a file URL as input
287
288```bash
289curl "https://api.openai.com/v1/responses" \
290 -H "Content-Type: application/json" \
291 -H "Authorization: Bearer $OPENAI_API_KEY" \
292 -d '{
293 "model": "gpt-5.6",
294 "input": [
295 {
296 "role": "user",
297 "content": [
298 {
299 "type": "input_text",
300 "text": "Analyze the letter and provide a summary of the key points."
301 },
302 {
303 "type": "input_file",
304 "file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf"
305 }
306 ]
307 }
308 ]
309 }'
310```
311
312```javascript
313import OpenAI from "openai";
314const client = new OpenAI();
315
316const response = await client.responses.create({
317 model: "gpt-5.6",
318 input: [
319 {
320 role: "user",
321 content: [
322 {
323 type: "input_text",
324 text: "Analyze the letter and provide a summary of the key points.",
325 },
326 {
327 type: "input_file",
328 file_url: "https://www.berkshirehathaway.com/letters/2024ltr.pdf",
329 },
330 ],
331 },
332 ],
333});
334
335console.log(response.output_text);
336```
337
338```python
339from openai import OpenAI
340client = OpenAI()
341
342response = client.responses.create(
343 model="gpt-5.6",
344 input=[
345 {
346 "role": "user",
347 "content": [
348 {
349 "type": "input_text",
350 "text": "Analyze the letter and provide a summary of the key points.",
351 },
352 {
353 "type": "input_file",
354 "file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf",
355 },
356 ],
357 },
358 ]
359)
360
361print(response.output_text)
362```
363
364```ruby
365require "openai"
366
367openai = OpenAI::Client.new
368
369response = openai.responses.create(
370 model: "gpt-5.6",
371 input: [
372 {
373 role: "user",
374 content: [
375 {
376 type: "input_text",
377 text: "Analyze the letter and provide a summary of the key points."
378 },
379 {
380 type: "input_file",
381 file_url: "https://www.berkshirehathaway.com/letters/2024ltr.pdf"
382 }
383 ]
384 }
385 ]
386)
387
388puts(response.output_text)
389```
390
391```csharp
392using OpenAI.Files;
393using OpenAI.Responses;
394
395string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
396OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
397
398using HttpClient http = new();
399using Stream stream = await http.GetStreamAsync("https://www.berkshirehathaway.com/letters/2024ltr.pdf");
400OpenAIFileClient files = new(key);
401OpenAIFile file = files.UploadFile(stream, "2024ltr.pdf", FileUploadPurpose.UserData);
402
403OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
404 ResponseItem.CreateUserMessageItem([
405 ResponseContentPart.CreateInputTextPart("Analyze the letter and provide a summary of the key points."),
406 ResponseContentPart.CreateInputFilePart(file.Id),
407 ]),
408]);
409
410Console.WriteLine(response.GetOutputText());
411```
412
135 </div>413 </div>
136 <div data-content-switcher-pane data-value="file-upload" hidden>414 <div data-content-switcher-pane data-value="file-upload" hidden>
137 <div class="hidden">Upload file</div>415 <div class="hidden">Upload file</div>
416 Upload a file and use it as input
417
418```bash
419curl https://api.openai.com/v1/files \
420 -H "Authorization: Bearer $OPENAI_API_KEY" \
421 -F purpose="user_data" \
422 -F file="@draconomicon.pdf"
423
424curl "https://api.openai.com/v1/responses" \
425 -H "Content-Type: application/json" \
426 -H "Authorization: Bearer $OPENAI_API_KEY" \
427 -d '{
428 "model": "gpt-5.6",
429 "input": [
430 {
431 "role": "user",
432 "content": [
433 {
434 "type": "input_file",
435 "file_id": "file-6F2ksmvXxt4VdoqmHRw6kL"
436 },
437 {
438 "type": "input_text",
439 "text": "What is the first dragon in the book?"
440 }
441 ]
442 }
443 ]
444 }'
445```
446
447```javascript
448import fs from "fs";
449import OpenAI from "openai";
450const client = new OpenAI();
451
452const file = await client.files.create({
453 file: fs.createReadStream("draconomicon.pdf"),
454 purpose: "user_data",
455});
456
457const response = await client.responses.create({
458 model: "gpt-5.6",
459 input: [
460 {
461 role: "user",
462 content: [
463 {
464 type: "input_file",
465 file_id: file.id,
466 },
467 {
468 type: "input_text",
469 text: "What is the first dragon in the book?",
470 },
471 ],
472 },
473 ],
474});
475
476console.log(response.output_text);
477```
478
479```python
480from openai import OpenAI
481client = OpenAI()
482
483file = client.files.create(
484 file=open("draconomicon.pdf", "rb"),
485 purpose="user_data"
486)
487
488response = client.responses.create(
489 model="gpt-5.6",
490 input=[
491 {
492 "role": "user",
493 "content": [
494 {
495 "type": "input_file",
496 "file_id": file.id,
497 },
498 {
499 "type": "input_text",
500 "text": "What is the first dragon in the book?",
501 },
502 ]
503 }
504 ]
505)
506
507print(response.output_text)
508```
509
510```ruby
511require "openai"
512
513openai = OpenAI::Client.new
514
515file = openai.files.create(
516 file: File.open("draconomicon.pdf", "rb"),
517 purpose: "user_data"
518)
519
520response = openai.responses.create(
521 model: "gpt-5.6",
522 input: [
523 {
524 role: "user",
525 content: [
526 {type: "input_file", file_id: file.id},
527 {type: "input_text", text: "What is the first dragon in the book?"}
528 ]
529 }
530 ]
531)
532
533puts(response.output_text)
534```
535
536```csharp
537using OpenAI.Files;
538using OpenAI.Responses;
539
540string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
541OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
542
543OpenAIFileClient files = new(key);
544OpenAIFile file = files.UploadFile("draconomicon.pdf", FileUploadPurpose.UserData);
545
546OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
547 ResponseItem.CreateUserMessageItem([
548 ResponseContentPart.CreateInputFilePart(file.Id),
549 ResponseContentPart.CreateInputTextPart("What is the first dragon in the book?"),
550 ]),
551]);
552
553Console.WriteLine(response.GetOutputText());
554```
555
138 </div>556 </div>
139 557
140 558
163 581
164<div data-content-switcher-pane data-value="web-search">582<div data-content-switcher-pane data-value="web-search">
165 <div class="hidden">Web search</div>583 <div class="hidden">Web search</div>
584 Use web search in a response
585
586```javascript
587import OpenAI from "openai";
588const client = new OpenAI();
589
590const response = await client.responses.create({
591 model: "gpt-5.6",
592 tools: [
593 { type: "web_search" },
594 ],
595 input: "What was a positive news story from today?",
596});
597
598console.log(response.output_text);
599```
600
601```python
602from openai import OpenAI
603client = OpenAI()
604
605response = client.responses.create(
606 model="gpt-5.6",
607 tools=[{"type": "web_search"}],
608 input="What was a positive news story from today?"
609)
610
611print(response.output_text)
612```
613
614```bash
615curl "https://api.openai.com/v1/responses" \
616 -H "Content-Type: application/json" \
617 -H "Authorization: Bearer $OPENAI_API_KEY" \
618 -d '{
619 "model": "gpt-5.6",
620 "tools": [{"type": "web_search"}],
621 "input": "what was a positive news story from today?"
622}'
623```
624
625```cli
626openai responses create \
627 --model gpt-5.6 \
628 --raw-output \
629 --transform 'output.#(type=="message").content.0.text' <<'YAML'
630tools:
631 - type: web_search
632input: What was a positive news story from today?
633YAML
634```
635
636```csharp
637using OpenAI.Responses;
638
639string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
640OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
641
642ResponseCreationOptions options = new();
643options.Tools.Add(ResponseTool.CreateWebSearchTool());
644
645OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
646 ResponseItem.CreateUserMessageItem([
647 ResponseContentPart.CreateInputTextPart("What was a positive news story from today?"),
648 ]),
649], options);
650
651Console.WriteLine(response.GetOutputText());
652```
653
654```ruby
655require "openai"
656
657openai = OpenAI::Client.new
658
659response = openai.responses.create(
660 model: "gpt-5.6",
661 tools: [{type: "web_search"}],
662 input: "What was a positive news story from today?"
663)
664
665puts(response.output_text)
666```
667
166 </div>668 </div>
167 <div data-content-switcher-pane data-value="file-search" hidden>669 <div data-content-switcher-pane data-value="file-search" hidden>
168 <div class="hidden">File search</div>670 <div class="hidden">File search</div>
671 Search your files in a response
672
673```python
674from openai import OpenAI
675client = OpenAI()
676
677response = client.responses.create(
678 model="gpt-5.6",
679 input="What is deep research by OpenAI?",
680 tools=[{
681 "type": "file_search",
682 "vector_store_ids": ["<vector_store_id>"]
683 }]
684)
685print(response)
686```
687
688```javascript
689import OpenAI from "openai";
690const openai = new OpenAI();
691
692const response = await openai.responses.create({
693 model: "gpt-5.6",
694 input: "What is deep research by OpenAI?",
695 tools: [
696 {
697 type: "file_search",
698 vector_store_ids: ["<vector_store_id>"],
699 },
700 ],
701});
702console.log(response);
703```
704
705```csharp
706using OpenAI.Responses;
707
708string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
709OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
710
711ResponseCreationOptions options = new();
712options.Tools.Add(ResponseTool.CreateFileSearchTool(["<vector_store_id>"]));
713
714OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
715 ResponseItem.CreateUserMessageItem([
716 ResponseContentPart.CreateInputTextPart("What is deep research by OpenAI?"),
717 ]),
718], options);
719
720Console.WriteLine(response.GetOutputText());
721```
722
723```ruby
724require "openai"
725
726openai = OpenAI::Client.new
727
728response = openai.responses.create(
729 model: "gpt-5.6",
730 input: "What is deep research by OpenAI?",
731 tools: [
732 {
733 type: "file_search",
734 vector_store_ids: ["<vector_store_id>"]
735 }
736 ]
737)
738
739puts(response)
740```
741
169 </div>742 </div>
170 <div data-content-switcher-pane data-value="code-interpreter" hidden>743 <div data-content-switcher-pane data-value="code-interpreter" hidden>
171 <div class="hidden">Code Interpreter</div>744 <div class="hidden">Code Interpreter</div>
745 Use Code Interpreter in a response
746
747```javascript
748import OpenAI from "openai";
749const client = new OpenAI();
750
751const response = await client.responses.create({
752 model: "gpt-5.6",
753 instructions: "You are a personal math tutor. When asked a math question, write and run code to answer the question.",
754 tools: [
755 {
756 type: "code_interpreter",
757 container: { type: "auto" },
758 },
759 ],
760 input: "I need to solve the equation 3x + 11 = 14. Can you help me?",
761});
762
763console.log(response.output_text);
764```
765
766```python
767from openai import OpenAI
768client = OpenAI()
769
770response = client.responses.create(
771 model="gpt-5.6",
772 instructions="You are a personal math tutor. When asked a math question, write and run code to answer the question.",
773 tools=[{
774 "type": "code_interpreter",
775 "container": {"type": "auto"}
776 }],
777 input="I need to solve the equation 3x + 11 = 14. Can you help me?"
778)
779
780print(response.output_text)
781```
782
783```bash
784curl https://api.openai.com/v1/responses \
785 -H "Content-Type: application/json" \
786 -H "Authorization: Bearer $OPENAI_API_KEY" \
787 -d '{
788 "model": "gpt-5.6",
789 "instructions": "You are a personal math tutor. When asked a math question, write and run code to answer the question.",
790 "tools": [
791 {
792 "type": "code_interpreter",
793 "container": { "type": "auto" }
794 }
795 ],
796 "input": "I need to solve the equation 3x + 11 = 14. Can you help me?"
797 }'
798```
799
800```ruby
801require "openai"
802
803openai = OpenAI::Client.new
804
805response = openai.responses.create(
806 model: "gpt-5.6",
807 instructions: "You are a personal math tutor. When asked a math question, write and run code to answer the question.",
808 tools: [
809 {
810 type: "code_interpreter",
811 container: {type: "auto"}
812 }
813 ],
814 input: "I need to solve the equation 3x + 11 = 14. Can you help me?"
815)
816
817puts(response.output_text)
818```
819
172 </div>820 </div>
173 <div data-content-switcher-pane data-value="function-calling" hidden>821 <div data-content-switcher-pane data-value="function-calling" hidden>
174 <div class="hidden">Function calling</div>822 <div class="hidden">Function calling</div>
823 Call your own function
824
825```javascript
826import OpenAI from "openai";
827const client = new OpenAI();
828
829const tools = [
830 {
831 type: "function",
832 name: "get_weather",
833 description: "Get current temperature for a given location.",
834 parameters: {
835 type: "object",
836 properties: {
837 location: {
838 type: "string",
839 description: "City and country e.g. Bogotá, Colombia",
840 },
841 },
842 required: ["location"],
843 additionalProperties: false,
844 },
845 strict: true,
846 },
847];
848
849const response = await client.responses.create({
850 model: "gpt-5.6",
851 input: [
852 { role: "user", content: "What is the weather like in Paris today?" },
853 ],
854 tools,
855});
856
857console.log(response.output[0].to_json());
858```
859
860```python
861from openai import OpenAI
862
863client = OpenAI()
864
865tools = [
866 {
867 "type": "function",
868 "name": "get_weather",
869 "description": "Get current temperature for a given location.",
870 "parameters": {
871 "type": "object",
872 "properties": {
873 "location": {
874 "type": "string",
875 "description": "City and country e.g. Bogotá, Colombia",
876 }
877 },
878 "required": ["location"],
879 "additionalProperties": False,
880 },
881 "strict": True,
882 },
883]
884
885response = client.responses.create(
886 model="gpt-5.6",
887 input=[
888 {"role": "user", "content": "What is the weather like in Paris today?"},
889 ],
890 tools=tools,
891)
892
893print(response.output[0].to_json())
894```
895
896```csharp
897using System.Text.Json;
898using OpenAI.Responses;
899
900string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
901OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
902
903ResponseCreationOptions options = new();
904options.Tools.Add(ResponseTool.CreateFunctionTool(
905 functionName: "get_weather",
906 functionDescription: "Get current temperature for a given location.",
907 functionParameters: BinaryData.FromObjectAsJson(new
908 {
909 type = "object",
910 properties = new
911 {
912 location = new
913 {
914 type = "string",
915 description = "City and country e.g. Bogotá, Colombia"
916 }
917 },
918 required = new[] { "location" },
919 additionalProperties = false
920 }),
921 strictModeEnabled: true
922 )
923);
924
925OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
926 ResponseItem.CreateUserMessageItem([
927 ResponseContentPart.CreateInputTextPart("What is the weather like in Paris today?")
928 ])
929], options);
930
931Console.WriteLine(JsonSerializer.Serialize(response.OutputItems[0]));
932```
933
934```bash
935curl -X POST https://api.openai.com/v1/responses \
936 -H "Authorization: Bearer $OPENAI_API_KEY" \
937 -H "Content-Type: application/json" \
938 -d '{
939 "model": "gpt-5.6",
940 "input": [
941 {"role": "user", "content": "What is the weather like in Paris today?"}
942 ],
943 "tools": [
944 {
945 "type": "function",
946 "name": "get_weather",
947 "description": "Get current temperature for a given location.",
948 "parameters": {
949 "type": "object",
950 "properties": {
951 "location": {
952 "type": "string",
953 "description": "City and country e.g. Bogotá, Colombia"
954 }
955 },
956 "required": ["location"],
957 "additionalProperties": false
958 },
959 "strict": true
960 }
961 ]
962 }'
963```
964
965```ruby
966require "openai"
967
968openai = OpenAI::Client.new
969
970tools = [
971 {
972 type: "function",
973 name: "get_weather",
974 description: "Get current temperature for a given location.",
975 parameters: {
976 type: "object",
977 properties: {
978 location: {
979 type: "string",
980 description: "City and country e.g. Bogotá, Colombia"
981 }
982 },
983 required: ["location"],
984 additionalProperties: false
985 },
986 strict: true
987 }
988]
989
990response = openai.responses.create(
991 model: "gpt-5.6",
992 input: [
993 {role: "user", content: "What is the weather like in Paris today?"}
994 ],
995 tools: tools
996)
997
998puts(response.output.first.to_json)
999```
1000
175 </div>1001 </div>
176 <div data-content-switcher-pane data-value="remote-mcp" hidden>1002 <div data-content-switcher-pane data-value="remote-mcp" hidden>
177 <div class="hidden">Remote MCP</div>1003 <div class="hidden">Remote MCP</div>
1004 Call a remote MCP server
1005
1006```bash
1007curl https://api.openai.com/v1/responses \
1008-H "Content-Type: application/json" \
1009-H "Authorization: Bearer $OPENAI_API_KEY" \
1010-d '{
1011 "model": "gpt-5.6",
1012 "tools": [
1013 {
1014 "type": "mcp",
1015 "server_label": "dmcp",
1016 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
1017 "server_url": "https://dmcp-server.deno.dev/mcp",
1018 "require_approval": "never"
1019 }
1020 ],
1021 "input": "Roll 2d4+1"
1022 }'
1023```
1024
1025```javascript
1026import OpenAI from "openai";
1027const client = new OpenAI();
1028
1029const resp = await client.responses.create({
1030 model: "gpt-5.6",
1031 tools: [
1032 {
1033 type: "mcp",
1034 server_label: "dmcp",
1035 server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",
1036 server_url: "https://dmcp-server.deno.dev/mcp",
1037 require_approval: "never",
1038 },
1039 ],
1040 input: "Roll 2d4+1",
1041});
1042
1043console.log(resp.output_text);
1044```
1045
1046```python
1047from openai import OpenAI
1048
1049client = OpenAI()
1050
1051resp = client.responses.create(
1052 model="gpt-5.6",
1053 tools=[
1054 {
1055 "type": "mcp",
1056 "server_label": "dmcp",
1057 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
1058 "server_url": "https://dmcp-server.deno.dev/mcp",
1059 "require_approval": "never",
1060 },
1061 ],
1062 input="Roll 2d4+1",
1063)
1064
1065print(resp.output_text)
1066```
1067
1068```csharp
1069using OpenAI.Responses;
1070
1071string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
1072OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
1073
1074ResponseCreationOptions options = new();
1075options.Tools.Add(ResponseTool.CreateMcpTool(
1076 serverLabel: "dmcp",
1077 serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),
1078 toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
1079));
1080
1081OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
1082 ResponseItem.CreateUserMessageItem([
1083 ResponseContentPart.CreateInputTextPart("Roll 2d4+1")
1084 ])
1085], options);
1086
1087Console.WriteLine(response.GetOutputText());
1088```
1089
1090```ruby
1091require "openai"
1092
1093openai = OpenAI::Client.new
1094
1095response = openai.responses.create(
1096 model: "gpt-5.6",
1097 tools: [
1098 {
1099 type: "mcp",
1100 server_label: "dmcp",
1101 server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",
1102 server_url: "https://dmcp-server.deno.dev/mcp",
1103 require_approval: "never"
1104 }
1105 ],
1106 input: "Roll 2d4+1"
1107)
1108
1109puts(response.output_text)
1110```
1111
178 </div>1112 </div>
179 1113
180 1114
195 1129
196](https://developers.openai.com/api/docs/guides/function-calling)1130](https://developers.openai.com/api/docs/guides/function-calling)
197 1131
198## Stream responses and build realtime apps1132## Stream responses and build real-time apps
1133
1134Use server‑sent [streaming events](https://developers.openai.com/api/docs/guides/streaming-responses) to show results as they’re generated, or use the [Realtime API](https://developers.openai.com/api/docs/guides/realtime) for interactive voice apps and apps with text, audio, and image inputs.
1135
1136Stream server-sent events from the API
1137
1138```javascript
1139import { OpenAI } from "openai";
1140const client = new OpenAI();
1141
1142const stream = await client.responses.create({
1143 model: "gpt-5.6",
1144 input: [
1145 {
1146 role: "user",
1147 content: "Say 'double bubble bath' ten times fast.",
1148 },
1149 ],
1150 stream: true,
1151});
1152
1153for await (const event of stream) {
1154 console.log(event);
1155}
1156```
1157
1158```python
1159from openai import OpenAI
1160client = OpenAI()
1161
1162stream = client.responses.create(
1163 model="gpt-5.6",
1164 input=[
1165 {
1166 "role": "user",
1167 "content": "Say 'double bubble bath' ten times fast.",
1168 },
1169 ],
1170 stream=True,
1171)
1172
1173for event in stream:
1174 print(event)
1175```
1176
1177```csharp
1178using OpenAI.Responses;
1179
1180string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
1181OpenAIResponseClient client = new(model: "gpt-5.6", apiKey: key);
1182
1183var responses = client.CreateResponseStreamingAsync([
1184 ResponseItem.CreateUserMessageItem([
1185 ResponseContentPart.CreateInputTextPart("Say 'double bubble bath' ten times fast."),
1186 ]),
1187]);
1188
1189await foreach (var response in responses)
1190{
1191 if (response is StreamingResponseOutputTextDeltaUpdate delta)
1192 {
1193 Console.Write(delta.Delta);
1194 }
1195}
1196```
1197
1198```ruby
1199require "openai"
1200
1201openai = OpenAI::Client.new
1202
1203stream = openai.responses.stream(
1204 model: "gpt-5.6",
1205 input: [
1206 {
1207 role: "user",
1208 content: "Say 'double bubble bath' ten times fast."
1209 }
1210 ]
1211)
1212
1213stream.each do |event|
1214 puts(event)
1215end
1216```
199 1217
200Use server‑sent [streaming events](https://developers.openai.com/api/docs/guides/streaming-responses) to show results as they’re generated, or the [Realtime API](https://developers.openai.com/api/docs/guides/realtime) for interactive voice and multimodal apps.
201 1218
202[1219[
203 1220
217 1234
218## Build agents1235## Build agents
219 1236
220Use the OpenAI platform to build [agents](https://developers.openai.com/api/docs/guides/agents) capable of taking action—like [controlling computers](https://developers.openai.com/api/docs/guides/tools-computer-use)—on behalf of your users. Use the [Agents SDK](https://developers.openai.com/api/docs/guides/agents) to create orchestration logic on the backend.1237Use the OpenAI platform to build [agents](https://developers.openai.com/api/docs/guides/agents) capable of taking action—like [controlling computers](https://developers.openai.com/api/docs/guides/tools-computer-use)—on behalf of your users. Use the [Agents SDK](https://developers.openai.com/api/docs/guides/agents) to create orchestration logic on your server.
1238
1239Build a language triage agent
1240
1241```javascript
1242import { Agent, run } from '@openai/agents';
1243
1244const spanishAgent = new Agent({
1245 name: 'Spanish agent',
1246 instructions: 'You only speak Spanish.',
1247});
1248
1249const englishAgent = new Agent({
1250 name: 'English agent',
1251 instructions: 'You only speak English',
1252});
1253
1254const triageAgent = new Agent({
1255 name: 'Triage agent',
1256 instructions:
1257 'Handoff to the appropriate agent based on the language of the request.',
1258 handoffs: [spanishAgent, englishAgent],
1259});
1260
1261const result = await run(triageAgent, 'Hola, ¿cómo estás?');
1262console.log(result.finalOutput);
1263```
1264
1265```python
1266from agents import Agent, Runner
1267import asyncio
1268
1269spanish_agent = Agent(
1270 name="Spanish agent",
1271 instructions="You only speak Spanish.",
1272)
1273
1274english_agent = Agent(
1275 name="English agent",
1276 instructions="You only speak English",
1277)
1278
1279triage_agent = Agent(
1280 name="Triage agent",
1281 instructions="Handoff to the appropriate agent based on the language of the request.",
1282 handoffs=[spanish_agent, english_agent],
1283)
1284
1285
1286async def main():
1287 result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
1288 print(result.final_output)
1289
1290
1291if __name__ == "__main__":
1292 asyncio.run(main())
1293```
1294
221 1295
222[1296[
223 1297