POST /txt2aql turns a question in natural language into an AQL query and
answers it. POST /query optimizes an AQL query. For how the AQLizer reasons
about your database to do this, see AQLizer. For a step-by-step
guide, see the Quick Start.
The endpoints are relative to the path of the AQLizer service of a database,
https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}. The path
starts with /reasoner/ because the AQLizer runs on the Reasoner service
(arangodb-reasoner). service_id_postfix is the end of the service ID,
such as mxsli for arangodb-reasoner-mxsli. The Manage services dialog
of the Query Editor shows it as the
Service ID. The endpoints have no version prefix such as /v1.
Every endpoint except the health checks requires a JWT in the
Authorization: Bearer <token> header. The AQLizer uses this token for all
database access during the request, so queries are subject to your permissions
in the database.
If role-based access control (RBAC) is enabled, the endpoints require a permission. Expand the Role-based access control (RBAC) box below the URL of an endpoint to see the required permission and the predefined roles that grant it. See Role-based access control for the AQLizer for details.
| Endpoint | Operation | Purpose | Call |
|---|---|---|---|
POST /txt2aql | Generate | Turn a question into an AQL query, run it, and answer the question | Synchronous or streamed |
POST /query | Optimize | Make an AQL query faster, with results verified to match | Synchronous or streamed |
POST /query/ | Approve | Answer a request for permission to run a tool during POST /query | Synchronous |
GET /health | Monitor | Check that the service process is running | Synchronous |
GET /health/ | Monitor | Check the connection to the AI agent and the MCP server | Synchronous |
Generate a query
Role-based access control (RBAC)
Roles: ai-user or ai-developer
Scope: Databases (the database that the AQLizer is installed for)
Checked permissions:
ai:reasoner.queryonai:database:<database>ai:mcp.template.manageonai:database:<database>, ifadd_templateistrue
Turns a question in natural language into an AQL query, runs it, and returns the query, the rows it returned, and a short answer.
Request
{
"query": "What are the top 5 performing stores based on revenue?",
"stream": false,
"add_template": false
}
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | Yes | The question in natural language. Cannot be empty. | |
stream | boolean | No | false | true returns an SSE stream, false a JSON response after completion. The default differs from POST /query. |
add_ | boolean | No | false | true saves the query as a template after it runs and sets added_ in the response. See Save queries as templates. |
How a request is processed
- The AQLizer looks up saved query templates in the
Toolscollection. It turns your question into an embedding vector and ranks the templates by the cosine similarity between this vector and the vector of each template’s description, so a template matches a question with the same meaning even if the wording differs. - If the best matching template has a score of at least
0.85, the AQLizer adapts it to your question, mainly by filling in its bind parameters, and runs it. - If no template scores that high, or filling in the template does not succeed, the AQLizer writes a new query. The most similar templates, up to 3, are used as examples. If the filled-in template writes data, or saving it as a template fails, the request ends with an error instead.
A query that writes data, for example with INSERT, UPDATE, REPLACE,
UPSERT, or REMOVE, is rejected before it runs.
Response
{
"aql": "FOR s IN stores SORT s.revenue DESC LIMIT 5 RETURN { name: s.name, revenue: s.revenue }",
"json": [
{"name": "North", "revenue": 1250000},
{"name": "Central", "revenue": 1180000},
{"name": "East", "revenue": 970000},
{"name": "West", "revenue": 940000},
{"name": "South", "revenue": 880000}
],
"nl": "The top 5 stores by revenue are North (1,250,000), Central (1,180,000), East (970,000), West (940,000), and South (880,000). This answer is based on 5 rows.",
"error": null,
"added_template_id": null
}
| Field | Type | Meaning |
|---|---|---|
aql | string | The generated AQL query. |
json | object[] | The rows returned by the query, at most 50. |
nl | string | The answer in natural language. The language model writes it, so its wording varies. |
error | string or null | Set when no answer is produced. |
added_ | string or null | The ID of the saved template in the Tools collection. Set when add_ is true. |
The response contains at most 50 rows. The nl answer ends by stating how
many rows it is based on. If the query finds more than 50 rows, json holds
the first 50 and nl states that the answer is based on only the first 50
rows. For questions that match many documents, ask for a count, a total, or a
top N instead of the full list.
If no answer can be produced, the request still succeeds with HTTP status
200, with error set and aql, json, and nl empty:
error | Meaning |
|---|---|
Can not generate AQL | Generating is not available because the AQLizer started without its internal MCP server. |
Can not add template | add_ was true but the query could not be saved, for example because RBAC is enabled and your role doesn’t grant the ai: action. |
Can not change data: text-to-AQL only reads | The question asks to add, change, or delete data. |
Query contains write operation '<OPERATION>', followed by a snippet of the query | The query would modify data, so it did not run. |
I can only answer questions about the data in this database. | The question is not about the data in the database. |
Two cases return no rows without an error:
- If the database has no data for what the question asks for,
aqlandjsonare empty andnlexplains what is missing. - If the query runs but finds nothing,
aqlcontains the query,jsonis empty, andnlisThe query found no matching data.
| Status Code | Meaning |
|---|---|
200 | The request completed, with an answer or with error set. |
401 | The Authorization header is missing or does not use the Bearer scheme, or the token is invalid or expired. |
422 | The request body is invalid, for example query is empty. |
500 | An unexpected failure occurred. In streaming mode, failures during processing are reported as an error event instead. |
503 | The authentication service is unavailable. |
Streaming response
With "stream": true, the endpoint returns a Server-Sent Events (SSE) stream
with the following events:
| Event | Meaning |
|---|---|
phase | The processing phase changed (executing). |
text | Raw output of the language model, which can be JSON such as {"nl":. Don’t show it as the answer. The answer is nl in the done event. |
tool_ | A database tool was called. |
tool_ | A database tool returned a result. |
done | The final result: aql, json, nl, error (null), and added_. |
error | Generating or running the query failed. The data includes message and error. |
If no event is sent for 5 seconds, the stream sends an SSE comment
(: heartbeat) to keep the connection open. Standard SSE clients ignore
comments. If the client closes the connection, the AQLizer stops processing
the request.
The AQLizer service of a database answers one request at a time.
POST /txt2aql and POST /query share this queue, so a second request waits
until the first one finishes, even if both come from the same user. While a
request waits, its stream only sends : heartbeat comments, and no event says
that it is waiting. Send requests one at a time, or allow for this wait in your
client’s timeouts.
Save queries as templates
Query templates are only available through the API. The web interface does not support them.
Set add_template to true to save the query as a template in the Tools
collection, so that the AQLizer can reuse it for similar questions. The
AQLizer writes the template with its own service identity, so you don’t need
write access to the Tools collection. If role-based access control (RBAC) is
enabled, saving templates requires the ai:mcp.template.manage action, which
only the ai-developer role grants. See
Role-based access control for the AQLizer.
When a question closely matches a saved template, the AQLizer adapts the template to the question, mainly by filling in its bind parameters. This takes fewer steps than writing a new query, where the AQLizer first samples the collections and, if needed, looks up values in the database. When no template matches closely enough, the most similar templates still serve as examples for writing the new query.
The template is saved with your question as its description. The AQLizer also
stores an embedding vector of the description, which it compares with new
questions. The Tools collection is created if it doesn’t exist. If the same
query with the same bind parameters is already saved, added_template_id is
the ID of the existing template. Any query that runs without an error is
saved, whether it answers the question correctly or not, so check the query
before you save it.
If saving fails, the request ends with the Can not add template error. If no
query is generated, for example because the database has no data for the
question, nothing is saved and added_template_id is null.
The AQLizer endpoints don’t let you list or delete saved templates. To manage
them, query the Tools collection directly, for example with AQL.
HTTP example
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"query": "What are the top 5 performing stores based on revenue?",
"stream": false,
"add_template": false
}' \
https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/txt2aql
Optimize a query
Role-based access control (RBAC)
Roles: ai-user or ai-developer
Scope: Databases (the database that the AQLizer is installed for)
Checked permissions:
ai:reasoner.queryonai:database:<database>
Makes an AQL query faster and returns a report with the optimized query.
The AQLizer optimizes when request contains the query and one of the terms
optimize, slow, performance, speed up, faster, execution time, or
profile. Other requests, such as List all graphs in the database, are
answered with the database tools instead, without the optimization pipeline.
Request
{
"request": "Optimize this query: FOR u IN users FILTER u.status == 'active' SORT u.created_at DESC RETURN u",
"stream": false
}
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
request | string | Yes | The query to optimize with an instruction, or another request about the database. Cannot be empty. | |
stream | boolean | No | true | true returns an SSE stream, false a JSON response after completion. |
Response
{
"result": "## Optimization Summary\n\n### Performance Comparison\n| Metric | Original | Optimized |\n..."
}
| Field | Type | Meaning |
|---|---|---|
result | string | The final answer. For an optimization, a markdown report. |
error | string or null | Set when the request failed. |
The report in result looks like this:
## Optimization Summary
### Performance Comparison
| Metric | Original | Optimized |
|----------------|----------|--------------|
| Execution time | 0.842s | 0.091s |
| Rows returned | 1,247 | 1,247 |
| Peak memory | 8.2 MB | 1.1 MB |
| Speedup | - | 9.25× faster |
### What Changed
- Added a composite index hint on `status` and `created_at` to avoid a full
collection scan.
- The SORT on `created_at DESC` is now served directly by the index, eliminating
a separate in-memory sort step.
### Why It's Faster
- The original query performed a full scan of all documents in the `users`
collection before filtering by status. With the composite index, only documents
matching `status == 'active'` are read, already in the correct sort order,
reducing both execution time and memory usage significantly.
### Final Optimized Query
```aql
FOR u IN users
OPTIONS { indexHint: "status_created_at", forceIndexHint: true }
FILTER u.status == "active"
SORT u.created_at DESC
RETURN u
```
If the query writes data, the AQLizer does not run it and ends the request with
This is a write query. Only read-only queries can be optimized or run.
| Status Code | Meaning |
|---|---|
200 | The request completed. |
401 | The Authorization header is missing or invalid, or the token is expired. |
422 | The request body is invalid, for example request is empty. |
500 | Processing failed. The error detail includes the phase in which it failed. |
503 | The authentication service is unavailable. |
Streaming response
With "stream": true, the default, the endpoint returns a Server-Sent Events
(SSE) stream with the following events:
| Event | Meaning |
|---|---|
phase | The processing phase changed: executing, validating, or synthesizing. |
text | Partial text from the language model. |
tool_ | A database tool was called. |
tool_ | A database tool returned a result. |
validation | The result of checking an optimization attempt. See When validation does not pass. |
permission_ | A tool needs your approval before it runs. See Approve or reject a tool call. |
done | The final result. For an optimization, result holds the report. |
error | Processing failed. |
The stream sends the same : heartbeat comment as POST /txt2aql, including
while the request waits for other requests. Closing the
connection stops the request.
event: phase
data: {"phase": "executing"}
event: phase
data: {"phase": "validating"}
event: validation
data: {"passed": true, "original_time": 0.842, "optimized_time": 0.091, "improvement_pct": 89.2, "rows_match": true, "content_match": true, "reason": "Optimization valid: execution time reduced by 89.2%, rows match (1247=1247), content verified (hash match)"}
event: phase
data: {"phase": "synthesizing"}
event: done
data: {"synthesized": true, "result": "## Optimization Summary\n\n### Performance Comparison\n| Metric | Original | Optimized |\n..."}
For a request that is not an optimization, the stream has no validation
events and done reports "synthesized": false. The answer is in the
text events:
event: phase
data: {"phase": "executing"}
event: tool_call
data: {"tool": "list-collections", "input": {}, "status": "pending"}
event: tool_result
data: {"tool": "list-collections", "result": "[\"users\", \"orders\", \"products\"]"}
event: text
data: {"content": "The database contains 3 collections: **users**, **orders**, and **products**."}
event: done
data: {"synthesized": false}
When validation does not pass
Each validation event has a reason field that explains why an attempt did
not pass:
| Symptom | Likely cause |
|---|---|
rows_ | The rewritten query returns a different number of results. The optimization may have changed the query’s logic. |
content_ | The row counts match but the content does not. |
improvement_ below 5 | The optimization is valid but the improvement is below the minimum of 5%. The AQLizer retries with a different approach. |
HTTP example
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"request": "Optimize this query: FOR u IN users FILTER u.status == '\''active'\'' SORT u.created_at DESC RETURN u",
"stream": false
}' \
https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/query
Approve or reject a tool call
Role-based access control (RBAC)
Roles: ai-user or ai-developer
Scope: Databases (the database that the AQLizer is installed for)
Checked permissions:
ai:reasoner.queryonai:database:<database>
Answers a request for permission to run a tool. Some database tools, such as
the ones that create documents or collections, need your approval before they
run. When POST /query wants to call one, the stream sends a
permission_required event and waits for your answer:
event: permission_required
data: {"permission_id": "per_01", "session_id": "ses_01", "tool_name": "arangodb_create-document", "tool_input": {…}}
Request
{
"permission_id": "per_01",
"session_id": "ses_01",
"action": "reject"
}
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
permission_ | string | Yes | The permission_ of the permission_ event. | |
session_ | string | Yes | The session_ of the permission_ event. | |
action | string | Yes | approve runs the tool once, reject does not run it. |
Response
{
"success": true,
"action": "reject"
}
| Field | Type | Meaning |
|---|---|---|
success | boolean | Whether the answer has been forwarded. |
action | string | The action you sent. |
| Status Code | Meaning |
|---|---|
200 | The answer has been forwarded. |
401 | The Authorization header is missing or invalid, or the token is expired. |
422 | action is not approve or reject, or a field is missing. |
500 | The answer could not be forwarded. |
HTTP example
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
"permission_id": "per_01",
"session_id": "ses_01",
"action": "reject"
}' \
https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/query/permission
Check that the service is running
Role-based access control (RBAC)
Any authenticated user can call this endpoint. You need a valid token, but no permission is checked.
Returns healthy whenever the service process is running, regardless of its
connections. Use it as the Kubernetes liveness probe. No token is needed.
Response
{
"status": "healthy",
"version": "1.0.0",
"environment": "production"
}
| Field | Type | Meaning |
|---|---|---|
status | string | Always healthy. |
version | string | The version of the service. |
environment | string | The environment the service runs in. |
| Status Code | Meaning |
|---|---|
200 | The service process is running. |
HTTP example
curl -X GET \
https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/health
Check that the service is ready
Role-based access control (RBAC)
Any authenticated user can call this endpoint. You need a valid token, but no permission is checked.
Checks the connection to the AI agent and the MCP server. The service is ready when the AI agent is reachable. The MCP server status is reported for information. Use it as the Kubernetes readiness probe. No token is needed.
Response
{
"ready": true,
"checks": {
"opencode": {
"status": "healthy",
"url": "http://localhost:4099"
},
"mcp_servers": {
"status": "available",
"details": {
"arangodb": { "status": "connected" }
}
}
}
}
| Field | Type | Meaning |
|---|---|---|
ready | boolean | Whether the service is ready. |
checks.opencode.status | string | healthy or unhealthy, the status of the AI agent (OpenCode). |
checks | string | Whether MCP servers are available. |
checks | object | The connection status of each MCP server. |
| Status Code | Meaning |
|---|---|
200 | The check has run. Read ready for the result. |
HTTP example
curl -X GET \
https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/health/ready
