API reference
AI gateway
OpenAI-compatible chat completions for Claude, GPT, Gemini and more, on NewHost credits or your own provider key.
- List AI models
GET /ai/v1/models - Create a chat completion
POST /ai/v1/chat/completions
List AI models
GET/ai/v1/models
Models available on NewHost credits with their price in rand per million tokens, and the providers that accept your own key.
Works with a public key (browser-safe) or a secret key.
Request
curl "https://api.newhost.co.za/ai/v1/models" \
-H "X-Public-Key: pk_live_..."Response
{
"object": "list",
"data": [
{
"id": "anthropic/claude-opus-5",
"object": "model",
"owned_by": "anthropic",
"name": "Claude Opus 5",
"credits": true,
"pricing_zar_per_million": {
"input": "120.25",
"output": "601.25"
}
}
],
"byok_providers": [
{
"id": "anthropic",
"name": "Anthropic (Claude)"
},
{
"id": "openai",
"name": "OpenAI"
}
]
}Create a chat completion
POST/ai/v1/chat/completions
OpenAI-compatible. Name the model as provider/model. Uses your saved key for that provider when you have one (billed by the provider), otherwise NewHost credits. Set stream: true for server-sent events; the last chunk carries usage. Responses are in OpenAI's format for every provider.
Requires a secret key with the ai scope.
Body
| Field | Type | Description |
|---|---|---|
modelrequired | string | provider/model, e.g. anthropic/claude-opus-5 or openai/<model>. |
messagesrequired | array | OpenAI chat messages (system, user, assistant); user content may include image_url parts. |
max_tokens | integer | Output limit (Claude default 16000). |
stream | boolean | Stream chat.completion.chunk events. |
stop | string | string[] | Stop sequences. |
Request
curl -X POST "https://api.newhost.co.za/ai/v1/chat/completions" \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{"model":"anthropic/claude-opus-5","messages":[{"role":"system","content":"You are concise."},{"role":"user","content":"Write a haiku about Table Mountain"}]}'Response
{
"id": "msg_01…",
"object": "chat.completion",
"model": "anthropic/claude-opus-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Flat stone crown of clouds…"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 19,
"total_tokens": 43
}
}