Use AI in your deployment with AI Tokens
Turn AI on for a deployment and your code can call AI models right away. You pay with the AI Tokens you already have.
Updated Dec 5, 2026Any deployment can call AI models, a website, an API or a worker as much as a Discord or Telegram bot. Turn AI on and Bot-Hosting gives the deployment its own key and an address that works with the official OpenAI libraries. You do not open an account at an AI provider, and every request is paid from your AI Tokens.
Turn it on
Open the deployment, then AI. Pick a default model, accept the providers' terms and select Turn on AI. Only the owner of the deployment can do this, because usage is paid from the owner's AI Tokens.
The key is shown once on the page. It is already saved in the deployment's variables, so there is nothing to copy. Restart the deployment so your code sees the new variables.
The environment variables
Bot-Hosting adds three environment variables to the deployment.
| Variable | What it holds |
|---|---|
OPENAI_BASE_URL |
The address of Bot-Hosting AI, https://bot-hosting.net/api/ai/v1 |
OPENAI_API_KEY |
The key of this deployment, starting with bhai_ |
BOTHOSTING_AI_MODEL |
The default model you picked |
The OpenAI libraries read the first two on their own. They have no variable for the model, so your code passes BOTHOSTING_AI_MODEL as model.
When the deployment already has OpenAI variables
If OPENAI_BASE_URL or OPENAI_API_KEY already holds a value of your own, such as the key of your own OpenAI account, Bot-Hosting leaves both untouched. It writes BOTHOSTING_AI_BASE_URL and BOTHOSTING_AI_API_KEY instead, and the AI page tells you. Pass them to the library yourself.
const ai = new OpenAI({
baseURL: process.env.BOTHOSTING_AI_BASE_URL,
apiKey: process.env.BOTHOSTING_AI_API_KEY,
});
ai = OpenAI(
base_url=os.environ["BOTHOSTING_AI_BASE_URL"],
api_key=os.environ["BOTHOSTING_AI_API_KEY"],
)
Node.js
Install the library with npm install openai. It reads the address and the key from the environment on its own.
import OpenAI from "openai";
const ai = new OpenAI({ timeout: 60_000, maxRetries: 2 });
const answer = await ai.chat.completions.create({
model: process.env.BOTHOSTING_AI_MODEL,
messages: [
{ role: "system", content: "You answer in two sentences." },
{ role: "user", content: "What is a webhook?" },
],
});
console.log(answer.choices[0].message.content);
Python
Install the library with pip install openai.
import os
from openai import OpenAI
ai = OpenAI(timeout=60, max_retries=2)
answer = ai.chat.completions.create(
model=os.environ["BOTHOSTING_AI_MODEL"],
messages=[
{"role": "system", "content": "You answer in two sentences."},
{"role": "user", "content": "What is a webhook?"},
],
)
print(answer.choices[0].message.content)
curl
From the deployment's shell, or from any language that can send HTTP.
curl "$OPENAI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-6-luna", "messages": [{"role": "user", "content": "What is a webhook?"}]}'
GET $OPENAI_BASE_URL/models returns every model id the key can use. Any other library that speaks the OpenAI chat completions API works with the same address and key.
Streaming
Add stream: true and the answer arrives in pieces, as with OpenAI. Show it while the model writes, in a chat page or in a message you edit.
const stream = await ai.chat.completions.create({
model: process.env.BOTHOSTING_AI_MODEL,
messages: [{ role: "user", content: "Explain DNS in three sentences." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
stream = ai.chat.completions.create(
model=os.environ["BOTHOSTING_AI_MODEL"],
messages=[{"role": "user", "content": "Explain DNS in three sentences."}],
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
Ask for stream_options: { include_usage: true } if you want the token counts in the last chunk. That chunk has no choices, which is why the loops above check for them.
Tool calling
The model can ask your code to run a function, then answer with its result. Describe the function, run it when the model asks, and send the result back.
const tools = [{
type: "function",
function: {
name: "get_order_status",
description: "Returns the delivery status of an order",
parameters: {
type: "object",
properties: { id: { type: "string" } },
required: ["id"],
},
},
}];
const messages = [{ role: "user", content: "Where is order 1042?" }];
const model = process.env.BOTHOSTING_AI_MODEL;
const first = await ai.chat.completions.create({ model, messages, tools });
const reply = first.choices[0].message;
if (reply.tool_calls) {
messages.push(reply);
for (const call of reply.tool_calls) {
const { id } = JSON.parse(call.function.arguments);
const status = await getOrderStatus(id); // your own function
messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify(status) });
}
const final = await ai.chat.completions.create({ model, messages, tools });
console.log(final.choices[0].message.content);
} else {
console.log(reply.content);
}
The twelve recommended models below all passed a tool-calling test. Among the other models, check the model page of its maker before you rely on tools. Models with image input also accept image_url parts in a message, as with OpenAI.
Choose a model
GPT-6 Luna is the default and the cheapest. The twelve models below are the recommended ones. Each was tested with tools and its price is measured.
| Model | Id | Input, per million tokens | Output, per million tokens | Short messages for 1 EUR |
|---|---|---|---|---|
| GPT-6 Luna | gpt-6-luna |
111,000 (0.17 EUR) | 442,000 (0.66 EUR) | about 5,500 |
| Claude Haiku 5.5 | claude-haiku-5.5 |
111,000 (0.17 EUR) | 442,000 (0.66 EUR) | about 5,500 |
| DeepSeek V4.1 Flash | deepseek-v4.1-flash |
265,000 (0.40 EUR) | 1,062,000 (1.59 EUR) | about 2,300 |
| gpt-oss 120B | gpt-oss-120b |
265,000 (0.40 EUR) | 1,062,000 (1.59 EUR) | about 2,300 |
| GLM 5.3 Flash | glm-5.3-flash |
265,000 (0.40 EUR) | 885,000 (1.32 EUR) | about 2,500 |
| Gemini 3.8 Flash | gemini-3.8-flash |
663,000 (0.99 EUR) | 3,317,000 (4.96 EUR) | about 810 |
| Qwen3.8 27B | qwen3.8-27b |
885,000 (1.32 EUR) | 5,308,000 (7.94 EUR) | about 540 |
| Kimi K2.6 | kimi-k2.6 |
1,415,000 (2.12 EUR) | 6,015,000 (8.99 EUR) | about 420 |
| Claude Sonnet 5.5 | claude-sonnet-5.5 |
2,212,000 (3.31 EUR) | 8,846,000 (13.22 EUR) | about 270 |
| GPT-6.2 Sol | gpt-6.2-sol |
2,212,000 (3.31 EUR) | 8,846,000 (13.22 EUR) | about 270 |
| Gemini 3.1 Pro | gemini-3.1-pro |
1,769,000 (2.64 EUR) | 10,615,000 (15.87 EUR) | about 270 |
| Grok 4.7 | grok-4.7 |
1,769,000 (2.64 EUR) | 5,308,000 (7.94 EUR) | about 400 |
Prices are in AI Tokens. The euro figures use the Starter pack (2.99 EUR for 2,000,000 AI Tokens, before tax), the smallest one. Larger packs cost less per token. A short message is 500 tokens in and 150 tokens out.
All the other models
More than 300 other chat models are available, from the same makers and many others, such as Mistral, Llama and Qwen. The AI page lists them under All models with a search field, and GET /v1/models returns their ids, such as anthropic/claude-opus-5.5. Their prices are shown with ≈ because they are estimated from the provider's list price.
Set the model
There are two ways, and they mix well.
- The default model. Pick it on the AI page. Bot-Hosting updates
BOTHOSTING_AI_MODEL, and your code picks it up at the next restart. Code that reads the variable never needs to change. - A model per request. Pass any id as
model, for exampleclaude-haiku-5.5for quick replies andclaude-sonnet-5.5for the hard questions.
What a request costs
Each request is charged from what it really cost to run. The prices above are a guide, and the exact amount depends on the request. A prompt the model already has in cache costs less, and a model can be billed a little above or below its list price. The AI page shows what each day and each model used.
Monthly limit
Each deployment has a monthly limit, 5,000,000 AI Tokens by default. It protects your balance from a loop in your code. You get a notification at 50%, 75% and 90%, and the deployment stops using AI when the limit is reached, until you raise it or the month ends. Change it on the AI page, from 100,000 to 1,000,000,000 AI Tokens.
AI Tokens
There is one balance of AI Tokens for your whole account, the same one Ask AI and Studio use. Buy AI Tokens in Billing, AI Tokens. Packs have no subscription and never expire.
Only purchased AI Tokens are used by your deployments. The free weekly allowance and the tokens included in a plan are not, so a deployment never eats the allowance you use in the panel.
Errors
Errors have the same shape as OpenAI's, so your library raises its usual exceptions. The message says what to do.
| Status | Code | What to do |
|---|---|---|
| 401 | missing_api_key, invalid_api_key |
The key is missing, was regenerated or AI was turned off. Check the AI page and restart the deployment |
| 402 | insufficient_quota |
No purchased AI Tokens left, or the monthly limit is reached. The message says which. Do not retry |
| 403 | account_suspended |
AI was suspended for your account. Contact support |
| 403 | gateway_disabled |
AI is turned off for this deployment. Turn it on again on the AI page |
| 403 | source_not_allowed |
The key was used outside its deployment. Call the API from the deployment itself |
| 404 | model_not_found |
The message lists the recommended model ids, and GET /v1/models lists them all |
| 400 | context_length_exceeded |
The conversation is too long for the model. Send fewer messages |
| 400 | invalid_request |
The request is not valid. The message gives the detail |
| 413 | request_too_large |
The request is over 16 MB, usually because of images. Send smaller images |
| 429 | rate_limit_exceeded |
More than 60 requests a minute or 4 at once from this deployment. Wait the time given in retry-after |
| 429 | upstream_busy |
The AI service is busy. Wait the time given in retry-after |
| 503 | service_unavailable |
The AI service did not answer. Nothing is charged. Try again a little later |
| 504 | upstream_timeout |
The model took too long to answer. Nothing is charged. Try again |
When the balance is empty
Requests are refused with status 402 and nothing is charged. Your deployment keeps running, only its AI calls fail. Catch the error and answer without AI instead of crashing.
try {
const answer = await ai.chat.completions.create({ model: process.env.BOTHOSTING_AI_MODEL, messages });
return answer.choices[0].message.content;
} catch (error) {
if (error.status === 402) return "AI is paused for now.";
throw error;
}
Regenerate the key
Select Regenerate key on the AI page if you think the key leaked. The old key stops working at once, the new one is written to the variables, and the new key is shown once. Restart the deployment so it uses the new key.
Good practice
- Set a timeout and retries.
new OpenAI({ timeout: 60_000, maxRetries: 2 })in Node.js,OpenAI(timeout=60, max_retries=2)in Python. The libraries retry 429, 503 and 504 on their own and followretry-after. - Do not retry 401, 402 and 403. Trying again cannot fix them, so show a short message and log the error code.
- Never log the key. Do not print
OPENAI_API_KEY, do not commit it and do not paste it in a support ticket. It lives in the deployment's variables, and that is enough. - Send only what the model needs. Keep the last messages of a conversation rather than all of them. Shorter prompts are cheaper and faster.
- Stream long answers. People see the first words at once, and the connection stays busy instead of idle.
- Keep the monthly limit close to your real use. It is the cheapest protection against a bug that loops.
Turn it off
Select Turn off on the AI page. The key stops working within a few seconds and the variables Bot-Hosting added are removed.