Agentic AI Suite Beta

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.

EndpointOperationPurposeCall
POST /txt2aqlGenerateTurn a question into an AQL query, run it, and answer the questionSynchronous or streamed
POST /queryOptimizeMake an AQL query faster, with results verified to matchSynchronous or streamed
POST /query/permissionApproveAnswer a request for permission to run a tool during POST /querySynchronous
GET /healthMonitorCheck that the service process is runningSynchronous
GET /health/readyMonitorCheck the connection to the AI agent and the MCP serverSynchronous

Generate a query

POST https://<EXTERNAL_ENDPOINT>:8529/reasoner/:service_id_postfix/txt2aql
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.query on ai:database:<database>
  • ai:mcp.template.manage on ai:database:<database>, if add_template is true

See Role-based access control for the AQLizer.

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

ParameterTypeRequiredDefaultDescription
querystringYesThe question in natural language. Cannot be empty.
streambooleanNofalsetrue returns an SSE stream, false a JSON response after completion. The default differs from POST /query.
add_templatebooleanNofalsetrue saves the query as a template after it runs and sets added_template_id in the response. See Save queries as templates.

How a request is processed

  1. The AQLizer looks up saved query templates in the Tools collection. 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.
  2. 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.
  3. 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
}
FieldTypeMeaning
aqlstringThe generated AQL query.
jsonobject[]The rows returned by the query, at most 50.
nlstringThe answer in natural language. The language model writes it, so its wording varies.
errorstring or nullSet when no answer is produced.
added_template_idstring or nullThe ID of the saved template in the Tools collection. Set when add_template 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:

errorMeaning
Can not generate AQLGenerating is not available because the AQLizer started without its internal MCP server.
Can not add templateadd_template was true but the query could not be saved, for example because RBAC is enabled and your role doesn’t grant the ai:mcp.template.manage action.
Can not change data: text-to-AQL only readsThe question asks to add, change, or delete data.
Query contains write operation '<OPERATION>', followed by a snippet of the queryThe 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, aql and json are empty and nl explains what is missing.
  • If the query runs but finds nothing, aql contains the query, json is empty, and nl is The query found no matching data.
Status CodeMeaning
200The request completed, with an answer or with error set.
401The Authorization header is missing or does not use the Bearer scheme, or the token is invalid or expired.
422The request body is invalid, for example query is empty.
500An unexpected failure occurred. In streaming mode, failures during processing are reported as an error event instead.
503The authentication service is unavailable.

Streaming response

With "stream": true, the endpoint returns a Server-Sent Events (SSE) stream with the following events:

EventMeaning
phaseThe processing phase changed (executing).
textRaw output of the language model, which can be JSON such as {"nl":"","off_topic":true}. Don’t show it as the answer. The answer is nl in the done event.
tool_callA database tool was called.
tool_resultA database tool returned a result.
doneThe final result: aql, json, nl, error (null), and added_template_id.
errorGenerating 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.

Note:

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

Note:

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

POST https://<EXTERNAL_ENDPOINT>:8529/reasoner/:service_id_postfix/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.query on ai:database:<database>

See Role-based access control for the AQLizer.

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

ParameterTypeRequiredDefaultDescription
requeststringYesThe query to optimize with an instruction, or another request about the database. Cannot be empty.
streambooleanNotruetrue returns an SSE stream, false a JSON response after completion.

Response

{
  "result": "## Optimization Summary\n\n### Performance Comparison\n| Metric | Original | Optimized |\n..."
}
FieldTypeMeaning
resultstringThe final answer. For an optimization, a markdown report.
errorstring or nullSet 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 CodeMeaning
200The request completed.
401The Authorization header is missing or invalid, or the token is expired.
422The request body is invalid, for example request is empty.
500Processing failed. The error detail includes the phase in which it failed.
503The authentication service is unavailable.

Streaming response

With "stream": true, the default, the endpoint returns a Server-Sent Events (SSE) stream with the following events:

EventMeaning
phaseThe processing phase changed: executing, validating, or synthesizing.
textPartial text from the language model.
tool_callA database tool was called.
tool_resultA database tool returned a result.
validationThe result of checking an optimization attempt. See When validation does not pass.
permission_requiredA tool needs your approval before it runs. See Approve or reject a tool call.
doneThe final result. For an optimization, result holds the report.
errorProcessing 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:

SymptomLikely cause
rows_match: falseThe rewritten query returns a different number of results. The optimization may have changed the query’s logic.
content_match: falseThe row counts match but the content does not.
improvement_pct below 5The 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

POST https://<EXTERNAL_ENDPOINT>:8529/reasoner/:service_id_postfix/query/permission
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.query on ai:database:<database>

See Role-based access control for the AQLizer.

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

ParameterTypeRequiredDefaultDescription
permission_idstringYesThe permission_id of the permission_required event.
session_idstringYesThe session_id of the permission_required event.
actionstringYesapprove runs the tool once, reject does not run it.

Response

{
  "success": true,
  "action": "reject"
}
FieldTypeMeaning
successbooleanWhether the answer has been forwarded.
actionstringThe action you sent.
Status CodeMeaning
200The answer has been forwarded.
401The Authorization header is missing or invalid, or the token is expired.
422action is not approve or reject, or a field is missing.
500The 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

GET https://<EXTERNAL_ENDPOINT>:8529/reasoner/:service_id_postfix/health
Role-based access control (RBAC)

Any authenticated user can call this endpoint. You need a valid token, but no permission is checked.

See Role-based access control for the AQLizer.

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"
}
FieldTypeMeaning
statusstringAlways healthy.
versionstringThe version of the service.
environmentstringThe environment the service runs in.
Status CodeMeaning
200The service process is running.

HTTP example

curl -X GET \
  https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/health

Check that the service is ready

GET https://<EXTERNAL_ENDPOINT>:8529/reasoner/:service_id_postfix/health/ready
Role-based access control (RBAC)

Any authenticated user can call this endpoint. You need a valid token, but no permission is checked.

See Role-based access control for the AQLizer.

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" }
      }
    }
  }
}
FieldTypeMeaning
readybooleanWhether the service is ready.
checks.opencode.statusstringhealthy or unhealthy, the status of the AI agent (OpenCode).
checks.mcp_servers.statusstringWhether MCP servers are available.
checks.mcp_servers.detailsobjectThe connection status of each MCP server.
Status CodeMeaning
200The check has run. Read ready for the result.

HTTP example

curl -X GET \
  https://<EXTERNAL_ENDPOINT>:8529/reasoner/{service_id_postfix}/health/ready