Quickstart: calling AISIA with the OpenAI SDK
In short
AISIA exposes an OpenAI-compatible chat API at https://api.aisia.fr/v1. With the OpenAI SDK you change three values: the base URL, the key (an AISIA token or an ak_live_ key issued for your organisation) and the model (auto, aisia, local/<model> or provider/model). SSE streaming and the /v1/models list are available.
This page gives minimal examples that match the API code. The authoritative contract is the OpenAPI snapshot published with each release; whether a model is usable depends on your organisation and on the deployed runtime.
Create an account and get accessBefore you start: get access
Two kinds of credentials are accepted in the Authorization: Bearer header. A user token, obtained through POST /auth/login once an account exists. Or an organisation API key starting with ak_live_, created by an organisation administrator in their workspace (API keys section). The X-API-Key header is also accepted for an ak_live_ key.
Keep that secret on the server side, in an environment variable or a secrets manager. Never ship it in JavaScript served to a browser, and never commit it to a Git repository.
export AISIA_API_KEY="ak_live_…" # or a token obtained through POST /auth/loginPython: the OpenAI SDK with another base_url
The official openai SDK for Python accepts a base_url parameter. Only the address, the key and the model name change: the rest of your code is a regular OpenAI call.
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.aisia.fr/v1", api_key=os.environ["AISIA_API_KEY"])
reply = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Explain local-first routing in two sentences."}],
)
print(reply.choices[0].message.content)TypeScript and Node.js: the baseURL option
The openai SDK for Node.js accepts a baseURL option. Run this code on the server: the key must never reach the browser.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.aisia.fr/v1", apiKey: process.env.AISIA_API_KEY });
const reply = await client.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "Explain local-first routing in two sentences." }],
});
console.log(reply.choices[0].message.content);curl and SSE streaming
With stream=true the response arrives as Server-Sent Events: data: blocks in the chat.completion.chunk format, ending with data: [DONE]. The curl -N option turns off buffering so tokens show up as they arrive.
curl -N https://api.aisia.fr/v1/chat/completions \
-H "Authorization: Bearer $AISIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"auto","stream":true,"messages":[{"role":"user","content":"Hello"}]}'Choosing the model: auto, aisia, local or a named provider
The model field drives routing. An explicitly named model is never silently swapped for another one: if the target is unavailable or not allowed, the API returns an error instead of switching elsewhere.
| Value | Effect | Fallback |
|---|---|---|
| auto | Automatic routing (bandit). On this endpoint the default policy favours the configured cloud, unless your organisation is set to local first. | Depends on the organisation policy |
| aisia | Composite mode: several models are called, then a synthesis is produced. | Local fallback if the composition cannot run |
| local or local/<model> | Forced execution on a local model served by Ollama, for example local/llama3.2:1b. | No cloud fallback |
| <provider>/<model> | Provider and model are imposed, for example an identifier listed by GET /v1/models. | No fallback to another provider |
A bare model name that the local registry does not know returns a 400 error that suggests the right form (local/<model> or provider/model).
Listing the models you can reach
GET /v1/models answers in the OpenAI format ({"object": "list", "data": [...]}) with provider/model identifiers that can be used as is in model. When authenticated, the list reflects the providers allowed for your organisation. The limit and offset parameters paginate it. A catalogued model is not necessarily enabled: using it depends on the configured provider keys and on the runtime.
curl https://api.aisia.fr/v1/models -H "Authorization: Bearer $AISIA_API_KEY"Common errors and how to handle them
Set a client-side timeout and handle the codes below explicitly. Log the trace identifier returned by the API, never the key.
| Code | Usual cause | Action |
|---|---|---|
| 400 | Invalid request: no user message, or unknown model. | Fix the body or use an identifier from GET /v1/models. |
| 401 | Missing or expired token, or invalid key. | Renew the token or check the ak_live_ key. |
| 403 | Provider or model not allowed for your organisation. | Ask the organisation administrator for access. |
| 429 | Token quota or rate limit reached. | Wait for the quota reset or contact the administrator. |
| 503 | No cloud provider configured for the request, or a local model still loading (a Retry-After header may be sent). | Retry after the given delay or pick another model. |
On /v1/compare and /v1/debate, the local_only option requires at least two distinct local models: otherwise the API answers 503 rather than calling the cloud.
Going further: native API, MCP and service status
The native API POST /v1/invoke and its streaming variant /v1/invoke/stream also return the model actually served, the routing reason and, for a local model, the serving lane that was used. The MCP server POST /v1/mcp exposes the same capabilities to agents and IDEs.
The interactive OpenAPI documentation is turned off in production: ask dev@aisia.fr for the versioned contract snapshot. Check the version being served and the state of the services with GET /health and the status page.
Frequently asked questions
Do I have to change my OpenAI code to use AISIA?
For the chat endpoint, no: change the base URL (https://api.aisia.fr/v1), the key and the model name. Not every OpenAI endpoint is reproduced, so check the ones you need in the published OpenAPI snapshot.
Which key goes into api_key?
A user token obtained through POST /auth/login, or an organisation API key starting with ak_live_ created by an administrator. Never a cloud provider key: those stay inside the platform.
Does the auto model send my requests to the cloud?
On /v1/chat/completions, auto favours the configured cloud by default, unless your organisation is set to local first. To stay local, request local or local/<model> explicitly: no cloud fallback is attempted then.
Is streaming supported?
Yes, with stream=true: the response arrives as Server-Sent Events in the chat.completion.chunk format and ends with data: [DONE].
Where is the full API reference?
The interactive documentation is turned off in production. A versioned OpenAPI snapshot is available on request from dev@aisia.fr, and the API documentation page summarises the endpoint families.
Sources
Public facts checked on the dates shown. A vendor page can change: check it before you decide.
Related pages
- LLM proxy: one API for local and cloud models
- AISIA Python, Go and TypeScript SDKs and CLI
- Ollama for business behind AISIA
- AISIA MCP server