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.
While a request on credits runs, what it may cost is held from your balance: its prompt plus its max_tokens (16 000 when not set) of output, at most your balance. When it finishes the hold is released and you are charged what it actually cost. Requests sent in parallel each hold their share, so a low balance runs out sooner: set max_tokens to what you need.
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 | Code | When |
|---|---|---|
| 402 | plan_limit | Your AI credit balance (after what your running requests hold) is below R0.50 and you have no key saved for that provider. |
| 400 | invalid_request | Unknown model name, or a model that isn't sold on credits (add your own key to use it). |
| 403 | insufficient_scope | The API key lacks the ai scope. |
| 400 | ai_provider_error | The provider rejected the request, e.g. too many tokens or an image it can't read. |
| 429 | rate_limited | The provider is limiting requests. Retry with backoff. |
| 502 | ai_provider_unavailable | The provider failed or couldn't be reached. Retry with backoff. |
On NewHost credits, the provider's answer is about NewHost's own account with it, so the message of a provider error is a general text. With your own key, it is the error message your provider returned.
When a stream fails after it started, its last event carries the same error object:
data: {"error":{"message":"The AI provider couldn't complete the request right now. Retry with backoff.","code":"ai_provider_unavailable","status":502}}