Skip to content

Search API

Where: Settings › Agents › API Agent for the token. Your application calls Tursio over HTTPS.
Who can use it: Admins and Owners create the token.

The search API brings Tursio's answers into your own application. Your backend sends a question in plain language with an API token, and gets back the SQL, the result table, and a summary to show in your UI. Tursio applies the same access control as in the portal when you tell it who is asking.

Get a token

The search API accepts tokens from the API agent named default. It's the same token the MCP server uses.

  1. Open Settings › Agents and find the API Agent section.
  2. Open the agent named default. If there isn't one, add an API agent with the name default.
  3. Create a token and copy it. Tokens are valid for two years.

For the full steps, see API Agent.

Tokens from other API agents

The search API rejects tokens from API agents with any other name. Those calls get 401 Unauthorized.

Asking questions

  1. Send the question from your backend to /nlp-search on your Tursio host. Put the token in the SmartApps-License header.
  2. Pass the dataset ID and the question. The dataset ID is the dataset_id in the database's MCP package configuration file.
  3. Pass the user's email in user so Tursio applies that user's access. See Access control below.
  4. Show the answer in your UI: the summary, the table, and, if you want, the sql.
Search request and response
curl -X POST https://<your-tursio-hostname>/nlp-search \
  -H "Content-Type: application/json" \
  -H "SmartApps-License: <token>" \
  -d '{
        "dataset": "<dataset ID>",
        "question": "How many orders shipped last month?",
        "user": "user@example.com",
        "generate_summary": true
      }'
Field Required Meaning
dataset Yes The dataset ID.
question Yes The question in plain language.
user No The email of the Tursio user who is asking.
generate_summary No true by default. Set false to skip the summary and get only the SQL and table.

A successful call returns 200 with:

Field Meaning
tursio_search_id The ID of this search. Use it to send feedback.
sql The SQL Tursio ran.
table The result as a Markdown table. Empty when no rows match.
summary A plain-language summary of the result. Present when generate_summary is on.
budget_warning Present only when this search took the AI agent over its daily budget. The search itself still returns.

Errors return JSON with an error message:

Status When
400 dataset or question is missing.
401 The token is missing, expired, or not from the default API agent.
402 The AI agent's daily budget is used up.
403 The user doesn't have access to this dataset.
404 No dataset with that ID.

Send feedback

  1. Keep the tursio_search_id from the search response.
  2. Post it to /nlp-feedback with positive or negative, and an optional comment.
Feedback request
curl -X POST https://<your-tursio-hostname>/nlp-feedback \
  -H "Content-Type: application/json" \
  -H "SmartApps-License: <token>" \
  -d '{
        "tursio_search_id": "<id from the search response>",
        "feedback": "negative",
        "feedback_details": "Wrong date range"
      }'

The call returns {"status": "ok"}. Tursio ignores feedback with a value other than positive or negative, or for a search ID it doesn't recognize, and still returns ok.

Get context

Your application can read the dataset's semantic context: the description of its tables and columns that helps phrase questions well. Post the dataset ID to /nlp-context. Tursio returns the context as plain text.

Context request
curl -X POST https://<your-tursio-hostname>/nlp-context \
  -H "Content-Type: application/json" \
  -H "SmartApps-License: <token>" \
  -d '{"dataset": "<dataset ID>", "user": "user@example.com"}'

The context includes your edits on the MCP tab of the Context page. See MCP.

Access control

Tursio matches the user email to a Tursio user. When it finds one, that user's access applies: the databases they can see, and the table, column, and row rules on the Access Control tab.

Calls without a matching user

A call with no user, or with an email that doesn't match a Tursio user, isn't tied to anyone. It isn't limited by access control and can query any dataset. Always pass the signed-in user's email.

Tips and limits

  • Call Tursio from your backend, not the browser. The token is a secret, and Tursio doesn't accept cross-origin browser requests.
  • Use HTTPS so the token isn't sent in clear text. See Upgrade and maintain to turn on HTTPS.
  • Searches count toward the AI agent's daily budget. When it runs out, calls get 402 until midnight. See Set a daily budget.
  • Large results are cut. The table holds the first rows only, up to a row limit and a size cap.
  • Deleting the default API agent removes its tokens. Your application and the MCP server stop working until you add a new token.
  • Use the MCP server for AI assistants. Use it when an AI assistant, such as Claude, ChatGPT, or Copilot, should query Tursio. Use the search API when your own code shows the answer. See MCP server.
  • People can also use Tursio in Microsoft Teams. See Use Tursio in Teams.