Skip to content

POST /api/llm/generate

A general-purpose endpoint: you send a document text plus an instruction, and get the model's answer back as text. Use it for jobs that have no dedicated endpoint yet — summarising a letter, rewriting it for a patient, pulling out a specific passage.

If you need a structured result, use POST /api/documents/extract instead. It is schema-bound and grounding-validated; this endpoint gives you free text and no such guarantees.

Request

{
  "text": "Zuweisung vom 12.08.2026 ...",
  "prompt": "Fasse die Fragestellung dieser Zuweisung in einem Satz zusammen."
}
  • text — the document/content to work on, 1–20 000 characters.
  • prompt — the instruction: what to do with the text, 1–5 000 characters. It is passed as the system prompt, text as the user message.

Response

{
  "output": "# Zusammenfassung der Fragestellung\n\nDer Hausarzt möchte klären, ob eine Kniegelenksprothese (Knie-TP) rechts indiziert ist.",
  "model": "eu.anthropic.claude-haiku-4-5-...",
  "usage": { "tokens_in": 207, "tokens_out": 56 },
  "processing_time_ms": 1397.92
}
  • output — the answer as plain text. Models like to add Markdown headings; if you need a bare sentence, say so in the prompt.
  • model, usage, processing_time_ms — which model answered, token counts, server-side duration.

The output is not validated. Nothing checks that the answer is covered by text, so treat it as a draft for a human, not as a fact. Where that matters, use the extraction endpoint.

Example

curl -X POST https://medical-api.dev.unomed.ch/api/llm/generate \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"text":"Zuweisung vom 12.08.2026 ...","prompt":"Fasse die Fragestellung in einem Satz zusammen."}'

Errors

401 key missing/invalid · 422 validation failed (e.g. text or prompt empty or too long) · 429 rate limit or daily quota reached · 502 the model call failed · 503 service not configured. See Errors & Health.

Error messages are deliberately generic — provider errors can quote parts of the request, which would mean patient data in an error string.