NewHost Docs

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 creditsYour own provider key
Who bills youNewHost, in rand, from prepaid creditsThe provider, on your own account
ModelsThose listed by GET /ai/v1/modelsAnything that provider offers
Set upBuy credits on the dashboard's AI pageSave 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

  1. Create a secret key with the ai scope under Developers.
  2. Buy credits or add a provider key on the dashboard's AI page.
  3. 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_tokens defaults to 16 000 when not set.
  • temperature and top_p are 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:

StatusWhen
402Your AI credit balance is below R0.50 and you have no key saved for that provider.
400Unknown model name, or a model that isn't sold on credits (add your own key to use it).
403The API key lacks the ai scope.
429 / 502The provider rate-limited or failed the request. Retry with backoff.
Keep your NewHost secret key on your server. Anyone with it can spend your AI credits.