Updated
At a glance
- Bearer token on the server side
- One key per app, with limited permissions
- SSE for streamed answers
- Official documentation for endpoints
Which API is this guide about?
The concepts here apply to most HTTP AI APIs. The examples have placeholders because the exact URLs and request bodies belong in the documentation. The LumanexAI public API covers chat, transcription, retrieval from documents, presentations and code assistance, uses Bearer authentication, issues keys with permissions and supports SSE. Its reference is at app.lumanex.it/ai/lumanex-api-docs.html. A summary of what the API is for is in AI API for developers. C1V Hosting also sells a separate AI Inference API.
What is a Bearer token?
A Bearer token is a secret string that you send in the Authorization header of every request. Whoever has the token can use the key, so handle it like a password.
Authorization: Bearer YOUR_API_KEYNever put the key in a mobile app, in front-end JavaScript or in a public repository. Call the AI API from your own backend, and let your front end call your backend.
How should you scope and store API keys?
LumanexAI keys carry permissions. Use that to limit damage if a key leaks.
- Create one key per application and per environment (development, staging, production).
- Give each key only the permissions the application needs. A key for transcription does not need to do anything else.
- Store keys in environment variables or a secrets manager, not in source code.
- Rotate keys on a schedule and revoke them immediately if you suspect exposure.
- Log which key made a request, never the key itself.
How do you send the first request?
Start with a command-line call, so that you separate API problems from application problems. Replace the placeholders with the values from the documentation:
curl -sS "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d @request.jsonAPI_URL is the endpoint for the capability you want, and request.json is the body described in the documentation for that endpoint. Once it works, move the same call into your code, with the key read from the environment.
What is SSE streaming and when do you need it?
Server-Sent Events (SSE) is a simple way for a server to send a response in pieces over one HTTP connection. For chat, it lets your interface show text as it is produced, instead of waiting for the full answer. Use it for interactive screens, and use a normal request when your code only needs the final result, for example in a background job.
An SSE response is text. Events are separated by a blank line, and each data line starts with data:. A minimal reader in JavaScript, run on your server or in Node:
const res = await fetch(API_URL, { method: "POST", headers, body });
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const events = buffer.split("\n\n");
buffer = events.pop();
for (const ev of events) {
for (const line of ev.split("\n")) {
if (line.startsWith("data:")) handle(line.slice(5).trim());
}
}
}What each data: line contains, and how the end of the stream is signalled, is defined by the API. Read it in the documentation and do not assume.
What problems appear with streaming?
- Proxy buffering: some reverse proxies hold the response until it is complete. Disable buffering for the streaming route.
- Timeouts: long answers can outlast default timeouts of load balancers and clients. Set them explicitly.
- Partial chunks: a network read may end in the middle of an event, which is why the code above keeps a buffer.
- Closed connections: when the user leaves the page, cancel the request so that you stop consuming it.
How should you handle errors?
| HTTP status | Usual meaning | What to do |
|---|---|---|
| 400 | The request is malformed | Fix the body, do not retry unchanged |
| 401 | Missing or invalid key | Check the header and the key |
| 403 | The key lacks permission | Use a key with the right permission |
| 429 | Too many requests | Slow down and retry later |
| 5xx | Temporary problem on the server side | Retry with a growing delay, up to a limit |
These are common HTTP conventions. The documentation of the API defines its own error format, so read it and show your users a clear message, not a raw error.
How do you test and go to production?
- Write an automated test that calls the API through a thin wrapper, so that you can replace it with a fake in other tests.
- Set a timeout on every request, and retry only the safe ones.
- Cap the size of the user input that you send.
- Keep logs of status codes and durations, and be careful with the content of prompts, which may contain personal data.
- Show a visible fallback when the API is not available.
Where do you go next?
Read the official API documentation, check the access conditions that apply to your plan on the LumanexAI product page (Italian), and see Flow vs Deep if you need to choose a model. If you have questions, the Italian support team answers by ticket in the client area or on Telegram.
Frequently asked questions
Where is the official documentation of the LumanexAI API?
At https://app.lumanex.it/ai/lumanex-api-docs.html.
How do I authenticate?
With a Bearer token in the Authorization header. Each key has its own permissions.
Should I call the API from the browser?
No. Call it from your backend, so that the key never reaches the client.
Does the API support streaming?
Yes, with Server-Sent Events (SSE).
Is the AI Inference API the same thing?
No. It is a separate HTTP inference API sold by C1V Hosting with pay-per-use pricing.
