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

# Send Your First AI Request via the Portrix Gateway

> Walk through making your first AI model request using the Portrix gateway. Includes cURL, Python, and JavaScript examples you can run immediately.

This guide walks you through making a live request to an AI model via Portrix. Whether you prefer the command line, Python, or JavaScript, you'll have a working request running in under five minutes — with access to 400+ models through a single endpoint.

## Before you begin

<Card title="Prerequisites">
  * A Portrix API key — grab one at [app.portrix.ai](https://app.portrix.ai)
  * `curl` installed, or a code editor with Python 3.8+ or Node.js 18+
</Card>

## Using cURL

The fastest way to verify your setup is a raw `curl` request. Replace `YOUR_API_KEY` with your actual key:

```bash theme={null}
curl https://api.portrix.ai/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "What is the capital of France?"
      }
    ]
  }'
```

You should receive a JSON response within a few seconds. If you see a `401` error, double-check that your API key is correct and that you have not included extra whitespace.

## Using Python

Install the official OpenAI SDK — Portrix is fully compatible with it:

```bash theme={null}
pip install openai
```

Then point the client at the Portrix base URL:

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.portrix.ai/v1",
)

response = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[
        {"role": "user", "content": "What is the capital of France?"}
    ],
)

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

## Using JavaScript / TypeScript

Install the OpenAI npm package:

```bash theme={null}
npm install openai
```

Configure the client with the Portrix base URL:

```typescript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://api.portrix.ai/v1",
});

const response = await client.chat.completions.create({
  model: "openai/gpt-4o",
  messages: [
    { role: "user", content: "What is the capital of France?" },
  ],
});

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

## Understanding the response

A successful response follows the standard OpenAI chat completions shape:

```json theme={null}
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1714000000,
  "model": "openai/gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 9,
    "total_tokens": 24
  }
}
```

The fields you'll use most often:

| Field                        | Description                                             |
| ---------------------------- | ------------------------------------------------------- |
| `choices[0].message.content` | The model's text reply                                  |
| `choices[0].finish_reason`   | Why generation stopped (`stop`, `length`, `tool_calls`) |
| `usage.total_tokens`         | Total tokens consumed — used for billing                |
| `id`                         | Unique request ID, useful when contacting support       |

## Legacy text completions

Portrix also supports the `POST /v1/completions` endpoint for older integrations that use the non-chat completions format. The request shape mirrors the OpenAI legacy completions API — use a `prompt` string instead of a `messages` array:

```bash theme={null}
curl https://api.portrix.ai/v1/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-3.5-turbo-instruct",
    "prompt": "The capital of France is",
    "max_tokens": 10
  }'
```

For all new integrations, prefer `POST /v1/chat/completions` — it is supported by every model on Portrix and is the format used throughout this documentation.

## Switching models

One of Portrix's core benefits is that changing the underlying model requires updating a single string. Everything else in your code stays identical:

<CodeGroup>
  ```python Python — Claude theme={null}
  response = client.chat.completions.create(
      model="anthropic/claude-3-5-sonnet",   # changed from openai/gpt-4o
      messages=[
          {"role": "user", "content": "What is the capital of France?"}
      ],
  )
  ```

  ```python Python — Gemini theme={null}
  response = client.chat.completions.create(
      model="google/gemini-2.0-flash",       # changed from openai/gpt-4o
      messages=[
          {"role": "user", "content": "What is the capital of France?"}
      ],
  )
  ```

  ```typescript TypeScript — Claude theme={null}
  const response = await client.chat.completions.create({
    model: "anthropic/claude-3-5-sonnet",    // changed from openai/gpt-4o
    messages: [
      { role: "user", content: "What is the capital of France?" },
    ],
  });
  ```
</CodeGroup>

<Tip>
  If you already have working OpenAI code, migrating to Portrix requires exactly two changes: set `base_url` / `baseURL` to `https://api.portrix.ai/v1`, and replace your OpenAI key with your Portrix API key. Your prompts, tools, and response-parsing logic need no modifications.
</Tip>
