Using the API
Chat completions
Send a conversation and get the model's answer.
POST https://api.danskllm.dk/v1/chat/completions works like OpenAI's Chat Completions API.
curl https://api.danskllm.dk/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DANSKLLM_API_KEY" \
-d '{
"model": "muse-glimmer-30b",
"messages": [
{"role": "system", "content": "Du er en hjælpsom assistent."},
{"role": "user", "content": "Forklar kort, hvad en API-nøgle er."}
]
}'The conversation
messages is the whole conversation so far. Each message has a role and a content.
role | Used for |
|---|---|
system or developer | Instructions for the model, such as the task and the tone. |
user | What the user writes. |
assistant | The model's earlier answers. |
tool | The result of a tool call. Set tool_call_id to the id of the call. |
The API doesn't remember conversations. Send the whole history every time. The part that is the same as last time is read from the cache and costs less. See prompt caching.
Parameters
| Field | Description |
|---|---|
model | The model id, for example muse-glimmer-30b. Required. |
messages | The conversation. Required. |
max_tokens or max_completion_tokens | The most tokens the answer may have. |
temperature, top_p | How much answers vary. |
stop | Text that makes the model stop. |
seed | Makes answers more alike from one request to the next. |
n | How many answers to the same request, at most 4. Each answer is billed. |
presence_penalty, frequency_penalty, logit_bias | Control repetition and specific tokens. |
logprobs, top_logprobs | Probabilities of the chosen tokens. |
reasoning_effort | How much the model thinks before it answers: none, low, medium or high. Only for models that can think. See the model's page. |
stream, stream_options | See streaming. |
tools, tool_choice, parallel_tool_calls and response_format are passed on to the model, but only work if the model is set up for them. See the model's page. Other fields are ignored, so code written for OpenAI doesn't fail.
Streaming
Set stream to true. The answer arrives as server-sent events: one data: line per piece of text, then data: [DONE]. Now and then a comment line starting with : arrives. Skip those; the SDKs do it for you.
Models that think send their thinking first, in delta.reasoning, and then the answer in delta.content. The examples print only the answer, so nothing shows while the model thinks. See Models.
curl -N https://api.danskllm.dk/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DANSKLLM_API_KEY" \
-d '{
"model": "muse-glimmer-30b",
"messages": [{"role": "user", "content": "Skriv et kort digt om København."}],
"stream": true
}'A stream only includes usage if you ask for it:
{ "stream": true, "stream_options": { "include_usage": true } }Then the last piece before [DONE] has a usage field and an empty choices list.
If the model stops answering in the middle of an answer, the stream ends with an error instead of [DONE]. You don't pay for an answer we cut off.
data: {"error": {"message": "The model stopped answering before the reply was complete. Try again.", "type": "server_error", "param": null, "code": null}}Usage
The answer has a usage field with what you pay for:
"usage": {
"prompt_tokens": 28,
"completion_tokens": 87,
"total_tokens": 115,
"prompt_tokens_details": { "cached_tokens": 16 }
}cached_tokens is the part of the prompt that was read from the cache.
Context window
The prompt and the answer together must fit in the model's context window. If they are too long, you get status 400 with the code context_length_exceeded. The context window is on each model's page under Models.