Skip to content

AI Gateway

Diploi provides an AI Gateway inside every deployment so your apps, agents and coding tools can use AI models without provider API keys. Usage is billed from the same account balance as your deployments.

The gateway works with the OpenAI and Anthropic APIs and supports streaming. The cloud IDE, OpenCode and the Prompt view in the console already use it.

Connect using these values from any process running inside your deployment:

  • Base URL: http://core.diploi/ai-core-proxy
  • Authentication: Bearer token, unique to each deployment

You do not need to copy these values by hand. Diploi fills them in for you when you use these placeholders in diploi.yaml (see Using the gateway in a component):

Placeholder Value
{diploi-ai-gateway-url} http://core.diploi/ai-core-proxy
{diploi-ai-gateway-token} The token of this deployment

Development environments also have these environment variables set:

Environment variable Value
DIPLOI_AI_API_BASE_URL http://core.diploi/ai-core-proxy/v1
DIPLOI_AI_TOKEN The token of this deployment

Add the path of the API you are calling to the gateway URL:

  • OpenAI: {diploi-ai-gateway-url}/openai/v1
  • Anthropic: {diploi-ai-gateway-url}/anthropic

The gateway also accepts the older OpenAI-style path {diploi-ai-gateway-url}/v1/..., which is where DIPLOI_AI_API_BASE_URL points. On that path the gateway picks the provider from the model field.

Kimi, GLM and Qwen models only work on the /v1 path, not on /openai/ or /anthropic/.

Send the deployment token in one of these ways:

  • Authorization: Bearer <token> header
  • x-api-key: <token> header
  • ?key=<token> query parameter

Each deployment has its own token, and cloning or re-enabling a deployment gives it a new one. Read the token from the environment instead of hard-coding it.

These examples read the URL and token from DIPLOI_AI_GATEWAY_URL and DIPLOI_AI_GATEWAY_TOKEN, which you can set up as shown in Using the gateway in a component.

import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.DIPLOI_AI_GATEWAY_TOKEN,
baseURL: `${process.env.DIPLOI_AI_GATEWAY_URL}/openai/v1`,
});
const response = await openai.chat.completions.create({
model: "gpt-5.6-terra",
messages: [{ role: "user", content: "Say hello from Diploi." }],
});

Streaming works the same way as with OpenAI (stream: true).

In the cloud IDE you can use process.env.DIPLOI_AI_TOKEN and process.env.DIPLOI_AI_API_BASE_URL instead. That base URL already ends with /v1, so pass it to baseURL as it is.

import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: process.env.DIPLOI_AI_GATEWAY_TOKEN,
baseURL: `${process.env.DIPLOI_AI_GATEWAY_URL}/anthropic`,
});
const message = await anthropic.messages.create({
model: "claude-sonnet-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Say hello from Diploi." }],
});
Terminal window
curl http://core.diploi/ai-core-proxy/openai/v1/chat/completions \
-H "Authorization: Bearer $DIPLOI_AI_GATEWAY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-terra",
"messages": [{"role": "user", "content": "Say hello from Diploi."}]
}'

Add the placeholders as environment variables of the component that calls the gateway. Diploi fills them in when the deployment starts:

components:
- name: Node.js
identifier: api
package: https://github.com/diploi/component-nodejs#main
env:
include:
- name: DIPLOI_AI_GATEWAY_URL
value: '{diploi-ai-gateway-url}'
- name: DIPLOI_AI_GATEWAY_TOKEN
value: '{diploi-ai-gateway-token}'

You can also set these variables in the Options tab of the deployment. The placeholders work in any environment variable, so you can use the names your framework expects, such as OPENAI_API_KEY and OPENAI_BASE_URL.

This works in development, staging and production deployments, and any component in the deployment can call core.diploi.

Diploi’s own AI tools already use the gateway, so there is nothing to set up for them.

In the console, open a development deployment and switch to the Prompt view. Describe the change you want, and the agent edits the code for you.

OpenCode is set up in every development environment. Run opencode in the cloud IDE or in an SSH session.

Continue is set up in the cloud IDE with Diploi models selected.

Usage from these tools is billed from your balance, the same way as calls from your own app.

Send the model ID exactly as listed. Kimi, GLM and Qwen models use the /v1 path (see URL formats).

ModelModel ID
GPT-6 Astragpt-6-astra
GPT-6 Solgpt-6-sol
GPT-6 Lunagpt-6-luna
Claude Fable 5.1claude-fable-5-1
Claude Opus 5.5claude-opus-5-5
Claude Sonnet 5claude-sonnet-5
Kimi K2.7 Codekimi-k2.7-code
GLM 5.3 Flashglm-5.3-flash
Qwen 3.8-27Bqwen3.8-27b

If a request returns Model … is currently not supported, check the model ID against this list.

AI usage is paid from the same prepaid balance as cluster hours, and there is no separate AI subscription. You can see your spending per model on the Billing page of your account.

On the Trial plan, €1 of AI usage per day is included. The allowance resets at 00:00 UTC, and trial AI usage also uses up your trial credits. To keep going after the daily limit, choose a plan.

On Pay as you go, Pro and Ultra, AI usage is billed at model rates from your balance. Pro gets 5% off AI usage and Ultra gets 10% off.

When your balance runs out, requests are refused until you add funds. A refused request gets an HTTP 402 response, with an error that says whether the trial’s daily limit was reached or the balance ran out.

  • Use the {diploi-ai-gateway-url} and {diploi-ai-gateway-token} placeholders instead of copying values from another deployment.
  • Call the gateway from server-side code, and never expose the token to browsers or public clients.
  • Use cheaper models, such as GPT Terra, for high-volume or background jobs.
  • If your app uses AI all the time in production, keep an eye on the Billing page and turn on auto top-up, so the app does not stop when the balance runs out.
  • If you need a model Diploi does not offer, use your own provider key. Those calls are not billed through Diploi.