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.

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_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:

StatusCodeWhen
402plan_limitYour AI credit balance (after what your running requests hold) is below R0.50 and you have no key saved for that provider.
400invalid_requestUnknown model name, or a model that isn't sold on credits (add your own key to use it).
403insufficient_scopeThe API key lacks the ai scope.
400ai_provider_errorThe provider rejected the request, e.g. too many tokens or an image it can't read.
429rate_limitedThe provider is limiting requests. Retry with backoff.
502ai_provider_unavailableThe 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}}
Keep your NewHost secret key on your server. Anyone with it can spend your AI credits.