Best practices
Recommended flow
1. (optional) GET /v1/history?q=<question> → is there a saved answer already?
2. POST /v1/ask → only if there isn't (spends LLM)
3. run sql + params on your database (read-only user)
4. POST /v1/feedback → 👍 / 👎 from the user
Checklist
- The call to Datafala goes out from your backend; the API key never goes to the browser or the app.
- The SQL runs with a read-only user, with access only to the registered tables and a maximum time per query.
-
paramsis always passed to the driver, even when empty. -
end_useris sent in every question, generated with HMAC and a fixed server secret. - If the system is multi-company, there is RLS, filtered views or restricted access (see Data scope).
- The timeout of your HTTP client on
/v1/askis at least 60 s, and a timeout is not retried automatically. - Errors are handled by the
code, withRetry-Afterrespected on429and503. - The
request_id(or theX-Request-IDheader) is recorded in your logs. - The user can give 👍 / 👎, sent to
/v1/feedback.
Save tokens
- Reuse before generating. Repeated questions can come from
/v1/history?q=or from your own cache byrequest_id. - Be careful with relative dates when reusing: the stored
paramsare the ones from the day of the question. - Show the
explanationto the user. It helps people notice when the query is not what they wanted, and a 👎 becomes a signal for the administrator to improve the context and examples.