Server-side routes in WAHS (such as SvelteKit /api/chat/+server.ts using the Vercel AI SDK @ai-sdk/openai-compatible provider) call wahs-engine using standard OpenAI chat completion payloads. Vanilla OpenAI requests with no wahs extension field default automatically to the signed-in user’s full fhir-auth record at the model’s recommended budget; optional wahs.chart_scope and wahs.overlay_resources fields control per-turn filtering and unsaved draft notes, while the final streamed chunk attaches x_wahs citation and HL7 AI Transparency metadata.
POST /v1/chat/completions
Authorization: Bearer <keycloak_access_token>
Content-Type: application/json
{
"model": "wahs-12b-kb",
"stream": true,
"messages": [
{ "role": "user", "content": "Do any of my heart or kidney medications conflict across clinics?" }
],
"wahs": {
"target_budget_tokens": 8192,
"chart_scope": {
"include_sources": ["UW Medicine", "MultiCare", "My Story"],
"exclude_categories": [],
"include_resource_types": [],
"exclude_resource_ids": [],
"ips_bundle_id": null,
"date_from": null,
"date_to": null
},
"overlay_resources": []
}
}
──► Standard OpenAI SSE token stream (data: {"object":"chat.completion.chunk", ...})
──► Final chunk attaches x_wahs provenance for clickable [N] source pills & HL7 AI-Provenance:
{
"x_wahs": {
"citation_map": {
"7": { "resourceType": "MedicationRequest", "id": "med-spiro-01", "date": "2026-01-12", "source": "UW Medicine", "display": "Spironolactone 25 MG Oral Tablet" },
"10": { "resourceType": "Observation", "id": "obs-k-56", "date": "2026-01-16", "source": "MultiCare", "display": "Potassium 5.6 mEq/L" }
},
"condensation": { "budget_tokens": 8192, "actual_tokens": 6410, "datasets_included": 3, "omitted_clinical_items": 0 },
"ai_provenance": { "model": "ollama/gemma4:12b", "kb_enabled": true, "human_review_required": true }
}
}