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

# Universal API

> One API for 3,000+ LLMs across every major provider. Use OpenAI's Chat Completions, Responses API, or Anthropic's Messages format -- Prisma AIRS AI Gateway translates between them all.

<Info>
  Available on all AI Gateway plans.
</Info>

AI Gateway provides a single, unified API for 3,000+ models from every major provider. Write once in any format, switch providers by changing one parameter.

## Three API Formats, Any Provider

The AI Gateway supports three API formats. Each works with **all providers** — the AI Gateway handles translation automatically.

<CardGroup cols={3}>
  <Card title="Chat Completions" icon="comments" href="/docs/aigw/product/ai-gateway/chat-completions">
    **OpenAI spec** · `POST /v1/chat/completions`

    Widest ecosystem compatibility
  </Card>

  <Card title="Responses API" icon="robot" href="/docs/aigw/product/ai-gateway/responses-api">
    **OpenAI spec** · `POST /v1/responses`

    Agentic AI with built-in tool use
  </Card>

  <Card title="Messages API" icon="message" href="/docs/aigw/product/ai-gateway/messages-api">
    **Anthropic spec** · `POST /v1/messages`

    Native Anthropic format across providers
  </Card>
</CardGroup>

### Chat Completions — `POST /v1/chat/completions`

OpenAI-compatible format with the widest ecosystem support. [Full guide →](/docs/aigw/product/ai-gateway/chat-completions)

<CodeGroup>
  ```python OpenAI Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      api_key="PORTKEY_API_KEY",
      base_url="https://aigw.portkey.ai/v1"
  )

  response = client.chat.completions.create(
      model="@anthropic-provider/claude-sonnet-4-5-20250514",
      messages=[{"role": "user", "content": "Hello!"}]
  )

  print(response.choices[0].message.content)
  ```

  ```javascript OpenAI Node.js theme={"system"}
  import OpenAI from 'openai';

  const client = new OpenAI({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai/v1"
  });

  const response = await client.chat.completions.create({
      model: "@anthropic-provider/claude-sonnet-4-5-20250514",
      messages: [{ role: "user", content: "Hello!" }]
  });

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

  ```sh cURL theme={"system"}
  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{
      "model": "@anthropic-provider/claude-sonnet-4-5-20250514",
      "messages": [{"role": "user", "content": "Hello!"}]
    }'
  ```
</CodeGroup>

### Responses API — `POST /v1/responses`

OpenAI's next-gen format for agentic AI with built-in tool use and reasoning. [Full guide →](/docs/aigw/product/ai-gateway/responses-api)

<CodeGroup>
  ```python OpenAI Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      api_key="PORTKEY_API_KEY",
      base_url="https://aigw.portkey.ai/v1"
  )

  response = client.responses.create(
      model="@anthropic-provider/claude-sonnet-4-5-20250514",
      input="Hello!"
  )

  print(response.output_text)
  ```

  ```javascript OpenAI Node.js theme={"system"}
  import OpenAI from 'openai';

  const client = new OpenAI({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai/v1"
  });

  const response = await client.responses.create({
      model: "@anthropic-provider/claude-sonnet-4-5-20250514",
      input: "Hello!"
  });

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

  ```sh cURL theme={"system"}
  curl https://aigw.portkey.ai/v1/responses \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{
      "model": "@anthropic-provider/claude-sonnet-4-5-20250514",
      "input": "Hello!"
    }'
  ```
</CodeGroup>

### Messages API — `POST /v1/messages`

Anthropic-native format using the Anthropic SDK pointed at the AI Gateway's base URL. [Full guide →](/docs/aigw/product/ai-gateway/messages-api)

<CodeGroup>
  ```python Python theme={"system"}
  import anthropic

  client = anthropic.Anthropic(
      api_key="dummy", # auth happens via the Authorization header
      default_headers={"Authorization": "Bearer YOUR_PORTKEY_API_KEY"},
      base_url="https://aigw.portkey.ai"
  )

  message = client.messages.create(
      model="@anthropic-provider/claude-sonnet-4-5-20250514",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello!"}]
  )

  print(message.content[0].text)
  ```

  ```typescript TypeScript theme={"system"}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai"
  });

  const message = await client.messages.create({
      model: "@anthropic-provider/claude-sonnet-4-5-20250514",
      max_tokens: 1024,
      messages: [{ role: "user", content: "Hello!" }]
  });

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

  ```sh cURL theme={"system"}
  curl https://aigw.portkey.ai/v1/messages \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{
      "model": "@anthropic-provider/claude-sonnet-4-5-20250514",
      "max_tokens": 1024,
      "messages": [{"role": "user", "content": "Hello!"}]
    }'
  ```
</CodeGroup>

<Info>
  The OpenAI SDK works directly with the AI Gateway — point `base_url` at `https://aigw.portkey.ai/v1`. For the Messages API, use the Anthropic SDK. See [Model Catalog](/docs/aigw/product/model-catalog) for provider setup.
</Info>

## Switching Providers

Change the `@provider/model` string to switch between any provider. The API format stays the same.

<CodeGroup>
  ```python OpenAI Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      api_key="PORTKEY_API_KEY",
      base_url="https://aigw.portkey.ai/v1"
  )

  # OpenAI
  response = client.chat.completions.create(
      model="@openai-provider/gpt-4o",
      messages=[{"role": "user", "content": "Hello"}]
  )

  # Switch to Anthropic -- same client, different model string
  response = client.chat.completions.create(
      model="@anthropic-provider/claude-sonnet-4-5-20250514",
      messages=[{"role": "user", "content": "Hello"}]
  )

  # Switch to Gemini
  response = client.chat.completions.create(
      model="@google-provider/gemini-2.0-flash",
      messages=[{"role": "user", "content": "Hello"}]
  )
  ```

  ```javascript OpenAI Node.js theme={"system"}
  import OpenAI from 'openai';

  const client = new OpenAI({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai/v1"
  });

  // OpenAI
  const response = await client.chat.completions.create({
      model: "@openai-provider/gpt-4o",
      messages: [{ role: "user", content: "Hello" }]
  });

  // Switch to Anthropic -- same client, different model string
  const response2 = await client.chat.completions.create({
      model: "@anthropic-provider/claude-sonnet-4-5-20250514",
      messages: [{ role: "user", content: "Hello" }]
  });
  ```

  ```sh cURL theme={"system"}
  # OpenAI
  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{"model": "@openai-provider/gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}'

  # Switch to Anthropic -- same endpoint, different model string
  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{"model": "@anthropic-provider/claude-sonnet-4-5-20250514", "messages": [{"role": "user", "content": "Hello"}]}'
  ```
</CodeGroup>

<Info>
  Set up providers and credentials in the [Model Catalog](/docs/aigw/product/model-catalog). The `@provider-slug` in the model string routes requests to the correct provider automatically.
</Info>

## Routing, Fallbacks, and Load Balancing

[Configs](/docs/aigw/product/ai-gateway/configs) enable routing strategies, fallbacks, and load balancing across providers.

<CodeGroup>
  ```python OpenAI Python theme={"system"}
  from openai import OpenAI

  # Use a saved config ID from Strata Cloud Manager
  client = OpenAI(
      api_key="PORTKEY_API_KEY",
      base_url="https://aigw.portkey.ai/v1",
      default_headers={"x-portkey-config": "pp-config-xxx"}
  )

  # Automatically falls back to Anthropic if OpenAI fails
  response = client.chat.completions.create(
      model="gpt-4o",
      messages=[{"role": "user", "content": "Hello"}]
  )
  ```

  ```javascript OpenAI Node.js theme={"system"}
  import OpenAI from 'openai';

  // Use a saved config ID from Strata Cloud Manager
  const client = new OpenAI({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai/v1",
      defaultHeaders: { "x-portkey-config": "pp-config-xxx" }
  });

  // Automatically falls back to Anthropic if OpenAI fails
  const response = await client.chat.completions.create({
      model: "gpt-4o",
      messages: [{ role: "user", content: "Hello" }]
  });
  ```

  ```sh cURL theme={"system"}
  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -H "x-portkey-config: pp-config-xxx" \
    -d '{"messages": [{"role": "user", "content": "Hello"}]}'
  ```
</CodeGroup>

Configs work with all three API formats -- Chat Completions, Responses, and Messages.

For more details, see [Configs](/docs/aigw/product/ai-gateway/configs) and [Conditional Routing](/docs/aigw/product/ai-gateway/conditional-routing).

## Local and Private Models

Route to local or private models with `custom_host`. The model must be compatible with a supported provider format.

<CodeGroup>
  ```python OpenAI Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      api_key="PORTKEY_API_KEY",
      base_url="https://aigw.portkey.ai/v1",
      default_headers={
          "x-portkey-provider": "mistral-ai",
          "x-portkey-custom-host": "http://MODEL_URL/v1/"
      }
  )

  response = client.chat.completions.create(
      model="mixtral-8x22b",
      messages=[{"role": "user", "content": "Hello"}]
  )
  ```

  ```javascript OpenAI Node.js theme={"system"}
  import OpenAI from 'openai';

  const client = new OpenAI({
      apiKey: "PORTKEY_API_KEY",
      baseURL: "https://aigw.portkey.ai/v1",
      defaultHeaders: {
          "x-portkey-provider": "mistral-ai",
          "x-portkey-custom-host": "http://MODEL_URL/v1/"
      }
  });

  const response = await client.chat.completions.create({
      model: "mixtral-8x22b",
      messages: [{ role: "user", content: "Hello" }]
  });
  ```

  ```sh cURL theme={"system"}
  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -H "x-portkey-provider: mistral-ai" \
    -H "x-portkey-custom-host: http://MODEL_URL/v1/" \
    -d '{"model": "mixtral-8x22b", "messages": [{"role": "user", "content": "Hello"}]}'
  ```
</CodeGroup>

<Note>
  Include the version identifier (e.g., `/v1`) in the `custom_host` URL. The AI Gateway appends the endpoint path (`/chat/completions`, `/responses`, etc.) automatically. For Ollama, see the [Ollama integration](/docs/aigw/integrations/llms/ollama).
</Note>

<Info>
  The AI Gateway blocks requests to private and reserved IP ranges by default to prevent SSRF attacks. If you need to route to a private network IP, see [Custom hosts](/docs/aigw/product/ai-gateway/custom-hosts) for the full list of blocked patterns and how to allowlist specific hosts.
</Info>

## Supported Endpoints

### Core Endpoints

* **[Chat Completions](/docs/aigw/product/ai-gateway/chat-completions)** — OpenAI-compatible text generation with streaming, function calling, and multimodal inputs
* **[Responses API](/docs/aigw/product/ai-gateway/responses-api)** — Next-gen format with built-in tool use and reasoning
* **[Messages API](/docs/aigw/product/ai-gateway/messages-api)** — Anthropic-compatible endpoint across all providers
* **[Images](/docs/api-reference/inference-api/images/create-image)** — Generate, edit, and create image variations (DALL-E, gpt-image-1, Stable Diffusion)
* **[Audio](/docs/api-reference/inference-api/audio/create-speech)** — Speech-to-text and text-to-speech
* **[OCR](/docs/api-reference/inference-api/ocr)** — Extract text and structured content from PDFs and images

### Advanced Capabilities

* **[Fine-tuning](/docs/aigw/product/ai-gateway/fine-tuning)** — Customize models on specific datasets
* **[Batch Processing](/docs/aigw/product/ai-gateway/batches)** — Process large request volumes efficiently
* **[Files](/docs/aigw/product/ai-gateway/files)** — Upload and manage files for fine-tuning and batch operations
* **[Moderations](/docs/api-reference/inference-api/moderations)** — Content safety and compliance checks

### Additional Endpoints

* **Gateway to Other APIs** — Proxy requests to any provider endpoint
* **[Assistants API](/docs/api-reference/inference-api/assistants-api/assistants/create-assistant)** — OpenAI Assistants with persistent threads
* **[Completions](/docs/api-reference/inference-api/completions)** — Legacy text completion endpoint

### Multimodal Capabilities

Multimodal inputs work across all three API formats:

* **[Vision](/docs/aigw/product/ai-gateway/multimodal-capabilities/vision)** — Image understanding across providers
* **[Function Calling](/docs/aigw/product/ai-gateway/multimodal-capabilities/function-calling)** — Tool use and function calling
* **[Image Generation](/docs/aigw/product/ai-gateway/multimodal-capabilities/image-generation)** — Text-to-image generation
* **[Speech-to-Text](/docs/aigw/product/ai-gateway/multimodal-capabilities/speech-to-text)** — Audio transcription
* **[Text-to-Speech](/docs/aigw/product/ai-gateway/multimodal-capabilities/text-to-speech)** — Audio generation
* **[Thinking / Reasoning](/docs/aigw/product/ai-gateway/multimodal-capabilities/thinking-mode)** — Extended reasoning modes

<Info>
  Not all providers support every endpoint or modality. See the [provider compatibility matrix](/docs/aigw/api-reference/inference-api/supported-providers) for details.
</Info>


## Related topics

- [Messages](/docs/aigw/product/ai-gateway/messages-api.md)
- [Chat Completions](/docs/aigw/product/ai-gateway/chat-completions.md)
- [Open Responses](/docs/aigw/product/ai-gateway/responses-api.md)
- [Bring Your Own LLM](/docs/aigw/integrations/llms/byollm.md)
- [AI Gateway](/docs/aigw/product/ai-gateway.md)
