NLQ (Natural Language Queries) API
NLQ lets you ask plain-English (or zh-CN) questions about your CRM data — Anvil interprets the question, runs the right query, and returns a chart-ready visualization.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | `/api/v1/nlq/query` | Ask a question |
| GET | `/api/v1/nlq/suggestions` | Suggested questions + recent history |
| GET | `/api/v1/nlq/history` | Past queries |
Examples
curl -X POST https://api.anvilhk.com/api/v1/nlq/query \
-H "Authorization: Bearer $ANVIL_KEY" \
-H "X-Tenant-ID: $TENANT" \
-H "Content-Type: application/json" \
-d '{ "question": "Top 10 contacts by lead value this quarter" }'Response includes answer_text, a visualization object (type / data / x_key / y_key), and follow-up question suggestions.
Every response uses the standard envelope:
{
"success": true,
"data": { /* resource or array */ },
"meta": { "total": 100, "cursor": "...", "hasMore": true },
"error": { "code": "ERROR_CODE", "message": "Human readable" }
}error is omitted on success; meta is omitted when not paginating.
Rate Limits
NLQ shares the per-user AI cap of 60/min/user.