> ## Documentation Index
> Fetch the complete documentation index at: https://openai-hd4n6.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Developer quickstart

> Take your first steps with the OpenAI API.

The OpenAI API provides a simple interface to state-of-the-art AI [models](/docs/models) for text generation, natural language processing, computer vision, and more. This example generates [text output](/docs/guides/text) from a prompt, as you might using [ChatGPT](https://chatgpt.com/).

<CodeGroup>
  ```javascript javascript theme={"system"}
  import OpenAI from "openai";
  const client = new OpenAI();

  const response = await client.responses.create({
      model: "gpt-4.1",
      input: "Write a one-sentence bedtime story about a unicorn."
  });

  console.log(response.output_text);
  ```

  ```python python theme={"system"}
  from openai import OpenAI
  client = OpenAI()

  response = client.responses.create(
      model="gpt-4.1",
      input="Write a one-sentence bedtime story about a unicorn."
  )

  print(response.output_text)
  ```

  ```bash curl theme={"system"}
  curl "https://api.openai.com/v1/responses" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -d '{
          "model": "gpt-4.1",
          "input": "Write a one-sentence bedtime story about a unicorn."
      }'
  ```
</CodeGroup>

<AccordionGroup>
  <Accordion title="Data retention for model responses">
    Response objects are saved for 30 days by default. They can be viewed in the dashboard [logs](https://platform.openai.com/logs?api=responses) page or [retrieved](/docs/api-reference/responses/get) via the API. You can disable this behavior by setting `store` to `false` when creating a Response.

    OpenAI does not use data sent via API to train our models without your explicit consent—[learn more](/docs/guides/your-data).
  </Accordion>
</AccordionGroup>

<CardGroup cols={1}>
  <Card title="Configure your development environment" icon="wrench" iconType="solid" horizontal href="/docs/libraries">
    Install and configure an official OpenAI SDK to run the code above.
  </Card>

  <Card title="Responses starter app" icon="code" iconType="solid" href="https://github.com/openai/openai-responses-starter-app" horizontal>
    Start building with the Responses API
  </Card>

  <Card title="Text generation and prompting" icon="rocketchat" iconType="solid" horizontal href="/docs/guides/text">
    Learn more about prompting, message roles, and building conversational apps.
  </Card>
</CardGroup>

## Analyze image inputs

You can provide image inputs to the model as well. Scan receipts, analyze screenshots, or find objects in the real world with [computer vision](/docs/guides/images).

<CodeGroup>
  ```javascript javascript theme={"system"}
  import OpenAI from "openai";
  const client = new OpenAI();

  const response = await client.responses.create({
      model: "gpt-4.1",
      input: [
          { role: "user", content: "What two teams are playing in this photo?" },
          {
              role: "user",
              content: [
                  {
                      type: "input_image", 
                      image_url: "https://upload.wikimedia.org/wikipedia/commons/3/3b/LeBron_James_Layup_%28Cleveland_vs_Brooklyn_2018%29.jpg",
                  }
              ],
          },
      ],
  });

  console.log(response.output_text);
  ```

  ```bash curl theme={"system"}
  curl "https://api.openai.com/v1/responses" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -d '{
          "model": "gpt-4.1",
          "input": [
              {
                  "role": "user",
                  "content": "What two teams are playing in this photo?"
              },
              {
                  "role": "user",
                  "content": [
                      {
                          "type": "input_image",
                          "image_url": "https://upload.wikimedia.org/wikipedia/commons/3/3b/LeBron_James_Layup_%28Cleveland_vs_Brooklyn_2018%29.jpg"
                      }
                  ]
              }
          ]
      }'
  ```

  ```python python theme={"system"}
  from openai import OpenAI
  client = OpenAI()

  response = client.responses.create(
      model="gpt-4.1",
      input=[
          {"role": "user", "content": "what teams are playing in this image?"},
          {
              "role": "user",
              "content": [
                  {
                      "type": "input_image",
                      "image_url": "https://upload.wikimedia.org/wikipedia/commons/3/3b/LeBron_James_Layup_%28Cleveland_vs_Brooklyn_2018%29.jpg"
                  }
              ]
          }
      ]
  )

  print(response.output_text)
  ```
</CodeGroup>

<CardGroup cols={1}>
  <Card title="Computer vision guide" icon="camera" iconType="solid" horizontal href="/docs/guides/images">
    Learn to use image inputs to the model and extract meaning from images.
  </Card>
</CardGroup>

## Extend the model with tools

Give the model access to new data and capabilities using [tools](/docs/guides/tools). You can either call your own [custom code](/docs/guides/function-calling), or use one of OpenAI's [powerful built-in tools](/docs/guides/tools). This example uses [web search](/docs/guides/tools-web-search) to give the model access to the latest information on the Internet.

<CodeGroup>
  ```javascript javascript theme={"system"}
  import OpenAI from "openai";
  const client = new OpenAI();

  const response = await client.responses.create({
  model: "gpt-4.1",
  tools: [ { type: "web_search_preview" } ],
  input: "What was a positive news story from today?",
  });

  console.log(response.output_text);

  ```

  ```python python theme={"system"}
  from openai import OpenAI
  client = OpenAI()

  response = client.responses.create(
      model="gpt-4.1",
      tools=[{"type": "web_search_preview"}],
      input="What was a positive news story from today?"
  )

  print(response.output_text)
  ```

  ```bash curl theme={"system"}
  curl "https://api.openai.com/v1/responses" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -d '{
          "model": "gpt-4.1",
          "tools": [{"type": "web_search_preview"}],
          "input": "what was a positive news story from today?"
      }'
  ```
</CodeGroup>

<CardGroup cols={1}>
  <Card title="Use built-in tools" icon="wrench" iconType="solid" horizontal href="/docs/guides/tools">
    Learn about powerful built-in tools like web search and file search.
  </Card>

  <Card title="Function calling guide" icon="code" iconType="solid" horizontal href="/docs/guides/function-calling">
    Learn to enable the model to call your own custom code.
  </Card>
</CardGroup>

## Deliver blazing fast AI experiences

Using either the new [Realtime API](/docs/guides/realtime) or server-sent [streaming events](/docs/guides/streaming-responses), you can build high performance, low-latency experiences for your users.

<CodeGroup>
  ```javascript javascript theme={"system"}
  import { OpenAI } from "openai";
  const client = new OpenAI();

  const stream = await client.responses.create({
    model: "gpt-4.1",
    input: [
      {
        role: "user",
        content: "Say 'double bubble bath' ten times fast.",
      },
    ],
    stream: true,
  });

  for await (const event of stream) {
    console.log(event);
  }
  ```

  ```python python theme={"system"}
  from openai import OpenAI
  client = OpenAI()

  stream = client.responses.create(
      model="gpt-4.1",
      input=[
          {
              "role": "user",
              "content": "Say 'double bubble bath' ten times fast.",
          },
      ],
      stream=True,
  )

  for event in stream:
      print(event)
  ```
</CodeGroup>

<CardGroup cols={1}>
  <Card title="Use streaming events" icon="timer" iconType="solid" horizontal href="/docs/guides/streaming-responses">
    Use server-sent events to stream model responses to users fast.
  </Card>

  <Card title="Get started with the Realtime API" icon="bolt" iconType="solid" horizontal href="/docs/guides/realtime">
    Use WebRTC or WebSockets for super fast speech-to-speech AI apps.
  </Card>
</CardGroup>

## Build agents

Use the OpenAI platform to build [agents](/docs/guides/agents) capable of taking action—like [controlling computers](/docs/guides/tools-computer-use)—on behalf of your users. Use the [Agent SDK for Python](/docs/guides/agents-sdk) to create orchestration logic on the backend.

```python theme={"system"}
from agents import Agent, Runner
import asyncio

spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
)

async def main():
    result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

# ¡Hola! Estoy bien, gracias por preguntar. ¿Y tú, cómo estás?
```

<CardGroup cols={1}>
  <Card title="Build agents that can take action" icon="brain-cog" iconType="solid" horizontal href="/docs/guides/agents">
    Learn how to use the OpenAI platform to build powerful, capable AI agents.
  </Card>
</CardGroup>

## Explore further

We've barely scratched the surface of what's possible with the OpenAI platform. Here are some resources you might want to explore next.

<CardGroup cols={1}>
  <Card title="Go deeper with prompting and text generation" icon="rocketchat" iconType="solid" horizontal href="/docs/guides/text">
    Learn more about prompting, message roles, and building conversational apps like chat bots.
  </Card>

  {" "}

  <Card title="Analyze the content of images" icon="camera" iconType="solid" horizontal href="/docs/guides/images">
    Learn to use image inputs to the model and extract meaning from images.
  </Card>

  {" "}

  <Card title="Generate structured JSON data from the model" icon="boxes" iconType="solid" horizontal href="/docs/guides/structured-outputs">
    Generate JSON data from the model that conforms to a JSON schema you specify.
  </Card>

  {" "}

  <Card title="Call custom code to help generate a response" icon="code" iconType="solid" horizontal href="/docs/guides/function-calling">
    Empower the model to invoke your own custom code to help generate a response.
    Do this to give the model access to data or systems it wouldn't be able to
    access otherwise.
  </Card>

  {" "}

  <Card title="Search the web or use your own data in responses" icon="wrench" iconType="solid" horizontal href="/docs/guides/tools">
    Try out powerful built-in tools to extend the capabilities of the models.
    Search the web or your own data for up-to-date information the model can use
    to generate responses.
  </Card>

  {" "}

  <Card title="Responses starter app" icon="code" iconType="solid" horizontal href="https://github.com/openai/openai-responses-starter-app">
    Start building with the Responses API
  </Card>

  {" "}

  <Card title="Build agents" icon="bot" iconType="solid" horizontal href="/docs/guides/agents">
    Explore interfaces to build powerful AI agents that can take action on behalf
    of users. Control a computer to take action on behalf of a user, or
    orchestrate multi-agent flows with the Agents SDK.
  </Card>

  <Card title="Full API Reference" icon="code" iconType="solid" horizontal href="/docs/api-reference">
    View the full API reference for the OpenAI platform.
  </Card>
</CardGroup>
