{"openapi":"3.1.0","info":{"title":"Avokati AI API","description":"Legal research API over Albanian, Kosovo, EU and international law. Every answer cites the articles it is built on.\n\n## Authentication\nCreate a key in the app under **Dashboard → API Keys**; it is shown only once. Send it as `X-API-Key: sk-...` or as `Authorization: Bearer sk-...`.\n\n## OpenAI SDKs\n`POST /v1/chat/completions` takes the OpenAI chat-completions request, so the official SDKs work:\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"https://avokati.ai/v1\", api_key=\"sk-...\")\nanswer = client.chat.completions.create(\n    model=\"avo-al\",\n    messages=[{\"role\": \"user\", \"content\": \"Kush ka të drejtë të nxjerrë urdhër administrativ?\"}],\n)\n```\n\nResponses add `sources` (cited articles, with `eli_uri` for Albanian acts), `metadata` and `conversation_id`. Pass `conversation_id` back to continue a thread.\n\n## Models\nPick the knowledge base with `model`:\n\n| model | Knowledge base |\n|---|---|\n| `avo-eu` | EU Law |\n| `avo-echr` | ECHR Case Law |\n| `avo-al` | Albanian Law |\n| `avo-rks` | Kosovo Law |\n| `avo-cjeu` | EUCJ |\n| `avo-icj` | ICJ Case Law |\n| `avo-venice` | Venice Commission |\n| `avo-kanuni` | Kanuni i Lekë Dukagjinit |\n\n`eu-law-rag`, `eu-law-rag-fast` are older names kept for existing clients.\n\n## Limits\nUsage is metered per account, not per key: every key on an account shares one token budget, including a free daily allowance. When it runs out the API answers `429` with `Retry-After`. Write to info@avokati.ai for higher volume.\n\n## Disclaimer\nAnswers are legal information, not legal advice. Check them against the official sources cited.\n","version":"1.0.0"},"servers":[{"url":"https://avokati.ai"}],"paths":{"/v1/models":{"get":{"tags":["OpenAI Compatible"],"summary":"List Models","description":"List the model ids. Each id selects one knowledge base.","operationId":"list_models_v1_models_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelListResponse"}}}},"401":{"description":"Missing, invalid or expired API key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Account inactive, organization suspended, or IP not on the key's allow list.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"ApiKeyHeader":[]},{"BearerApiKey":[]}]}},"/v1/chat/completions":{"post":{"tags":["OpenAI Compatible"],"summary":"Chat Completions","description":"Ask a legal question. The last `user` message is the question; earlier `user` and `assistant` messages give context. `choices[0].message.content` holds the answer followed by a plain-text list of the cited sources; the same sources come structured in `sources`. Pass the returned `conversation_id` to continue the thread. Questions outside law get a short refusal as the answer.","operationId":"chat_completions_v1_chat_completions_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionRequest"}}},"required":true},"responses":{"200":{"description":"Answer with cited sources. With `stream: true` the body is `text/event-stream`: `chat.completion.chunk` events carry `choices[0].delta.content`; the last chunk has `finish_reason: \"stop\"` plus `sources`, `metadata` and `conversation_id`; then `data: [DONE]`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionResponse"}},"text/event-stream":{"schema":{"type":"string"},"example":"data: {\"object\": \"chat.completion.chunk\", \"choices\": [{\"index\": 0, \"delta\": {\"content\": \"...\"}, \"finish_reason\": null}]}\n\ndata: [DONE]\n\n"}}},"400":{"description":"No user message, or unknown `data_source`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Missing, invalid or expired API key.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Account inactive, organization suspended, or IP not on the key's allow list.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"`conversation_id` not found for this account.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"422":{"description":"Request body failed validation; `detail` names the fields.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"The account's usage allowance is used up; wait `Retry-After` seconds.","headers":{"Retry-After":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/QuotaErrorResponse"}}}},"500":{"description":"Answer generation failed; safe to retry.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"ApiKeyHeader":[]},{"BearerApiKey":[]}]}}},"components":{"schemas":{"ChatCompletionChoice":{"properties":{"index":{"type":"integer","title":"Index"},"message":{"$ref":"#/components/schemas/ChatMessage"},"finish_reason":{"type":"string","title":"Finish Reason"}},"type":"object","required":["index","message","finish_reason"],"title":"ChatCompletionChoice"},"ChatCompletionRequest":{"properties":{"model":{"type":"string","maxLength":100,"title":"Model","description":"Knowledge base to answer from; see `GET /v1/models`.","default":"eu-law-rag"},"messages":{"items":{"$ref":"#/components/schemas/ChatMessage"},"type":"array","maxItems":200,"title":"Messages","description":"Conversation so far. The last `user` message is the question."},"temperature":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Temperature","description":"Accepted for OpenAI compatibility; ignored.","default":0.0},"max_tokens":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Max Tokens","description":"Accepted for OpenAI compatibility; ignored."},"stream":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Stream","description":"Return `text/event-stream` chunks instead of one JSON body.","default":false},"top_p":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Top P","description":"Accepted for OpenAI compatibility; ignored."},"frequency_penalty":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Frequency Penalty","description":"Accepted for OpenAI compatibility; ignored."},"presence_penalty":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Presence Penalty","description":"Accepted for OpenAI compatibility; ignored."},"stop":{"anyOf":[{"type":"string"},{"items":{"type":"string"},"type":"array"},{"type":"null"}],"title":"Stop","description":"Accepted for OpenAI compatibility; ignored."},"user":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"User","description":"Accepted for OpenAI compatibility; ignored."},"version_id":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Version Id","description":"Accepted for OpenAI compatibility; ignored."},"prompt_version":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Prompt Version","description":"Advanced. Pin a system prompt version; omit for the default."},"top_k":{"anyOf":[{"type":"integer","maximum":100.0,"minimum":1.0},{"type":"null"}],"title":"Top K","description":"Passages retrieved before reranking."},"rerank_top_k":{"anyOf":[{"type":"integer","maximum":100.0,"minimum":1.0},{"type":"null"}],"title":"Rerank Top K","description":"Passages kept after reranking."},"graph_expand":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Graph Expand","description":"Add articles linked to the retrieved ones.","default":true},"graph_expand_count":{"anyOf":[{"type":"integer","maximum":10.0,"minimum":0.0},{"type":"null"}],"title":"Graph Expand Count","description":"Maximum linked articles added per passage."},"max_context_chars":{"anyOf":[{"type":"integer","maximum":100000.0,"minimum":1000.0},{"type":"null"}],"title":"Max Context Chars","description":"Upper bound on source text given to the model."},"data_source":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Data Source","description":"Overrides the knowledge base chosen by `model`."},"include_historical":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Include Historical","description":"Also search repealed or superseded versions of acts.","default":false},"use_decomposition":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Use Decomposition","description":"Split the question into sub-questions before retrieval. Defaults to the server setting."},"skip_enrichment":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Skip Enrichment","description":"EU law only: search with the question as written, without query rewriting.","default":false},"conversation_id":{"anyOf":[{"type":"string","maxLength":64},{"type":"null"}],"title":"Conversation Id","description":"Continue an earlier thread returned by this endpoint."},"as_of":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"As Of","description":"Answer with the law as it stood on this date (YYYY-MM-DD, not in the future); omit for today."}},"type":"object","required":["messages"],"title":"ChatCompletionRequest"},"ChatCompletionResponse":{"properties":{"id":{"type":"string","title":"Id"},"object":{"type":"string","title":"Object","default":"chat.completion"},"created":{"type":"integer","title":"Created"},"model":{"type":"string","title":"Model"},"choices":{"items":{"$ref":"#/components/schemas/ChatCompletionChoice"},"type":"array","title":"Choices"},"usage":{"$ref":"#/components/schemas/Usage"},"sources":{"items":{"$ref":"#/components/schemas/SourceCitation"},"type":"array","title":"Sources","default":[]},"metadata":{"anyOf":[{"$ref":"#/components/schemas/RetrievalMetadata"},{"type":"null"}]},"conversation_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Conversation Id"}},"type":"object","required":["id","created","model","choices","usage"],"title":"ChatCompletionResponse"},"ChatMessage":{"properties":{"role":{"type":"string","enum":["system","user","assistant"],"title":"Role"},"content":{"type":"string","maxLength":50000,"title":"Content"}},"type":"object","required":["role","content"],"title":"ChatMessage"},"ErrorDetail":{"properties":{"type":{"type":"string","title":"Type","examples":["AuthenticationError"]},"message":{"type":"string","title":"Message"}},"type":"object","required":["type","message"],"title":"ErrorDetail"},"ErrorResponse":{"properties":{"detail":{"type":"string","title":"Detail","description":"Human-readable error message."},"error":{"anyOf":[{"$ref":"#/components/schemas/ErrorDetail"},{"type":"null"}],"description":"Present on authentication and authorization errors."}},"type":"object","required":["detail"],"title":"ErrorResponse"},"ModelInfo":{"properties":{"id":{"type":"string","title":"Id"},"object":{"type":"string","title":"Object","default":"model"},"created":{"type":"integer","title":"Created"},"owned_by":{"type":"string","title":"Owned By"}},"type":"object","required":["id","created","owned_by"],"title":"ModelInfo"},"ModelListResponse":{"properties":{"object":{"type":"string","title":"Object","default":"list"},"data":{"items":{"$ref":"#/components/schemas/ModelInfo"},"type":"array","title":"Data"}},"type":"object","required":["data"],"title":"ModelListResponse"},"QuotaDetail":{"properties":{"error":{"type":"string","title":"Error","examples":["token_budget_exceeded"]},"type":{"type":"string","title":"Type","description":"Which budget ran out."},"retry_after":{"type":"integer","title":"Retry After","description":"Seconds until the budget resets."},"message":{"type":"string","title":"Message"}},"type":"object","required":["error","type","retry_after","message"],"title":"QuotaDetail"},"QuotaErrorResponse":{"properties":{"detail":{"$ref":"#/components/schemas/QuotaDetail"}},"type":"object","required":["detail"],"title":"QuotaErrorResponse"},"RetrievalMetadata":{"properties":{"request_id":{"type":"string","title":"Request Id"},"data_source":{"type":"string","title":"Data Source","default":"eu_law"},"model":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Model"},"latency_ms":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Latency Ms"},"sources_count":{"type":"integer","title":"Sources Count","default":0},"parameters":{"additionalProperties":true,"type":"object","title":"Parameters","default":{}},"enrichment":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Enrichment"},"quality":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Quality"},"route":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Route","description":"`kb_status` or `catalogue` when the answer comes from the knowledge-base records, not retrieval."},"routed_from":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Routed From","description":"Knowledge base the thread moved from because its first question named Albanian law."},"gap_check":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Gap Check","description":"`gaps`: facts the cited provisions make decisive that the question did not give."},"disambiguation":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Disambiguation","description":"Several acts match the question: the answer lists them; `follow_ups` asks about each."},"follow_ups":{"anyOf":[{"items":{"type":"string"},"type":"array"},{"type":"null"}],"title":"Follow Ups","description":"Suggested next questions."},"clarification_needed":{"anyOf":[{"additionalProperties":true,"type":"object"},{"type":"null"}],"title":"Clarification Needed","description":"The question was too short to search; the answer asks for more, `suggestions` offers questions."}},"type":"object","required":["request_id"],"title":"RetrievalMetadata"},"SourceCitation":{"properties":{"treaty":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Treaty","description":"Title of the act, treaty or case."},"article":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Article"},"article_heading":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Article Heading"},"chunk_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Chunk Type"},"source_type":{"type":"string","title":"Source Type","default":"eurlex"},"score":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Score"},"text_preview":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Text Preview","description":"First 300 characters of the cited passage."},"case_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Case Id"},"case_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Case Name"},"eli_uri":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Eli Uri","description":"ELI identifier of an Albanian act, e.g. eli:al:ligj:2015:04:30:44."},"doc_type":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Doc Type"}},"type":"object","title":"SourceCitation"},"Usage":{"properties":{"prompt_tokens":{"type":"integer","title":"Prompt Tokens"},"completion_tokens":{"type":"integer","title":"Completion Tokens"},"total_tokens":{"type":"integer","title":"Total Tokens"}},"type":"object","required":["prompt_tokens","completion_tokens","total_tokens"],"title":"Usage","description":"Token counts; estimated when the pipeline reports none."}},"securitySchemes":{"ApiKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"},"BearerApiKey":{"type":"http","scheme":"bearer","description":"The same API key as `Authorization: Bearer sk-...`, as OpenAI SDKs send it."}}}}