> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI

> Route OpenAI model requests through Orq.ai's AI Router. Set up your API key and access GPT, DALL-E, and Whisper models with caching and fallbacks.

## Setup Your API Key

To use OpenAI with Orq.ai, follow these steps:

1. Navigate to **AI Router** > Providers
2. Find **OpenAI** in the list
3. Click the **Configure** button next to OpenAI
4. In the modal that opens, select **Setup your own API Key**
5. Enter a name for this configuration (e.g., "OpenAI Production")
6. Paste your OpenAI API Key into the provided field
7. Click **Save** to complete the setup

Your OpenAI API key is now configured and ready to use with Orq.ai in **AI Studio** or through the **AI Router**.

## Available Models

The **AI Router** supports all current OpenAI models. Here are the most commonly used:

### Recommended Models

| Model                  | Context | Best For                               |
| ---------------------- | ------- | -------------------------------------- |
| `openai/gpt-5.4`       | 128K    | Latest GPT-5 generation                |
| `openai/gpt-5.2-pro`   | 128K    | Most advanced, production-ready        |
| `openai/gpt-4o`        | 128K    | High performance, widely available     |
| `openai/gpt-4o-mini`   | 128K    | Cost-effective with strong performance |
| `openai/gpt-3.5-turbo` | 4K      | Budget-friendly for simple tasks       |

<AccordionGroup>
  <Accordion title="View all Supported models" icon="openai">
    #### Latest Generation (GPT-5.x)

    * `openai/gpt-5.4` - Latest GPT-5 generation
    * `openai/gpt-5.2-pro` - Most capable, production-ready
    * `openai/gpt-5.2-chat-latest` - GPT-5.2 latest
    * `openai/gpt-5.2` - GPT-5.2 base
    * `openai/gpt-5.1-chat-latest` - GPT-5.1 latest
    * `openai/gpt-5.1` - GPT-5.1 base
    * `openai/gpt-5-pro` - GPT-5 advanced
    * `openai/gpt-5-chat-latest` - GPT-5 latest
    * `openai/gpt-5-mini` - GPT-5 fast
    * `openai/gpt-5-nano` - GPT-5 lightweight
    * `openai/gpt-5` - GPT-5 base

    #### Current Generation (GPT-4.x)

    * `openai/gpt-4.1-2025-04-14` - GPT-4.1 April 2025
    * `openai/gpt-4.1-mini-2025-04-14` - GPT-4.1 mini April 2025
    * `openai/gpt-4.1-nano-2025-04-14` - GPT-4.1 nano April 2025
    * `openai/gpt-4.1` - GPT-4.1 base
    * `openai/gpt-4.1-mini` - GPT-4.1 mini
    * `openai/gpt-4.1-nano` - GPT-4.1 nano
    * `openai/gpt-4o` - Latest GPT-4o, recommended
    * `openai/gpt-4o-2024-11-20` - GPT-4o November 2024
    * `openai/gpt-4o-2024-08-06` - GPT-4o August 2024
    * `openai/gpt-4o-2024-05-13` - GPT-4o May 2024
    * `openai/gpt-4o-mini` - Optimized for speed and cost
    * `openai/gpt-4o-mini-2024-07-18` - GPT-4o mini July 2024
    * `openai/gpt-4-turbo` - High-performance model
    * `openai/gpt-4-turbo-2024-04-09` - GPT-4 Turbo April 2024

    #### Legacy Models

    * `openai/gpt-3.5-turbo` - Cost-effective, widely used
    * `openai/gpt-3.5-turbo-0125` - GPT-3.5 Turbo January 2025
    * `openai/gpt-3.5-turbo-16k` - Extended context

    #### Reasoning Models (Advanced)

    * `openai/o3-pro` - Advanced reasoning
    * `openai/o3-2025-04-16` - O3 April 2025
    * `openai/o3` - O3 foundation
    * `openai/o3-mini` - O3 lightweight
    * `openai/o3-mini-2025-01-31` - O3-mini January 2025
    * `openai/o1-pro` - Professional reasoning
    * `openai/o1-2024-12-17` - O1 December 2024
    * `openai/o1` - O1 foundation
    * `openai/o4-mini-2025-04-16` - O4-mini April 2025
    * `openai/o4-mini` - O4-mini base

    For a complete and up-to-date list of all available OpenAI models, see [Supported Models](/docs/proxy/supported-models#chat-models).

    All models are available through the **AI Router** with the `openai/` prefix.
  </Accordion>
</AccordionGroup>

<Tip>
  Use `openai/gpt-5.4` for the latest model, or `openai/gpt-4o` for the best balance of performance, cost, and availability.
</Tip>

<Note>
  Reasoning models (`o1`, `o1-pro`, `o3`, `o3-pro`, `o4-mini`) require developer mode enabled in your OpenAI account. Enable it in your account settings and accept the reasoning model terms before using these models.
</Note>

<Card title="Reasoning models" icon="brain" href="/docs/proxy/reasoning" horizontal>
  Configure `reasoning_effort` for o1 and o3 models through the **AI Router**.
</Card>

## Quick Start

Access OpenAI's GPT models through the **AI Router**.

<CodeGroup>
  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import OpenAI from "openai";

  const openai = new OpenAI({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: "https://api.orq.ai/v3/router",
  });

  const response = await openai.chat.completions.create({
    model: "openai/gpt-4o",
    messages: [
      {
        role: "user",
        content: "Explain quantum computing in simple terms",
      },
    ],
  });

  console.log(response.choices[0].message.content);
  ```
</CodeGroup>

## Using the AI Router

Access OpenAI's GPT models (GPT-4, GPT-4o, GPT-4 Turbo) through the **AI Router** with advanced chat completions, streaming, function calling, and intelligent model routing. All OpenAI models are available with consistent formatting and automatic request logging.

<Info>
  OpenAI models use the provider slug format: `openai/model-name`. For example: `openai/gpt-4o`
</Info>

### Prerequisites

Before making requests to the **AI Router**, you need to configure your environment and install the SDKs if you choose to use them.

**Router Endpoint**

To use the **AI Router** with OpenAI models, configure your OpenAI SDK client with the base URL:

```
https://api.orq.ai/v3/router
```

**Required Headers**

Include the following headers in all requests:

```
Authorization: Bearer $ORQ_API_KEY
Content-Type: application/json
```

Optional headers for advanced routing:

```
X-Orq-Provider: openai
X-Orq-Virtual-Key: your-virtual-key-name (optional)
```

**Getting your API Key:**

1. Go to [API Keys](/docs/router/api-keys)
2. Click **Create API Key** and copy it
3. Store it in your environment as `ORQ_API_KEY`

**SDK Installation**

Install the OpenAI SDK for your language:

<CodeGroup>
  ```bash Node.js/TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  npm install openai
  # or
  yarn add openai
  ```

  ```bash Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  pip install openai
  ```
</CodeGroup>

<Tip>
  If your OpenAI code is already functionning, you only need to change the `base_url` and `api_key` to the router endpoint and `ORQ_API_KEY`.
</Tip>

### Chat Completions

Send messages to OpenAI models and get intelligent responses:

<CodeGroup>
  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const response = await openai.chat.completions.create({
    model: "openai/gpt-4o",
    messages: [
      {
        role: "system",
        content: "You are a helpful assistant that explains complex concepts simply.",
      },
      {
        role: "user",
        content: "Explain machine learning",
      },
    ],
    temperature: 0.7,
    max_tokens: 500,
  });

  console.log(response.choices[0].message.content);
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  response = client.chat.completions.create(
      model="openai/gpt-4o",
      messages=[
          {
              "role": "system",
              "content": "You are a helpful assistant that explains complex concepts simply."
          },
          {
              "role": "user",
              "content": "Explain machine learning"
          }
      ],
      temperature=0.7,
      max_tokens=500
  )

  print(response.choices[0].message.content)
  ```
</CodeGroup>

### Function Calling

OpenAI models support function calling for structured interactions:

<CodeGroup>
  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const response = await openai.chat.completions.create({
    model: "openai/gpt-4o",
    messages: [
      {
        role: "user",
        content: "What's the weather in San Francisco?",
      },
    ],
    tools: [
      {
        type: "function",
        function: {
          name: "get_weather",
          description: "Get the current weather in a location",
          parameters: {
            type: "object",
            properties: {
              location: {
                type: "string",
                description: "The city and state, e.g. San Francisco, CA",
              },
              unit: {
                type: "string",
                enum: ["celsius", "fahrenheit"],
              },
            },
            required: ["location"],
          },
        },
      },
    ],
  });

  const toolCall = response.choices[0].message.tool_calls?.[0];
  if (toolCall?.type === "function") {
    console.log(`Calling function: ${toolCall.function.name}`);
    console.log(`Arguments: ${toolCall.function.arguments}`);
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  response = client.chat.completions.create(
      model="openai/gpt-4o",
      messages=[
          {
              "role": "user",
              "content": "What's the weather in San Francisco?"
          }
      ],
      tools=[
          {
              "type": "function",
              "function": {
                  "name": "get_weather",
                  "description": "Get the current weather in a location",
                  "parameters": {
                      "type": "object",
                      "properties": {
                          "location": {
                              "type": "string",
                              "description": "The city and state, e.g. San Francisco, CA"
                          },
                          "unit": {
                              "type": "string",
                              "enum": ["celsius", "fahrenheit"]
                          }
                      },
                      "required": ["location"]
                  }
              }
          }
      ]
  )

  tool_call = response.choices[0].message.tool_calls[0]
  print(f"Calling function: {tool_call.function.name}")
  print(f"Arguments: {tool_call.function.arguments}")
  ```
</CodeGroup>

<Card title="Tool Calling" icon="wrench" href="/docs/proxy/tool-calling" horizontal>
  Full reference for function tools, `tool_choice`, parallel calls, and streaming with tool calls through the **AI Router**.
</Card>

### Streaming

Stream responses for real-time output and improved user experience:

<CodeGroup>
  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const stream = await openai.chat.completions.create({
    model: "openai/gpt-4o",
    messages: [
      {
        role: "user",
        content: "Write a short poem about the ocean",
      },
    ],
    stream: true,
  });

  for await (const chunk of stream) {
    const content = chunk.choices[0]?.delta?.content || "";
    process.stdout.write(content);
  }
  console.log("\n");
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  stream = client.chat.completions.create(
      model="openai/gpt-4o",
      messages=[
          {
              "role": "user",
              "content": "Write a short poem about the ocean"
          }
      ],
      stream=True
  )

  for chunk in stream:
      print(chunk.choices[0].delta.content or "", end="", flush=True)
  print()
  ```

  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST https://api.orq.ai/v3/router/chat/completions \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "messages": [
        {
          "role": "user",
          "content": "Write a short poem about the ocean"
        }
      ],
      "stream": true
    }'
  ```
</CodeGroup>

## Using the Responses API

The Responses API combines the best of Chat Completions and Assistants APIs. Use `responses.create()` with the **AI Router**:

<CardGroup cols={2}>
  <Card title="Web Search" icon="magnifying-glass" href="/docs/proxy/web-search" horizontal>
    Add web search to Responses API calls with `web_search_preview` tools.
  </Card>

  <Card title="Reasoning models" icon="brain" href="/docs/proxy/reasoning" horizontal>
    Use the `reasoning` object with o-series models on the Responses API.
  </Card>
</CardGroup>

### Endpoint

```
POST https://api.orq.ai/v3/router/responses
```

### Basic Usage

Configure the OpenAI SDK to use the **AI Router** and call the Responses API:

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST https://api.orq.ai/v3/router/responses \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "input": "Write a three sentence bedtime story about a unicorn"
    }'
  ```

  ```typescript Node.js/TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import OpenAI from "openai";

  const openai = new OpenAI({
    apiKey: process.env.ORQ_API_KEY,
    baseURL: "https://api.orq.ai/v3/router",
  });

  const response = await openai.responses.create({
    model: "openai/gpt-4o",
    input: "Write a three sentence bedtime story about a unicorn",
  });

  console.log(response);
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from openai import OpenAI
  import os

  client = OpenAI(
      api_key=os.environ.get('ORQ_API_KEY'),
      base_url="https://api.orq.ai/v3/router"
  )

  response = client.responses.create(
      model="openai/gpt-4o",
      input="Write a three sentence bedtime story about a unicorn"
  )

  print(response)
  ```
</CodeGroup>

### With Streaming

Stream responses for real-time output:

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST https://api.orq.ai/v3/router/responses \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "input": "Explain quantum computing",
      "stream": true
    }'
  ```

  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const stream = await openai.responses.create({
    model: "openai/gpt-4o",
    input: "Explain quantum computing",
    stream: true,
  });

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

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  stream = client.responses.create(
      model="openai/gpt-4o",
      input="Explain quantum computing",
      stream=True
  )

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

### With Tools

Use function calling with the Responses API:

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST https://api.orq.ai/v3/router/responses \
    -H "Authorization: Bearer $ORQ_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "input": "What'\''s the weather in New York?",
      "tools": [
        {
          "type": "function",
          "function": {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "parameters": {
              "type": "object",
              "properties": {
                "location": {
                  "type": "string",
                  "description": "City and state"
                }
              },
              "required": ["location"]
            }
          }
        }
      ]
    }'
  ```

  ```typescript Typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const response = await openai.responses.create({
    model: "openai/gpt-4o",
    input: "What's the weather in New York?",
    tools: [
      {
        type: "function",
        function: {
          name: "get_weather",
          description: "Get current weather for a location",
          parameters: {
            type: "object",
            properties: {
              location: {
                type: "string",
                description: "City and state",
              },
            },
            required: ["location"],
          },
        },
      },
    ],
  });

  console.log(response);
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  response = client.responses.create(
      model="openai/gpt-4o",
      input="What's the weather in New York?",
      tools=[
          {
              "type": "function",
              "function": {
                  "name": "get_weather",
                  "description": "Get current weather for a location",
                  "parameters": {
                      "type": "object",
                      "properties": {
                          "location": {
                              "type": "string",
                              "description": "City and state"
                          }
                      },
                      "required": ["location"]
                  }
              }
          }
      ]
  )

  print(response)
  ```
</CodeGroup>

## Automatic Request Logging

All requests made through the **AI Router** are automatically logged to your dashboard. You can view:

* **Request details**: Model used, tokens, latency
* **Cost tracking**: Per-request and aggregate costs
* **Error monitoring**: Failed requests with error messages
* **Performance metrics**: Response times and throughput

No additional configuration is needed. Logging happens automatically.

## Troubleshooting

| Issue                  | Problem                         | Solution                                                                                                                                                                       |
| ---------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Rate Limiting          | Too many requests to OpenAI API | Implement exponential backoff for retries. The AI Router automatically retries failed requests with appropriate delays.                                                        |
| High Latency           | Slow response times             | Monitor dashboard for model performance. Consider using `gpt-3.5-turbo` for latency-sensitive applications.                                                                    |
| Invalid Request Errors | Malformed API requests          | Verify model name format (`openai/model-name`). Ensure required fields are present in messages array. Check that messages contain valid role values (user, assistant, system). |
| API Errors             | HTTP errors from OpenAI         | Handle errors with try/catch. Check error status codes and messages. Use the AI Router's automatic retry mechanism.                                                            |

## Reference

* [OpenAI API Documentation](https://platform.openai.com/docs/)
* [Model Pricing](https://openai.com/pricing)
* [API Reference](https://platform.openai.com/docs/api-reference)
* [Chat Completions Guide](https://platform.openai.com/docs/guides/chat-completions)
