Chat completions (OpenAI-compatible)
Pricing: Chat completions
Our hosted LLM speaks the OpenAI chat completions protocol, so any OpenAI SDK or OpenAI-compatible tool works by changing two settings:
| Setting | Value |
|---|---|
| Base URL | https://api.happypony.io/v1 |
| API key | your hp_… key (sent as Authorization: Bearer hp_…) |
| Model | the one id GET /v1/models returns (qwen3.8-27b on api.happypony.io at the time of writing; each deployment names its own) |
The request and response are passed through with only the proxy's own
bookkeeping added (usage reporting on streams, session affinity for the
upstream): messages (text and
image_url content parts), tools / tool_choice (tool calling),
temperature, max_tokens, response_format, reasoning /
reasoning_effort, stream, stream_options, and anything else the model
understands (llama.cpp's chat_template_kwargs is translated for upstreams
that do not know it, and a field the upstream rejects as unknown is dropped
and the request retried). Leave model out or send any id: the proxy accepts every model id and
forwards the request to its configured upstream model. Each response carries an
x-request-id header
(chatcmpl-…) that also appears in your usage rows, except
the 401, 413 and 503 answers, which are sent before a request is recorded.
Streaming. With "stream": true the answer arrives as server-sent events
(data: {…chunk…} lines, ending with data: [DONE]). Send
"stream_options": {"include_usage": true} to receive a final chunk with
usage (and an empty choices array); without it, no such chunk is sent.
Non-streaming answers. Without stream, the response is one
chat.completion JSON object, but its headers are sent as soon as the model
starts and the body begins with a few newline characters (one every 15 s)
while the model is still thinking, so a long answer is not cut off by an
HTTP timeout somewhere between you and us. Every JSON parser skips that
leading whitespace. If the model fails after the headers went out, the body
is {"error": {…, "code": "upstream_error"}} under HTTP 200 instead of a
choices array — check for error if you do not use an SDK.
Python (openai SDK)
# pip install openai | HP_KEY=hp_… python chat.py
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.happypony.io/v1", api_key=os.environ["HP_KEY"])
# One answer.
r = client.chat.completions.create(
model="qwen3.8-27b",
messages=[{"role": "user", "content": "Write a haiku about ponies."}],
)
print(r.choices[0].message.content, r.usage)
# Streaming.
stream = client.chat.completions.create(
model="qwen3.8-27b",
messages=[{"role": "user", "content": "Count to five."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
# Tool calling.
tools = [{"type": "function", "function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
}}]
r = client.chat.completions.create(
model="qwen3.8-27b",
messages=[{"role": "user", "content": "Weather in Paris?"}],
tools=tools,
)
print(r.choices[0].message.tool_calls)
Node.js (openai package)
// npm install openai | HP_KEY=hp_… node chat.mjs
import OpenAI from 'openai';
const client = new OpenAI({ baseURL: 'https://api.happypony.io/v1', apiKey: process.env.HP_KEY });
const stream = await client.chat.completions.create({
model: 'qwen3.8-27b',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'What is in this picture?' },
{ type: 'image_url', image_url: { url: 'https://example.com/pony.jpg' } },
],
},
],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
curl
curl https://api.happypony.io/v1/chat/completions \
-H "Authorization: Bearer $HP_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen3.8-27b", "messages": [{"role": "user", "content": "Hello!"}]}'
# Streaming (-N: don't buffer).
curl -N https://api.happypony.io/v1/chat/completions \
-H "Authorization: Bearer $HP_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen3.8-27b", "stream": true, "messages": [{"role": "user", "content": "Hello!"}]}'
Models
GET /v1/models lists the configured model; GET /v1/models/<any-id> returns that model. POST /v1/chat/completions accepts any model id and forwards the request to the configured upstream.
{ "object": "list", "data": [{ "id": "qwen3.8-27b", "object": "model", "created": 1793000000, "owned_by": "happypony" }] }
qwen3.8-27b is a thinking model: it reasons before it answers, and the reasoning is returned as reasoning_content on the message (or on the stream deltas). Those tokens count towards max_tokens, so give it room — with max_tokens below ~100 the reasoning alone can exhaust the budget and content comes back empty with finish_reason: "length". The model accepts image inputs (image_url content parts), tools and tool_choice: "auto" | "none" | "required"; forcing a single named function via tool_choice: {"type": "function", ...} is not honoured and behaves like "auto".
To switch reasoning off send reasoning_effort: "none" or reasoning: {"enabled": false} (llama.cpp's chat_template_kwargs: {"enable_thinking": false} is accepted too and translated); the answer then has no reasoning_content and costs fewer output tokens. If the request is served by the backup model (only while the primary is unavailable) those fields are dropped and the answer reasons, because the backup cannot switch it off. Messages must follow the model's chat template: exactly one system message, and only as the first message, otherwise the request is rejected with a 400 whose code is invalid_messages (not failed over).
Usage and cost
GET /api/v1/account/llm-usage (API key, or signed in on www.happypony.io)
returns your requests in a time window with their tokens and cost.
| Query | Default | |
|---|---|---|
from, to |
the last 30 days | ISO dates; from inclusive, to exclusive |
limit |
50 | rows per page, at most 200 |
offset |
0 |
{
"totals": { "requests": 2, "prompt_tokens": 2000, "cached_tokens": 400, "completion_tokens": 1000, "cost_usd": 0.00094, "cost_credits": 0.094 },
"pricing": { "model": "qwen3.8-27b", "input_usd_per_m": 0.2, "cached_usd_per_m": 0.05, "output_usd_per_m": 0.6 },
"rows": [
{ "id": 12, "request_id": "chatcmpl-…", "created_at": "2026-10-26T10:00:00.000Z", "model": "qwen3.8-27b",
"upstream": "primary", "stream": true, "status": 200, "prompt_tokens": 1000, "cached_tokens": 200,
"completion_tokens": 500, "usage_source": "upstream", "cost_usd": 0.00047, "latency_ms": 2310, "ttft_ms": 420, "error": null }
]
}
A malformed from, to, limit or offset is 400 invalid_request. totals cover the whole window, rows are one page of it, newest first.
usage_source is upstream (the model's own token counts), estimated
(~4 characters per token, when the model never reported them) or none (the
request never reached the model). pricing is null when no price is
configured.
Errors
Errors use OpenAI's shape, so SDKs raise them as the matching exception:
{"error": {"message": "…", "type": "…", "code": "…"}}.
| Status | code |
When |
|---|---|---|
| 400 | — (type: invalid_request_error) |
Bad JSON, no messages, a non-boolean stream; or the model refused the parameters (any 4xx other than a dropped unknown field is passed through as the model sent it, not failed over). |
| 400 | invalid_messages |
More than one system message, or one that is not first (see Models). |
| 401 | invalid_api_key |
Missing, wrong or revoked API key. |
| 402 | insufficient_credits |
Balance below the minimum to start a request, checked before the body is read. Top up at www.happypony.io/payment. |
| 404 | unknown_url |
A path under /v1/ other than chat completions and models. |
| 413 | request_too_large |
Body above 16 MiB (large images: send a URL rather than base64). |
| 429 | concurrency_limit |
Too many requests in flight on your account (16). Retry after retry-after seconds. |
| 502 | upstream_error |
The model is unavailable. Retry. |
| 503 | not_configured |
The API is not enabled on the server, or no price is configured for the model. |
A stream that breaks after it has started ends with an {"error": {…}} chunk
instead of [DONE]: the model's own type and code when it sent an error,
upstream_error otherwise.