> ## 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.

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.

> **[Chat Completions](https://docs.portkey.ai/docs/aigw/product/ai-gateway/chat-completions.md)**
>
> **OpenAI spec** · `POST /v1/chat/completions`
>
> Widest ecosystem compatibility

> **[Responses API](https://docs.portkey.ai/docs/aigw/product/ai-gateway/responses-api.md)**
>
> **OpenAI spec** · `POST /v1/responses`
>
> Agentic AI with built-in tool use

> **[Messages API](https://docs.portkey.ai/docs/aigw/product/ai-gateway/messages-api.md)**
>
> **Anthropic spec** · `POST /v1/messages`
>
> Native Anthropic format across providers

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

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

```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!"}]
  }'
```

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

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

```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!"
  }'
```

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

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

```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!"}]
  }'
```

> [!NOTE]
>
> 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](https://docs.portkey.ai/docs/aigw/product/model-catalog.md) for provider setup.

## Switching Providers

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

```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"}]}'
```

> [!NOTE]
>
> Set up providers and credentials in the [Model Catalog](https://docs.portkey.ai/docs/aigw/product/model-catalog.md). The `@provider-slug` in the model string routes requests to the correct provider automatically.

## Routing, Fallbacks, and Load Balancing

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

```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"}]}'
```

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

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

## Local and Private Models

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

```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"}]}'
```

> [!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](https://docs.portkey.ai/docs/aigw/integrations/llms/ollama.md).

> [!NOTE]
>
> 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](https://docs.portkey.ai/docs/aigw/product/ai-gateway/custom-hosts.md) for the full list of blocked patterns and how to allowlist specific hosts.

## Supported Endpoints

### Core Endpoints

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

### Advanced Capabilities

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

### Additional Endpoints

* **Gateway to Other APIs** — Proxy requests to any provider endpoint
* **[Assistants API](https://docs.portkey.ai/docs/aigw/api-reference/assistants/create-assistant.md)** — OpenAI Assistants with persistent threads
* **[Completions](https://docs.portkey.ai/docs/aigw/api-reference/completions/create-completion.md)** — Legacy text completion endpoint
* **[Decisions](https://docs.portkey.ai/docs/aigw/product/ai-gateway/decisions-api.md)** — Typed judgments (choice, score, probability) via `/v1/decisions`, currently available through [TypeSafe's Jev models](https://docs.portkey.ai/docs/aigw/integrations/llms/typesafe.md)

### Multimodal Capabilities

Multimodal inputs work across all three API formats:

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

> [!NOTE]
>
> Not all providers support every endpoint or modality. See the [provider compatibility matrix](https://docs.portkey.ai/docs/aigw/api-reference/inference-api/supported-providers.md) for details.


## Related topics

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.