API reference
OpenAI-compatible. Endpoints, schemas, error codes, rate limits.
Base URL and authentication
All requests go to https://api.grunden.ai. Send your key in the Authorization header:
Endpoints
Alla endpoints utom GET /v1/models kräver Authorization: Bearer sk-grunden-… och accepterar/returnerar JSON. Klicka på en kapacitet för fullständig anropssyntax och kodexempel.
Vill du ha hela kontraktet — varje parameter, svar och felkod — finns den interaktiva referensen på /docs/api/reference. Den genereras direkt ur OpenAPI-specen, som också serveras från https://api.grunden.ai/openapi.json om du hellre genererar en klient själv.
| Endpoint | Beskrivning | Kapacitet |
|---|---|---|
| POST /v1/chat/completions | Text-in / text-ut, OpenAI-kompatibel. Streaming + tool-calling stöds. | Chat (GLM 5.3 Flash) → |
| POST /v1/embeddings | 1024-dim multilingual embeddings (BGE-M3). OpenAI-kompatibel. | Embeddings → |
| POST /v1/rerank | Cross-encoder. Skicka query + lista texter, få relevans-scores i retur. | Rerank → |
| POST /v1/pii/redact | Detekterar namn, personnummer, e-post, telefon, adress. Returnerar maskerad version. | PII-detektering → |
| GET /v1/usage/allocation | Förbrukning summerad per API-nyckel och kostnadsdimension. JSON eller CSV. | Dimensionering → |
| GET /v1/balance | Organisationens aktuella saldo och valuta — samma belopp som betalningssidan visar. | Saldo → |
| POST /v1/messages | Anthropic-kompatibel (wire-format). Servar glm-5.3-flash (registrets default) i Anthropics request/response-form — kör INTE Claude. Låter Claude Code & Anthropic-SDK peka hit via ANTHROPIC_BASE_URL. Auth även via x-api-key. Streaming + tool-use stöds. | OpenAPI-spec → |
| GET /v1/models | Returnerar alla aktiva modeller med typ + endpoint, samt kontextfönster, capabilities (chat/tools/vision/reasoning), stödda parametrar och pris per 1M input- och output-tokens i EUR. Publik — kräver ingen API-nyckel. | Modeller & priser → |
| POST /v1/knowledge-bases | Kunskapsbas-API (RAG): skapa/lista/radera KB, ladda upp dokument (PDF/DOCX/TXT m.fl.) via /{id}/documents, text via /{id}/snippets, länka nyckel via /{id}/keys. | OpenAPI-spec → |
| POST /v1/chat/completions (knowledge_base_id) | Fråga en kunskapsbas: lägg knowledge_base_id i chat-anropet → relevanta utdrag injiceras automatiskt som kontext (OpenAI-kompatibel RAG). | OpenAPI-spec → |
Dimension your costs
Need to know which of your customers, departments or projects consumed what? Send the user field in the request with your own cost dimension — a tag you choose yourself. It is stored on the usage record and summed per dimension. The field works on every endpoint, not just chat.
The tag is trimmed and may be at most 128 characters. Control characters and invisible formatting characters are rejected with 400 — the value is never truncated, because two dimensions sharing the start of their tag would then be silently merged and summed incorrectly. Send an opaque identifier, not personal data. Omit the field and the call lands under "Not dimensioned".
Fetch the report with GET /v1/usage/allocation. The period is [from, to) — from inclusive, to exclusive — so two consecutive months never count the same second twice. Group by api_key, end_user and/or model, and fetch as JSON or CSV for import into your business system.
Amounts are integers in nano-euro (€1 = 10^9 nano-euro), and currency is EUR. cost_gross_nanoeur is what was deducted from your balance and includes VAT. cost_net_nanoeur is the same amount excluding VAT, and cost_vat_nanoeur is the difference. currency_decimals is the currency's display decimals (2), not the scale of the amounts. vat states which VAT rate and rule the split is based on; under reverse charge the rate is 0 and net equals gross. Earlier periods are reported in EUR with unchanged integers.
Where to see your usage
Usage can be followed in three places, at different levels of detail.
- In the chat, prompt and completion tokens, the cost in your currency and a region flag appear directly under each reply. That is the fastest feedback — you do not have to leave the conversation.
- On the billing page (/t/<org>/billing) there is a usage card with a date range of your choosing. It shows requests, tokens, cost net/VAT/gross and CO₂, and can be grouped by API key or by cost dimension. The card requires that you belong to an organisation; reachable from the user menu in the chat.
- GET /v1/usage/allocation returns the same data machine-readable, for your own business systems. See the section on dimensioning costs.
Balance via the API
Fetch the organisation's current balance with GET /v1/balance and the same API key you call the models with. It is the same amount the billing page shows.
amount is an exact decimal string in currency, never rounded, and includes VAT and all credits. The balance can be negative: a request already in progress may take it below zero, and the next paid request is then rejected with 402 until you top up. Requests are charged when they finish, so the balance lags by a few seconds — longer for batch jobs. The call counts against the key's rpm limit; fetch the balance at most about once a minute.
Error codes
- 401 Unauthorized — missing or invalid Authorization header.
- 402 Payment Required — wallet balance is 0 or negative. Top up at /t/<orgId>/billing.
- 413 Payload Too Large — uploaded file exceeds the limit.
- 429 Too Many Requests — rate limit at api-key level. Default 60 req/min, contact us for increases.
- 400 Bad Request — missing required header or invalid query param.
Vision (multimodal input)
GLM 5.3 Flash is natively multimodal, but image input via the API is not yet enabled in the current deployment. When it is activated it will be published via GET /v1/models (capabilities) and documented here.