---
title: "AI Gateway"
description: "Call language models through the OnePloy AI gateway API with one OpenAI-style chat completions endpoint, paid from prepaid credits."
url: https://oneploy.dev/docs/ai/ai-gateway/
type: op_doc
published: 2026-11-02T19:09:49+00:00
updated: 2026-11-02T19:09:49+00:00
author: "admin"
language: en-US
---

# AI Gateway

> Call language models through the OnePloy AI gateway API with one OpenAI-style chat completions endpoint, paid from prepaid credits.

The OnePloy AI Gateway gives your team one endpoint, `POST /api/v1/ai/chat/completions`, for calling language models. Requests use the OpenAI chat completions request and response shape, authenticate with a OnePloy API token, and are paid from your team’s prepaid AI credits. Streaming is not supported.

## How do I start using the AI Gateway?

1. Open **AI Gateway** in the sidebar (team owners and admins).
2. Add credits if the balance is zero. One credit is $0.01 of usage.
3. Note a model alias from **Configured model aliases** on the **Docs & models** tab.
4. Create an API token with the Write permission under **Keys & Tokens**, then **API tokens**.
5. Send a request.

You can also try a model in the page’s **Playground** first. It sends a real request through the same endpoint and spends the same credits.

The AI Gateway must be included in your plan. Compare plans on the [Billing](https://oneploy.dev/docs/billing/) page. If the page says the AI Gateway is not enabled or lists no models, contact [support](https://oneploy.dev/contact-us/).

## How do I send a request?

```bash
curl https://app.oneploy.dev/api/v1/ai/chat/completions \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1234-summary" \
  -d '{
    "model": "MODEL_ALIAS",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Summarise this order in one sentence."}
    ],
    "max_tokens": 200
  }'
```

Replace `MODEL_ALIAS` with one of the aliases shown on the AI Gateway page.

## Which request fields are accepted?

| Field | Rules |
| --- | --- |
| `model` | Required. A configured model alias. |
| `messages` | Required. 1 to 100 messages, each with only `role` (`system`, `user` or `assistant`) and `content` (a string up to 50,000 characters). Total content up to 200,000 characters. |
| `max_tokens` | 1 to 32,768. A default applies when you leave it out. |
| `temperature` | 0 to 2. |
| `top_p` | 0 to 1. |
| `stop` | A string up to 200 characters. |
| `presence_penalty`, `frequency_penalty` | -2 to 2. |
| `seed` | Integer. |
| `stream` | Only `false`. Streaming is rejected. |

Any other field is rejected with a validation error.

## How do idempotency keys work?

Send an `Idempotency-Key` header (8 to 128 URL-safe characters) to make retries safe. If you repeat a request with the same key and body, OnePloy returns the stored response instead of calling the model again, and adds the header `X-OnePloy-Idempotent-Replay: true`. Reusing a key with a different body returns a conflict.

## How is usage charged?

When a request starts, OnePloy sets aside enough credits to cover its largest possible cost. When the response arrives, you are charged the actual token cost and the rest is released. The AI Gateway page shows available credits, credits on hold for requests in progress, requests made, tokens used and tokens remaining in your plan’s monthly budget.

## What errors can I get?

| Status | Code | Meaning |
| --- | --- | --- |
| 402 | `insufficient_credits` | Not enough credits. Top up on the AI Gateway page. |
| 409 | `idempotency_conflict` or `request_in_progress` | The idempotency key was reused with a different body, or the first request is still running. |
| 422 | `model_not_allowed` or validation error | Unknown model alias or invalid fields. |
| 429 | `monthly_token_budget_exhausted` | Your plan’s monthly token budget is used up. Too many requests per minute also return 429. |
| 502 or 503 | `upstream_unavailable`, `upstream_error`, `upstream_rate_limited`, `gateway_disabled`, `provider_not_configured` | The model or the gateway is temporarily unavailable. Retry later. |

Errors use the body shape `{"error": {"message": "...", "type": "gateway_error", "code": "..."}}`.

**Tip:** Reuse the same `Idempotency-Key` when you retry after a 502, 503 or a network timeout, so a request that did succeed is never charged twice.

---

Source: https://oneploy.dev/docs/ai/ai-gateway/ · OnePloy
