AI gateway
The AI gateway gives your apps one OpenAI-compatible endpoint for many AI providers: Anthropic (Claude), OpenAI, Google Gemini, Mistral, Groq, DeepSeek, xAI and OpenRouter. Use any OpenAI SDK or HTTP client, change the base URL, and pick a model as provider/model.
Two ways to pay
| NewHost AI credits | Your own provider key | |
|---|---|---|
| Who bills you | NewHost, in rand, from prepaid credits | The provider, on your own account |
| Models | Those listed by GET /ai/v1/models | Anything that provider offers |
| Set up | Buy credits on the dashboard's AI page | Save your key on the AI page (stored encrypted) |
If you've saved a key for a provider, requests to that provider always use it. The AI page also has links to create an account with each provider.
Quick start
- Create a secret key with the
aiscope under Developers. - Buy credits or add a provider key on the dashboard's AI page.
- Call the gateway:
Node.js (openai package)
import OpenAI from "openai";
const ai = new OpenAI({ baseURL: "https://api.newhost.co.za/ai/v1", apiKey: process.env.NEWHOST_SECRET_KEY });
const res = await ai.chat.completions.create({
model: "anthropic/claude-opus-5",
messages: [{ role: "user", content: "Summarise our returns policy in two sentences." }],
});
console.log(res.choices[0].message.content);Python (openai package)
from openai import OpenAI
import os
ai = OpenAI(base_url="https://api.newhost.co.za/ai/v1", api_key=os.environ["NEWHOST_SECRET_KEY"])
res = ai.chat.completions.create(
model="anthropic/claude-opus-5",
messages=[{"role": "user", "content": "Summarise our returns policy in two sentences."}],
)
print(res.choices[0].message.content)curl
curl https://api.newhost.co.za/ai/v1/chat/completions \
-H "Authorization: Bearer $NEWHOST_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"anthropic/claude-opus-5","messages":[{"role":"user","content":"Hello"}]}'Streaming
Set stream: true to receive chat.completion.chunk server-sent events, ending with data: [DONE]. The final chunk before it includes usage.
Node.js
const stream = await ai.chat.completions.create({ model: "anthropic/claude-opus-5", messages, stream: true });
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");Models and pricing
GET /ai/v1/models lists the models available on credits with the rand price per million input and output tokens. Prices follow each provider's list price. Tokens are counted by the provider, and each request's cost is shown on the AI page.
Notes for Claude models
- System messages become Claude's system prompt; text and image parts are supported.
max_tokensdefaults to 16 000 when not set.temperatureandtop_pare ignored: current Claude models don't accept sampling parameters.- Tool calling isn't translated yet. Call Anthropic directly for tool use.
Errors
Errors use the standard error format. Gateway-specific cases:
| Status | When |
|---|---|
| 402 | Your AI credit balance is below R0.50 and you have no key saved for that provider. |
| 400 | Unknown model name, or a model that isn't sold on credits (add your own key to use it). |
| 403 | The API key lacks the ai scope. |
| 429 / 502 | The provider rate-limited or failed the request. Retry with backoff. |