Repository Public
1# Developer quickstart23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45The 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.67## Create and export an API key891011StatsigClient.logEvent("quickstart_create_api_key_click", null, null)12 }13>14 Create an API Key151617181920Before you begin, create an API key in the dashboard, which you'll use to21securely [access the API](https://developers.openai.com/api/reference/overview). Store the key22in a safe location, like a [`.zshrc`23file](https://www.freecodecamp.org/news/how-do-zsh-configuration-files-work/) or24another text file on your computer. Once you've generated an API key, export it25as an [environment variable](https://en.wikipedia.org/wiki/Environment_variable)26in your terminal.27282930macOS / Linux3132 Export an environment variable on macOS or Linux systems3334```bash35export OPENAI_API_KEY="your_api_key_here"36```3738 3940 4142 43Windows4445 Export an environment variable in PowerShell4647```bash48setx OPENAI_API_KEY "your_api_key_here"49```50515253Each OpenAI SDK automatically reads your API key from the system environment.5455## Install the OpenAI SDK and Run an API Call56575859JavaScript6061 6263To use the OpenAI API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official [OpenAI SDK for TypeScript and JavaScript](https://github.com/openai/openai-node). Get started by installing the SDK using [npm](https://www.npmjs.com/) or your preferred package manager:6465Install the OpenAI SDK with npm6667```bash68npm install openai69```707172With the OpenAI SDK installed, create a file called `example.mjs` and copy the example code into it:7374Test a basic API request7576```javascript77import OpenAI from "openai";78const client = new OpenAI();7980const response = await client.responses.create({81 model: "gpt-6-astra",82 input: "Write a one-sentence bedtime story about a unicorn.",83});8485console.log(response.output_text);86```878889Execute the code with `node example.mjs` (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.9091[Learn more on GitHub92939495 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-node)969798 99100 101102 103Python104105 106107To use the OpenAI API in Python, you can use the official [OpenAI SDK for Python](https://github.com/openai/openai-python). Get started by installing the SDK using [pip](https://pypi.org/project/pip/):108109Install the OpenAI SDK with pip110111```bash112pip install openai113```114115116With the OpenAI SDK installed, create a file called `example.py` and copy the example code into it:117118Test a basic API request119120```python121from openai import OpenAI122123client = OpenAI()124125response = client.responses.create(126 model="gpt-6-astra",127 input="Write a one-sentence bedtime story about a unicorn.",128)129130print(response.output_text)131```132133134Execute the code with `python example.py`. In a few moments, you should see the output of your API request.135136[Learn more on GitHub137138139140 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-python)141142143 144145 146147 148.NET149150 151152In collaboration with Microsoft, OpenAI provides an officially supported API client for C#. You can install it with the .NET CLI from [NuGet](https://www.nuget.org/).153154```155dotnet add package OpenAI156```157158A simple API request to the [Responses API](https://developers.openai.com/api/reference/resources/responses) would look like this:159160Test a basic API request161162```csharp163using OpenAI.Responses;164#pragma warning disable OPENAI001165166string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;167ResponsesClient client = new(key);168169ResponseResult response = await client.CreateResponseAsync(170 "gpt-6-astra",171 "Say 'this is a test.'"172);173174Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");175```176177178 179180 181182 183Java184185 186187OpenAI provides an API helper for the Java programming language, currently in beta. You can include the Maven dependency using the following configuration:188189```xml190<dependency>191 <groupId>com.openai</groupId>192 <artifactId>openai-java</artifactId>193 <version>4.65.0</version>194</dependency>195```196197198A simple API request to [Responses API](https://developers.openai.com/api/reference/resources/responses) would look like this:199200Test a basic API request201202```java203import com.openai.client.OpenAIClient;204import com.openai.client.okhttp.OpenAIOkHttpClient;205import com.openai.models.responses.Response;206import com.openai.models.responses.ResponseCreateParams;207208public class Main {209 public static void main(String[] args) {210 OpenAIClient client = OpenAIOkHttpClient.fromEnv();211212 ResponseCreateParams params =213 ResponseCreateParams.builder().input("Say this is a test").model("gpt-6-astra").build();214215 Response response = client.responses().create(params);216 response.output().stream()217 .flatMap(item -> item.message().stream())218 .flatMap(message -> message.content().stream())219 .flatMap(content -> content.outputText().stream())220 .forEach(outputText -> System.out.println(outputText.text()));221 }222}223```224225226To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!227228[Learn more on GitHub229230231232 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-java)233234235 236237 238239 240Go241242 243244OpenAI provides an API helper for the Go programming language, currently in beta. You can import the library using the code below:245246```go247import (248 "github.com/openai/openai-go/v3" // imported as openai249)250```251252253A first API request to the [Responses API](https://developers.openai.com/api/reference/resources/responses) would look like this:254255Test a basic API request256257```go258package main259260import (261 "context"262 "fmt"263264 "github.com/openai/openai-go/v3"265 "github.com/openai/openai-go/v3/responses"266)267268func main() {269 client := openai.NewClient()270271 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{272 Model: "gpt-6-astra",273 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Say this is a test")},274 })275 if err != nil {276 panic(err.Error())277 }278279 fmt.Println(resp.OutputText())280}281```282283284To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!285286[Learn more on GitHub287288289290 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-go)291292293 294295 296297 298Ruby299300 301302To use the OpenAI API in Ruby, you can use the official [OpenAI SDK for Ruby](https://github.com/openai/openai-ruby). Get started by adding the gem to your application:303304Install the OpenAI SDK with Bundler305306```ruby307gem "openai"308```309310311With the OpenAI SDK installed, create a file called `example.rb` and copy the example code into it:312313Test a basic API request314315```ruby316require "openai"317318openai = OpenAI::Client.new319320response = openai.responses.create(321 model: "gpt-6-astra",322 input: "Write a one-sentence bedtime story about a unicorn."323)324325puts(response.output_text)326```327328329Execute the code with `ruby example.rb`. In a few moments, you should see the output of your API request.330331[Learn more on GitHub332333334335 Discover more SDK capabilities and options on the library's GitHub README.](https://github.com/openai/openai-ruby)336337338[Responses starter app339340341342 Start building with the Responses API.](https://github.com/openai/openai-responses-starter-app)343344[Text generation and prompting345346347348 Learn more about prompting, message roles, and building conversational apps.](https://developers.openai.com/api/docs/guides/text)349350## Add credits to keep building351352353354StatsigClient.logEvent("quickstart_add_credits_billing_click", null, null)355 }356>357 Go to billing358359360361Congrats on running a free test API request! Start building real applications with higher limits and use [our models](https://developers.openai.com/api/docs/models) to generate text, audio, images, videos and more.362363364365366 Explore tools and docs designed to help you ship faster:367368369[StatsigClient.logEvent(370 "quickstart_add_credits_chat_playground_click",371 null,372 null373 )374 }375>376 Chat Playground377378379380 Build & test conversational prompts and embed them in your app.](https://platform.openai.com/chat)381[Build agents382383384385 Use the Agents SDK to build, run, and observe agent workflows.](https://developers.openai.com/api/docs/guides/agents)386387## Analyze images and files388389Send image URLs, uploaded files, or PDF documents directly to the model to extract text, classify content, or detect visual elements.390391392393Image URL394395 Analyze the content of an image396397```javascript398import OpenAI from "openai";399const client = new OpenAI();400401const response = await client.responses.create({402 model: "gpt-6-astra",403 input: [404 {405 role: "user",406 content: [407 {408 type: "input_text",409 text: "What is in this image?",410 },411 {412 type: "input_image",413 image_url:414 "https://openai-documentation.vercel.app/images/cat_and_otter.png",415 detail: "auto",416 },417 ],418 },419 ],420});421422console.log(response.output_text);423```424425```python426from openai import OpenAI427428client = OpenAI()429430response = client.responses.create(431 model="gpt-6-astra",432 input=[433 {434 "role": "user",435 "content": [436 {437 "type": "input_text",438 "text": "What teams are playing in this image?",439 },440 {441 "type": "input_image",442 "image_url": "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg",443 },444 ],445 }446 ],447)448449print(response.output_text)450```451452```go453package main454455import (456 "context"457 "fmt"458459 "github.com/openai/openai-go/v3"460 "github.com/openai/openai-go/v3/responses"461)462463func main() {464 client := openai.NewClient()465 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{466 Model: "gpt-6-astra",467 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{468 responses.ResponseInputItemParamOfMessage(469 responses.ResponseInputMessageContentListParam{470 responses.ResponseInputContentParamOfInputText("What is in this image?"),471 {OfInputImage: &responses.ResponseInputImageParam{472 Detail: responses.ResponseInputImageDetailAuto,473 ImageURL: openai.String("https://openai-documentation.vercel.app/images/cat_and_otter.png"),474 }},475 },476 responses.EasyInputMessageRoleUser,477 ),478 }},479 })480 if err != nil {481 panic(err)482 }483 fmt.Println(response.OutputText())484}485```486487```java488import com.openai.client.OpenAIClient;489import com.openai.client.okhttp.OpenAIOkHttpClient;490import com.openai.models.responses.ResponseCreateParams;491import com.openai.models.responses.ResponseInputImage;492import com.openai.models.responses.ResponseInputItem;493import java.util.List;494495ResponseInputItem imageInput =496 ResponseInputItem.ofMessage(497 ResponseInputItem.Message.builder()498 .role(ResponseInputItem.Message.Role.USER)499 .addInputTextContent("What teams are playing in this image?")500 .addContent(501 ResponseInputImage.builder()502 .detail(ResponseInputImage.Detail.AUTO)503 .imageUrl(504 "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg")505 .build())506 .build());507508ResponseCreateParams params =509 ResponseCreateParams.builder()510 .model("gpt-6-astra")511 .inputOfResponse(List.of(imageInput))512 .build();513514client.responses().create(params).output().stream()515 .flatMap(item -> item.message().stream())516 .flatMap(message -> message.content().stream())517 .flatMap(content -> content.outputText().stream())518 .forEach(text -> System.out.println(text.text()));519```520521```csharp522using OpenAI.Responses;523#pragma warning disable OPENAI001524525string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;526ResponsesClient client = new(key);527528Uri imageUrl = new(529 "https://openai-documentation.vercel.app/images/cat_and_otter.png"530);531532ResponseResult response = await client.CreateResponseAsync(533 "gpt-6-astra",534 [535 ResponseItem.CreateUserMessageItem(536 [537 ResponseContentPart.CreateInputTextPart("What is in this image?"),538 ResponseContentPart.CreateInputImagePart(imageUrl),539 ]540 ),541 ]542);543544Console.WriteLine(response.GetOutputText());545```546547```ruby548require "openai"549550openai = OpenAI::Client.new551552response = openai.responses.create(553 model: "gpt-6-astra",554 input: [555 {556 role: "user",557 content: [558 {559 type: "input_text",560 text: "What teams are playing in this image?"561 },562 {563 type: "input_image",564 image_url: "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg"565 }566 ]567 }568 ]569)570571puts(response.output_text)572```573574```bash575curl "https://api.openai.com/v1/responses" \576 -H "Content-Type: application/json" \577 -H "Authorization: Bearer $OPENAI_API_KEY" \578 -d '{579 "model": "gpt-6-astra",580 "input": [581 {582 "role": "user",583 "content": [584 {585 "type": "input_text",586 "text": "What is in this image?"587 },588 {589 "type": "input_image",590 "image_url": "https://openai-documentation.vercel.app/images/cat_and_otter.png"591 }592 ]593 }594 ]595}'596```597598```bash599openai responses create \600 --model gpt-6-astra \601 --raw-output \602 --transform 'output.#(type=="message").content.0.text' <<'YAML'603input:604 - role: user605 content:606 - type: input_text607 text: What is in this image?608 - type: input_image609 image_url: https://openai-documentation.vercel.app/images/cat_and_otter.png610YAML611```612613 614615 616617 618File URL619620 Use a file URL as input621622```javascript623import OpenAI from "openai";624const client = new OpenAI();625626const response = await client.responses.create({627 model: "gpt-6-astra",628 input: [629 {630 role: "user",631 content: [632 {633 type: "input_text",634 text: "Analyze the letter and provide a summary of the key points.",635 },636 {637 type: "input_file",638 file_url: "https://www.berkshirehathaway.com/letters/2024ltr.pdf",639 },640 ],641 },642 ],643});644645console.log(response.output_text);646```647648```python649from openai import OpenAI650651client = OpenAI()652653response = client.responses.create(654 model="gpt-6-astra",655 input=[656 {657 "role": "user",658 "content": [659 {660 "type": "input_text",661 "text": "Analyze the letter and provide a summary of the key points.",662 },663 {664 "type": "input_file",665 "file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf",666 },667 ],668 },669 ],670)671672print(response.output_text)673```674675```go676package main677678import (679 "context"680 "fmt"681682 "github.com/openai/openai-go/v3"683 "github.com/openai/openai-go/v3/responses"684)685686func main() {687 client := openai.NewClient()688689 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{690 Model: "gpt-6-astra",691 Input: responses.ResponseNewParamsInputUnion{692 OfInputItemList: responses.ResponseInputParam{693 responses.ResponseInputItemParamOfMessage(694 responses.ResponseInputMessageContentListParam{695 responses.ResponseInputContentParamOfInputText(696 "Analyze the letter and provide a summary of the key points.",697 ),698 {699 OfInputFile: &responses.ResponseInputFileParam{700 FileURL: openai.String(701 "https://www.berkshirehathaway.com/letters/2024ltr.pdf",702 ),703 },704 },705 },706 responses.EasyInputMessageRoleUser,707 ),708 },709 },710 })711 if err != nil {712 panic(err)713 }714715 fmt.Println(response.OutputText())716}717```718719```java720import com.openai.client.OpenAIClient;721import com.openai.client.okhttp.OpenAIOkHttpClient;722import com.openai.models.responses.ResponseCreateParams;723import com.openai.models.responses.ResponseInputFile;724import com.openai.models.responses.ResponseInputItem;725import java.util.List;726727ResponseCreateParams params =728 ResponseCreateParams.builder()729 .model("gpt-6-astra")730 .inputOfResponse(731 List.of(732 ResponseInputItem.ofMessage(733 ResponseInputItem.Message.builder()734 .role(ResponseInputItem.Message.Role.USER)735 .addInputTextContent(736 "Analyze the letter and provide a summary of the key points.")737 .addContent(738 ResponseInputFile.builder()739 .fileUrl(740 "https://www.berkshirehathaway.com/letters/2024ltr.pdf")741 .build())742 .build())))743 .build();744745client.responses().create(params).output().stream()746 .flatMap(item -> item.message().stream())747 .flatMap(message -> message.content().stream())748 .flatMap(content -> content.outputText().stream())749 .forEach(text -> System.out.println(text.text()));750```751752```csharp753using OpenAI.Responses;754#pragma warning disable OPENAI001755756string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;757ResponsesClient client = new(key);758759Uri fileUrl = new(760 "https://www.berkshirehathaway.com/letters/2024ltr.pdf"761);762763ResponseResult response = await client.CreateResponseAsync(764 "gpt-6-astra",765 [766 ResponseItem.CreateUserMessageItem(767 [768 ResponseContentPart.CreateInputTextPart(769 "Analyze the letter and provide a summary of the key points."770 ),771 ResponseContentPart.CreateInputFilePart(fileUrl),772 ]773 ),774 ]775);776777Console.WriteLine(response.GetOutputText());778```779780```ruby781require "openai"782783openai = OpenAI::Client.new784785response = openai.responses.create(786 model: "gpt-6-astra",787 input: [788 {789 role: "user",790 content: [791 {792 type: "input_text",793 text: "Analyze the letter and provide a summary of the key points."794 },795 {796 type: "input_file",797 file_url: "https://www.berkshirehathaway.com/letters/2024ltr.pdf"798 }799 ]800 }801 ]802)803804puts(response.output_text)805```806807```bash808curl "https://api.openai.com/v1/responses" \809 -H "Content-Type: application/json" \810 -H "Authorization: Bearer $OPENAI_API_KEY" \811 -d '{812 "model": "gpt-6-astra",813 "input": [814 {815 "role": "user",816 "content": [817 {818 "type": "input_text",819 "text": "Analyze the letter and provide a summary of the key points."820 },821 {822 "type": "input_file",823 "file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf"824 }825 ]826 }827 ]828 }'829```830831 832833 834835 836Upload file837838 Upload a file and use it as input839840```javascript841import fs from "fs";842import OpenAI from "openai";843const client = new OpenAI();844845const file = await client.files.create({846 file: fs.createReadStream("fixtures/draconomicon.pdf"),847 purpose: "user_data",848});849850const response = await client.responses.create({851 model: "gpt-6-astra",852 input: [853 {854 role: "user",855 content: [856 {857 type: "input_file",858 file_id: file.id,859 },860 {861 type: "input_text",862 text: "What is the first dragon in the book?",863 },864 ],865 },866 ],867});868869console.log(response.output_text);870```871872```python873from openai import OpenAI874875client = OpenAI()876877file = client.files.create(file=open("draconomicon.pdf", "rb"), purpose="user_data")878879response = client.responses.create(880 model="gpt-6-astra",881 input=[882 {883 "role": "user",884 "content": [885 {886 "type": "input_file",887 "file_id": file.id,888 },889 {890 "type": "input_text",891 "text": "What is the first dragon in the book?",892 },893 ],894 }895 ],896)897898print(response.output_text)899```900901```go902package main903904import (905 "context"906 "fmt"907 "os"908909 "github.com/openai/openai-go/v3"910 "github.com/openai/openai-go/v3/responses"911)912913func main() {914 client := openai.NewClient()915916 file, err := os.Open("draconomicon.pdf")917 if err != nil {918 panic(err)919 }920 defer file.Close()921922 uploadedFile, err := client.Files.New(context.Background(), openai.FileNewParams{923 File: file,924 Purpose: openai.FilePurposeUserData,925 })926 if err != nil {927 panic(err)928 }929930 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{931 Model: "gpt-6-astra",932 Input: responses.ResponseNewParamsInputUnion{933 OfInputItemList: responses.ResponseInputParam{934 responses.ResponseInputItemParamOfMessage(935 responses.ResponseInputMessageContentListParam{936 {937 OfInputFile: &responses.ResponseInputFileParam{938 FileID: openai.String(uploadedFile.ID),939 },940 },941 responses.ResponseInputContentParamOfInputText(942 "What is the first dragon in the book?",943 ),944 },945 responses.EasyInputMessageRoleUser,946 ),947 },948 },949 })950 if err != nil {951 panic(err)952 }953954 fmt.Println(response.OutputText())955}956```957958```java959import com.openai.client.OpenAIClient;960import com.openai.client.okhttp.OpenAIOkHttpClient;961import com.openai.models.files.FileCreateParams;962import com.openai.models.files.FilePurpose;963import com.openai.models.responses.ResponseCreateParams;964import com.openai.models.responses.ResponseInputFile;965import com.openai.models.responses.ResponseInputItem;966import java.nio.file.Path;967import java.util.List;968969var file =970 client971 .files()972 .create(973 FileCreateParams.builder()974 .file(Path.of(System.getenv("OPENAI_EXAMPLE_FILE_PATH")))975 .purpose(FilePurpose.USER_DATA)976 .build());977978var response =979 client980 .responses()981 .create(982 ResponseCreateParams.builder()983 .model("gpt-6-astra")984 .inputOfResponse(985 List.of(986 ResponseInputItem.ofMessage(987 ResponseInputItem.Message.builder()988 .role(ResponseInputItem.Message.Role.USER)989 .addContent(990 ResponseInputFile.builder().fileId(file.id()).build())991 .addInputTextContent("What is the first dragon in the book?")992 .build())))993 .build());994response.output().stream()995 .flatMap(item -> item.message().stream())996 .flatMap(message -> message.content().stream())997 .flatMap(content -> content.outputText().stream())998 .forEach(text -> System.out.println(text.text()));999```10001001```csharp1002using OpenAI.Files;1003using OpenAI.Responses;1004#pragma warning disable OPENAI00110051006string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1007ResponsesClient client = new(key);10081009OpenAIFileClient files = new(key);10101011OpenAIFile file = await files.UploadFileAsync(1012 "draconomicon.pdf",1013 FileUploadPurpose.UserData1014);10151016ResponseResult response = await client.CreateResponseAsync(1017 "gpt-6-astra",1018 [1019 ResponseItem.CreateUserMessageItem(1020 [1021 ResponseContentPart.CreateInputFilePart(file.Id),1022 ResponseContentPart.CreateInputTextPart(1023 "What is the first dragon in the book?"1024 ),1025 ]1026 ),1027 ]1028);10291030Console.WriteLine(response.GetOutputText());1031```10321033```ruby1034require "openai"1035require "pathname"10361037openai = OpenAI::Client.new10381039file = openai.files.create(1040 file: Pathname("draconomicon.pdf"),1041 purpose: "user_data"1042)10431044response = openai.responses.create(1045 model: "gpt-6-astra",1046 input: [1047 {1048 role: "user",1049 content: [1050 {1051 type: "input_file",1052 file_id: file.id1053 },1054 {1055 type: "input_text",1056 text: "What is the first dragon in the book?"1057 }1058 ]1059 }1060 ]1061)10621063puts(response.output_text)1064```10651066```bash1067curl https://api.openai.com/v1/files \1068 -H "Authorization: Bearer $OPENAI_API_KEY" \1069 -F purpose="user_data" \1070 -F file="@draconomicon.pdf"10711072curl "https://api.openai.com/v1/responses" \1073 -H "Content-Type: application/json" \1074 -H "Authorization: Bearer $OPENAI_API_KEY" \1075 -d '{1076 "model": "gpt-6-astra",1077 "input": [1078 {1079 "role": "user",1080 "content": [1081 {1082 "type": "input_file",1083 "file_id": "file-6F2ksmvXxt4VdoqmHRw6kL"1084 },1085 {1086 "type": "input_text",1087 "text": "What is the first dragon in the book?"1088 }1089 ]1090 }1091 ]1092 }'1093```1094109510961097[Image inputs guide1098109911001101 Learn to use image inputs to the model and extract meaning from images.](https://developers.openai.com/api/docs/guides/images-vision)11021103[File inputs guide1104110511061107 Learn to use file inputs to the model and extract meaning from documents.](https://developers.openai.com/api/docs/guides/file-inputs)11081109## Extend the model with tools11101111Give the model access to external data and functions by attaching [tools](https://developers.openai.com/api/docs/guides/tools). Use built-in tools like web search or file search, or define your own for calling APIs, running code, or integrating with third-party systems.1112111311141115Web search11161117 Use web search in a response11181119```javascript1120import OpenAI from "openai";1121const client = new OpenAI();11221123const response = await client.responses.create({1124 model: "gpt-6-astra",1125 tools: [{ type: "web_search" }],1126 input: "What was a positive news story from today?",1127});11281129console.log(response.output_text);1130```11311132```python1133from openai import OpenAI11341135client = OpenAI()11361137response = client.responses.create(1138 model="gpt-6-astra",1139 tools=[{"type": "web_search"}],1140 input="What was a positive news story from today?",1141)11421143print(response.output_text)1144```11451146```go1147package main11481149import (1150 "context"1151 "fmt"11521153 "github.com/openai/openai-go/v3"1154 "github.com/openai/openai-go/v3/responses"1155)11561157func main() {1158 client := openai.NewClient()1159 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{1160 Model: "gpt-6-astra",1161 Tools: []responses.ToolUnionParam{1162 responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch),1163 },1164 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What was a positive news story from today?")},1165 })1166 if err != nil {1167 panic(err)1168 }1169 fmt.Println(response.OutputText())1170}1171```11721173```java1174import com.openai.client.OpenAIClient;1175import com.openai.client.okhttp.OpenAIOkHttpClient;1176import com.openai.models.responses.ResponseCreateParams;1177import com.openai.models.responses.WebSearchTool;11781179ResponseCreateParams params =1180 ResponseCreateParams.builder()1181 .model("gpt-6-astra")1182 .input("What was a positive news story from today?")1183 .addTool(WebSearchTool.builder().type(WebSearchTool.Type.WEB_SEARCH).build())1184 .build();11851186client.responses().create(params).output().stream()1187 .flatMap(item -> item.message().stream())1188 .flatMap(message -> message.content().stream())1189 .flatMap(content -> content.outputText().stream())1190 .forEach(text -> System.out.println(text.text()));1191```11921193```csharp1194using OpenAI.Responses;1195#pragma warning disable OPENAI00111961197string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1198ResponsesClient client = new(key);11991200CreateResponseOptions options = new() { Model = "gpt-6-astra" };1201options.Tools.Add(ResponseTool.CreateWebSearchTool());1202options.InputItems.Add(1203 ResponseItem.CreateUserMessageItem("What was a positive news story from today?")1204);12051206ResponseResult response = await client.CreateResponseAsync(options);12071208Console.WriteLine(response.GetOutputText());1209```12101211```ruby1212require "openai"12131214openai = OpenAI::Client.new12151216response = openai.responses.create(1217 model: "gpt-6-astra",1218 tools: [{ type: "web_search" }],1219 input: "What was a positive news story from today?"1220)12211222puts(response.output_text)1223```12241225```bash1226curl "https://api.openai.com/v1/responses" \1227 -H "Content-Type: application/json" \1228 -H "Authorization: Bearer $OPENAI_API_KEY" \1229 -d '{1230 "model": "gpt-6-astra",1231 "tools": [{"type": "web_search"}],1232 "input": "what was a positive news story from today?"1233}'1234```12351236```bash1237openai responses create \1238 --model gpt-6-astra \1239 --raw-output \1240 --transform 'output.#(type=="message").content.0.text' <<'YAML'1241tools:1242 - type: web_search1243input: What was a positive news story from today?1244YAML1245```12461247 12481249 12501251 1252File search12531254 Search your files in a response12551256```javascript1257import OpenAI from "openai";1258const openai = new OpenAI();12591260const response = await openai.responses.create({1261 model: "gpt-6-astra",1262 input: "What is deep research by OpenAI?",1263 tools: [1264 {1265 type: "file_search",1266 vector_store_ids: ["<vector_store_id>"],1267 },1268 ],1269});1270console.log(response);1271```12721273```python1274from openai import OpenAI12751276client = OpenAI()12771278response = client.responses.create(1279 model="gpt-6-astra",1280 input="What is deep research by OpenAI?",1281 tools=[{"type": "file_search", "vector_store_ids": ["<vector_store_id>"]}],1282)1283print(response)1284```12851286```go1287package main12881289import (1290 "context"1291 "fmt"12921293 "github.com/openai/openai-go/v3"1294 "github.com/openai/openai-go/v3/responses"1295)12961297func main() {1298 client := openai.NewClient()1299 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{1300 Model: "gpt-6-astra",1301 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is deep research by OpenAI?")},1302 Tools: []responses.ToolUnionParam{responses.ToolParamOfFileSearch([]string{"<vector_store_id>"})},1303 })1304 if err != nil {1305 panic(err)1306 }1307 fmt.Println(response)1308}1309```13101311```java1312import com.openai.client.OpenAIClient;1313import com.openai.client.okhttp.OpenAIOkHttpClient;1314import com.openai.models.responses.ResponseCreateParams;1315import java.util.List;13161317String vectorStoreId = "<vector_store_id>";13181319ResponseCreateParams params =1320 ResponseCreateParams.builder()1321 .model("gpt-6-astra")1322 .input("What is deep research by OpenAI?")1323 .addFileSearchTool(List.of(vectorStoreId))1324 .build();13251326client.responses().create(params).output().stream()1327 .flatMap(item -> item.message().stream())1328 .flatMap(message -> message.content().stream())1329 .flatMap(content -> content.outputText().stream())1330 .forEach(text -> System.out.println(text.text()));1331```13321333```csharp1334using OpenAI.Responses;1335#pragma warning disable OPENAI00113361337string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1338string vectorStoreId = "<vector_store_id>";1339ResponsesClient client = new(key);13401341CreateResponseOptions options = new() { Model = "gpt-6-astra" };1342options.Tools.Add(1343 ResponseTool.CreateFileSearchTool([vectorStoreId])1344);1345options.InputItems.Add(1346 ResponseItem.CreateUserMessageItem("What is deep research by OpenAI?")1347);13481349ResponseResult response = await client.CreateResponseAsync(options);13501351Console.WriteLine(response.GetOutputText());1352```13531354```ruby1355require "openai"13561357openai = OpenAI::Client.new13581359response = openai.responses.create(1360 model: "gpt-6-astra",1361 input: "What is deep research by OpenAI?",1362 tools: [1363 {1364 type: "file_search",1365 vector_store_ids: ["<vector_store_id>"]1366 }1367 ]1368)13691370puts(response)1371```13721373 13741375 13761377 1378Code Interpreter13791380 Use Code Interpreter in a response13811382```javascript1383import OpenAI from "openai";1384const client = new OpenAI();13851386const response = await client.responses.create({1387 model: "gpt-6-astra",1388 instructions:1389 "You are a personal math tutor. When asked a math question, write and run code to answer the question.",1390 tools: [1391 {1392 type: "code_interpreter",1393 container: { type: "auto" },1394 },1395 ],1396 input: "I need to solve the equation 3x + 11 = 14. Can you help me?",1397});13981399console.log(response.output_text);1400```14011402```python1403from openai import OpenAI14041405client = OpenAI()14061407response = client.responses.create(1408 model="gpt-6-astra",1409 instructions="You are a personal math tutor. When asked a math question, write and run code to answer the question.",1410 tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],1411 input="I need to solve the equation 3x + 11 = 14. Can you help me?",1412)14131414print(response.output_text)1415```14161417```go1418package main14191420import (1421 "context"1422 "fmt"14231424 "github.com/openai/openai-go/v3"1425 "github.com/openai/openai-go/v3/responses"1426)14271428func main() {1429 client := openai.NewClient()1430 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{1431 Model: "gpt-6-astra",1432 Instructions: openai.String("You are a personal math tutor. When asked a math question, write and run code to answer the question."),1433 Tools: []responses.ToolUnionParam{1434 responses.ToolParamOfCodeInterpreter(responses.ToolCodeInterpreterContainerCodeInterpreterContainerAutoParam{}),1435 },1436 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("I need to solve the equation 3x + 11 = 14. Can you help me?")},1437 })1438 if err != nil {1439 panic(err)1440 }1441 fmt.Println(response.OutputText())1442}1443```14441445```java1446import com.openai.client.OpenAIClient;1447import com.openai.client.okhttp.OpenAIOkHttpClient;1448import com.openai.models.responses.ResponseCreateParams;1449import com.openai.models.responses.Tool;14501451ResponseCreateParams params =1452 ResponseCreateParams.builder()1453 .model("gpt-6-astra")1454 .input("I need to solve the equation 3x + 11 = 14. Can you help me?")1455 .instructions(1456 "You are a personal math tutor. When asked a math question, write and run code to answer the question.")1457 .addCodeInterpreterTool(1458 Tool.CodeInterpreter.Container.CodeInterpreterToolAuto.builder().build())1459 .build();14601461client.responses().create(params).output().stream()1462 .flatMap(item -> item.message().stream())1463 .flatMap(message -> message.content().stream())1464 .flatMap(content -> content.outputText().stream())1465 .forEach(text -> System.out.println(text.text()));1466```14671468```csharp1469using OpenAI.Responses;1470#pragma warning disable OPENAI00114711472string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1473ResponsesClient client = new(key);14741475CodeInterpreterToolContainer container = new(1476 CodeInterpreterToolContainerConfiguration.CreateAutomaticContainerConfiguration([])1477);1478CreateResponseOptions options = new()1479{1480 Model = "gpt-6-astra",1481 Instructions = "You are a personal math tutor. Write and run code to answer math questions.",1482};1483options.Tools.Add(ResponseTool.CreateCodeInterpreterTool(container));1484options.InputItems.Add(1485 ResponseItem.CreateUserMessageItem(1486 "I need to solve the equation 3x + 11 = 14. Can you help me?"1487 )1488);14891490ResponseResult response = await client.CreateResponseAsync(options);1491Console.WriteLine(response.GetOutputText());1492```14931494```ruby1495require "openai"14961497openai = OpenAI::Client.new14981499response = openai.responses.create(1500 model: "gpt-6-astra",1501 instructions: "You are a personal math tutor. When asked a math question, write and run code to answer the question.",1502 tools: [1503 {1504 type: "code_interpreter",1505 container: { type: "auto" }1506 }1507 ],1508 input: "I need to solve the equation 3x + 11 = 14. Can you help me?"1509)15101511puts(response.output_text)1512```15131514```bash1515curl https://api.openai.com/v1/responses \1516 -H "Content-Type: application/json" \1517 -H "Authorization: Bearer $OPENAI_API_KEY" \1518 -d '{1519 "model": "gpt-6-astra",1520 "instructions": "You are a personal math tutor. When asked a math question, write and run code to answer the question.",1521 "tools": [1522 {1523 "type": "code_interpreter",1524 "container": { "type": "auto" }1525 }1526 ],1527 "input": "I need to solve the equation 3x + 11 = 14. Can you help me?"1528 }'1529```15301531 15321533 15341535 1536Function calling15371538 Call your own function15391540```javascript1541import OpenAI from "openai";1542const client = new OpenAI();15431544const tools = [1545 {1546 type: "function",1547 name: "get_weather",1548 description: "Get current temperature for a given location.",1549 parameters: {1550 type: "object",1551 properties: {1552 location: {1553 type: "string",1554 description: "City and country e.g. Bogotá, Colombia",1555 },1556 },1557 required: ["location"],1558 additionalProperties: false,1559 },1560 strict: true,1561 },1562];15631564const response = await client.responses.create({1565 model: "gpt-6-astra",1566 input: [1567 { role: "user", content: "What is the weather like in Paris today?" },1568 ],1569 tools,1570});15711572console.log(response.output[0]);1573```15741575```python1576from openai import OpenAI15771578client = OpenAI()15791580tools = [1581 {1582 "type": "function",1583 "name": "get_weather",1584 "description": "Get current temperature for a given location.",1585 "parameters": {1586 "type": "object",1587 "properties": {1588 "location": {1589 "type": "string",1590 "description": "City and country e.g. Bogotá, Colombia",1591 }1592 },1593 "required": ["location"],1594 "additionalProperties": False,1595 },1596 "strict": True,1597 },1598]15991600response = client.responses.create(1601 model="gpt-6-astra",1602 input=[1603 {"role": "user", "content": "What is the weather like in Paris today?"},1604 ],1605 tools=tools,1606)16071608print(response.output[0].to_json())1609```16101611```go1612package main16131614import (1615 "context"1616 "fmt"16171618 "github.com/openai/openai-go/v3"1619 "github.com/openai/openai-go/v3/responses"1620)16211622func main() {1623 client := openai.NewClient()1624 parameters := map[string]any{1625 "type": "object",1626 "properties": map[string]any{1627 "location": map[string]any{1628 "type": "string",1629 "description": "City and country e.g. Bogotá, Colombia",1630 },1631 },1632 "required": []string{"location"},1633 "additionalProperties": false,1634 }1635 tool := responses.ToolParamOfFunction("get_weather", parameters, true)1636 tool.OfFunction.Description = openai.String("Get current temperature for a given location.")16371638 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{1639 Model: "gpt-6-astra",1640 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{1641 responses.ResponseInputItemParamOfMessage("What is the weather like in Paris today?", responses.EasyInputMessageRoleUser),1642 }},1643 Tools: []responses.ToolUnionParam{tool},1644 })1645 if err != nil {1646 panic(err)1647 }1648 fmt.Println(response.Output)1649}1650```16511652```java1653import com.openai.client.OpenAIClient;1654import com.openai.client.okhttp.OpenAIOkHttpClient;1655import com.openai.core.JsonValue;1656import com.openai.models.responses.FunctionTool;1657import com.openai.models.responses.ResponseCreateParams;1658import java.util.List;1659import java.util.Map;16601661ResponseCreateParams params =1662 ResponseCreateParams.builder()1663 .model("gpt-6-astra")1664 .input("What is the weather like in Paris today?")1665 .addTool(1666 FunctionTool.builder()1667 .name("get_weather")1668 .description("Get current temperature for a given location.")1669 .parameters(1670 FunctionTool.Parameters.builder()1671 .putAdditionalProperty("type", JsonValue.from("object"))1672 .putAdditionalProperty(1673 "properties",1674 JsonValue.from(1675 Map.of(1676 "location",1677 Map.of(1678 "type", "string",1679 "description",1680 "City and country e.g. Bogotá, Colombia"))))1681 .putAdditionalProperty("required", JsonValue.from(List.of("location")))1682 .putAdditionalProperty("additionalProperties", JsonValue.from(false))1683 .build())1684 .strict(true)1685 .build())1686 .build();16871688client.responses().create(params).output().forEach(System.out::println);1689```16901691```csharp1692using OpenAI.Responses;1693#pragma warning disable OPENAI00116941695string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1696ResponsesClient client = new(key);16971698CreateResponseOptions options = new() { Model = "gpt-6-astra" };1699options.Tools.Add(1700 ResponseTool.CreateFunctionTool(1701 functionName: "get_weather",1702 functionDescription: "Get current temperature for a given location.",1703 functionParameters: BinaryData.FromString(1704 """1705 {1706 "type": "object",1707 "properties": {1708 "location": {1709 "type": "string",1710 "description": "City and country e.g. Bogotá, Colombia"1711 }1712 },1713 "required": ["location"],1714 "additionalProperties": false1715 }1716 """1717 ),1718 strictModeEnabled: true1719 )1720);1721options.InputItems.Add(1722 ResponseItem.CreateUserMessageItem("What is the weather like in Paris today?")1723);17241725ResponseResult response = await client.CreateResponseAsync(options);1726foreach (ResponseItem outputItem in response.OutputItems)1727{1728 if (outputItem is FunctionCallResponseItem functionCall)1729 {1730 Console.WriteLine(1731 $"{functionCall.FunctionName}({functionCall.FunctionArguments})"1732 );1733 }1734 else if (outputItem is MessageResponseItem message)1735 {1736 foreach (ResponseContentPart content in message.Content)1737 {1738 if (content.Kind == ResponseContentPartKind.OutputText)1739 {1740 Console.WriteLine(content.Text);1741 }1742 else if (content.Kind == ResponseContentPartKind.Refusal)1743 {1744 Console.WriteLine(content.Refusal);1745 }1746 }1747 }1748}1749```17501751```ruby1752require "openai"17531754openai = OpenAI::Client.new17551756tools = [1757 {1758 type: "function",1759 name: "get_weather",1760 description: "Get current temperature for a given location.",1761 parameters: {1762 type: "object",1763 properties: {1764 location: {1765 type: "string",1766 description: "City and country e.g. Bogotá, Colombia"1767 }1768 },1769 required: ["location"],1770 additionalProperties: false1771 },1772 strict: true1773 }1774]17751776response = openai.responses.create(1777 model: "gpt-6-astra",1778 input: [1779 {1780 role: "user",1781 content: "What is the weather like in Paris today?"1782 }1783 ],1784 tools: tools1785)17861787puts(response.output.fetch(0).to_json)1788```17891790```bash1791curl -X POST https://api.openai.com/v1/responses \1792 -H "Authorization: Bearer $OPENAI_API_KEY" \1793 -H "Content-Type: application/json" \1794 -d '{1795 "model": "gpt-6-astra",1796 "input": [1797 {"role": "user", "content": "What is the weather like in Paris today?"}1798 ],1799 "tools": [1800 {1801 "type": "function",1802 "name": "get_weather",1803 "description": "Get current temperature for a given location.",1804 "parameters": {1805 "type": "object",1806 "properties": {1807 "location": {1808 "type": "string",1809 "description": "City and country e.g. Bogotá, Colombia"1810 }1811 },1812 "required": ["location"],1813 "additionalProperties": false1814 },1815 "strict": true1816 }1817 ]1818 }'1819```18201821 18221823 18241825 1826Remote MCP18271828 Call a remote MCP server18291830```bash1831curl https://api.openai.com/v1/responses \ 1832-H "Content-Type: application/json" \ 1833-H "Authorization: Bearer $OPENAI_API_KEY" \ 1834-d '{1835 "model": "gpt-6-astra",1836 "tools": [1837 {1838 "type": "mcp",1839 "server_label": "dmcp",1840 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",1841 "server_url": "https://dmcp-server.deno.dev/mcp",1842 "require_approval": "never"1843 }1844 ],1845 "input": "Roll 2d4+1"1846 }'1847```18481849```javascript1850import OpenAI from "openai";1851const client = new OpenAI();18521853const resp = await client.responses.create({1854 model: "gpt-6-astra",1855 tools: [1856 {1857 type: "mcp",1858 server_label: "dmcp",1859 server_description:1860 "A Dungeons and Dragons MCP server to assist with dice rolling.",1861 server_url: "https://dmcp-server.deno.dev/mcp",1862 require_approval: "never",1863 },1864 ],1865 input: "Roll 2d4+1",1866});18671868console.log(resp.output_text);1869```18701871```python1872from openai import OpenAI18731874client = OpenAI()18751876resp = client.responses.create(1877 model="gpt-6-astra",1878 tools=[1879 {1880 "type": "mcp",1881 "server_label": "dmcp",1882 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",1883 "server_url": "https://dmcp-server.deno.dev/mcp",1884 "require_approval": "never",1885 },1886 ],1887 input="Roll 2d4+1",1888)18891890print(resp.output_text)1891```18921893```go1894package main18951896import (1897 "context"1898 "fmt"18991900 "github.com/openai/openai-go/v3"1901 "github.com/openai/openai-go/v3/responses"1902)19031904func main() {1905 client := openai.NewClient()1906 tool := responses.ToolParamOfMcp("dmcp")1907 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")1908 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")1909 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}19101911 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{1912 Model: "gpt-6-astra",1913 Tools: []responses.ToolUnionParam{tool},1914 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},1915 })1916 if err != nil {1917 panic(err)1918 }1919 fmt.Println(response.OutputText())1920}1921```19221923```java1924import com.openai.client.OpenAIClient;1925import com.openai.client.okhttp.OpenAIOkHttpClient;1926import com.openai.models.responses.ResponseCreateParams;1927import com.openai.models.responses.Tool;19281929ResponseCreateParams params =1930 ResponseCreateParams.builder()1931 .model("gpt-6-astra")1932 .input("Roll 2d4+1")1933 .addTool(1934 Tool.Mcp.builder()1935 .serverLabel("dmcp")1936 .serverDescription(1937 "A Dungeons and Dragons MCP server to assist with dice rolling.")1938 .serverUrl("https://dmcp-server.deno.dev/mcp")1939 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)1940 .build())1941 .build();19421943client.responses().create(params).output().stream()1944 .flatMap(item -> item.message().stream())1945 .flatMap(message -> message.content().stream())1946 .flatMap(content -> content.outputText().stream())1947 .forEach(text -> System.out.println(text.text()));1948```19491950```csharp1951using OpenAI.Responses;1952#pragma warning disable OPENAI00119531954string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;1955ResponsesClient client = new(key);19561957CreateResponseOptions options = new() { Model = "gpt-6-astra" };1958options.Tools.Add(1959 ResponseTool.CreateMcpTool(1960 serverLabel: "dmcp",1961 serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),1962 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval1963 )1964);1965options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));19661967ResponseResult response = await client.CreateResponseAsync(options);19681969Console.WriteLine(response.GetOutputText());1970```19711972```ruby1973require "openai"19741975openai = OpenAI::Client.new19761977response = openai.responses.create(1978 model: "gpt-6-astra",1979 tools: [1980 {1981 type: "mcp",1982 server_label: "dmcp",1983 server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",1984 server_url: "https://dmcp-server.deno.dev/mcp",1985 require_approval: "never"1986 }1987 ],1988 input: "Roll 2d4+1"1989)19901991puts(response.output_text)1992```1993199419951996[Use built-in tools1997199819992000 Learn about powerful built-in tools like web search and file search.](https://developers.openai.com/api/docs/guides/tools)20012002[Function calling guide2003200420052006 Learn to enable the model to call your own custom code.](https://developers.openai.com/api/docs/guides/function-calling)20072008## Stream responses and build real-time apps20092010Use 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.20112012Stream server-sent events from the API20132014```javascript2015import { OpenAI } from "openai";2016const client = new OpenAI();20172018const stream = await client.responses.create({2019 model: "gpt-6-astra",2020 input: [2021 {2022 role: "user",2023 content: "Say 'double bubble bath' ten times fast.",2024 },2025 ],2026 stream: true,2027});20282029for await (const event of stream) {2030 console.log(event);2031}2032```20332034```python2035from openai import OpenAI20362037client = OpenAI()20382039stream = client.responses.create(2040 model="gpt-6-astra",2041 input=[2042 {2043 "role": "user",2044 "content": "Say 'double bubble bath' ten times fast.",2045 },2046 ],2047 stream=True,2048)20492050for event in stream:2051 print(event)2052```20532054```go2055package main20562057import (2058 "context"2059 "fmt"20602061 "github.com/openai/openai-go/v3"2062 "github.com/openai/openai-go/v3/responses"2063)20642065func main() {2066 client := openai.NewClient()2067 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{2068 Model: "gpt-6-astra",2069 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Say 'double bubble bath' ten times fast.")},2070 })2071 for stream.Next() {2072 fmt.Println(stream.Current().Type)2073 }2074 if err := stream.Err(); err != nil {2075 panic(err)2076 }2077}2078```20792080```java2081import com.openai.client.OpenAIClient;2082import com.openai.client.okhttp.OpenAIOkHttpClient;2083import com.openai.core.http.StreamResponse;2084import com.openai.models.responses.ResponseCreateParams;2085import com.openai.models.responses.ResponseStreamEvent;20862087ResponseCreateParams params =2088 ResponseCreateParams.builder()2089 .model("gpt-6-astra")2090 .input("Say 'double bubble bath' ten times fast.")2091 .build();20922093try (StreamResponse<ResponseStreamEvent> stream = client.responses().createStreaming(params)) {2094 stream.stream().forEach(System.out::println);2095}2096```20972098```csharp2099using OpenAI.Responses;2100#pragma warning disable OPENAI00121012102string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;2103ResponsesClient client = new(key);21042105var responses = client.CreateResponseStreamingAsync(2106 "gpt-6-astra",2107 "Say 'double bubble bath' ten times fast."2108);21092110await foreach (StreamingResponseUpdate response in responses)2111{2112 if (response is StreamingResponseOutputTextDeltaUpdate delta)2113 {2114 Console.Write(delta.Delta);2115 }2116}2117```21182119```ruby2120require "openai"21212122openai = OpenAI::Client.new21232124stream = openai.responses.stream(2125 model: "gpt-6-astra",2126 input: [2127 {2128 role: "user",2129 content: "Say 'double bubble bath' ten times fast."2130 }2131 ]2132)21332134stream.each do |event|2135 puts(event)2136end2137```213821392140[Use streaming events2141214221432144 Use server-sent events to stream model responses to users fast.](https://developers.openai.com/api/docs/guides/streaming-responses)21452146[Get started with the Realtime API2147214821492150 Use WebRTC or WebSockets for super fast speech-to-speech AI apps.](https://developers.openai.com/api/docs/guides/realtime)21512152## Build agents21532154Use 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.21552156Build a language triage agent21572158```javascript2159import { Agent, run } from "@openai/agents";21602161const spanishAgent = new Agent({2162 name: "Spanish agent",2163 instructions: "You only speak Spanish.",2164});21652166const englishAgent = new Agent({2167 name: "English agent",2168 instructions: "You only speak English",2169});21702171const triageAgent = new Agent({2172 name: "Triage agent",2173 instructions:2174 "Handoff to the appropriate agent based on the language of the request.",2175 handoffs: [spanishAgent, englishAgent],2176});21772178const result = await run(triageAgent, "Hola, ¿cómo estás?");2179console.log(result.finalOutput);2180```21812182```python2183from agents import Agent, Runner2184import asyncio21852186spanish_agent = Agent(2187 name="Spanish agent",2188 instructions="You only speak Spanish.",2189)21902191english_agent = Agent(2192 name="English agent",2193 instructions="You only speak English",2194)21952196triage_agent = Agent(2197 name="Triage agent",2198 instructions="Handoff to the appropriate agent based on the language of the request.",2199 handoffs=[spanish_agent, english_agent],2200)220122022203async def main():2204 result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")2205 print(result.final_output)220622072208if __name__ == "__main__":2209 asyncio.run(main())2210```221122122213[Build agents that can take action2214221522162217 Learn how to use the OpenAI platform to build powerful, capable AI agents.](https://developers.openai.com/api/docs/guides/agents)