Ask questions

Every option of the chat request, every field of the answer, and how SQL, rows and charts are controlled.

POST /v1/agents/{agent_id}/chat asks one question and returns one answer. It starts a new conversation unless you pass a session_id.

Request

FieldTypeDefaultMeaning
querystring— (required)The question, in plain language.
session_idstringnew conversationContinue an existing conversation. A session_id that belongs to another agent returns 404.
debug_infobooleanagent setting, else falseReturn the SQL, the tables used and the result rows in debug_info.
chart_outputbooleanagent setting, else trueReturn a chart suggestion when the result suits one.
follow_upbooleanagent setting, else falseReturn suggested next questions in follow_up.
allowed_chartsstring[]agent settingLimit which chart types may be suggested.
user_idstringthe key's userWho asked, as recorded in analytics and conversation history.

Query parameter stream (default false) switches the response to server-sent events. See Streaming.

A field you leave out (or send as null) falls back to the agent's own setting in the app, then to the default above.

Python
import os
import requests

API_ROOT = "https://futuresmart.ai/database-agent/api"
AGENT_ID = os.environ["DATABASE_AGENT_ID"]

r = requests.post(
    f"{API_ROOT}/v1/agents/{AGENT_ID}/chat",
    headers={"X-API-Key": os.environ["DATABASE_AGENT_API_KEY"]},
    json={
        "query": "How many orders were placed in each month of 2025? Show a bar chart.",
        "debug_info": True,
        "chart_output": True,
        "follow_up": True,
    },
    timeout=180,
)
r.raise_for_status()
answer = r.json()

print(answer["response"])
result = answer["debug_info"]["db_result"]
print([c["name"] for c in result["columns"]], result["row_count"], "rows")
if answer["chart_output"]:
    print("Chart:", answer["chart_output"]["chart_suggestion"])
print("Try next:", answer["follow_up"])

Response

FieldTypeMeaning
responsestringThe answer, in Markdown (it may contain headings, bold text and tables).
session_idstringThe conversation this answer belongs to.
chat_idstringThis question-and-answer turn. Used to rate an answer and to export rows.
is_answeredbooleanfalse when the agent could not answer from the data — for example the question is about something the database does not hold.
follow_upstring[] | nullSuggested next questions, when follow_up was requested.
debug_infoobject | nullPresent when debug_info was requested. See below.
chart_outputobject | nullA chart suggestion, when charts are on and the result suits one.
graph_outputobject | nullThe same object as chart_output, kept for older clients.
trace_idstring | nullInternal trace reference; quote it when reporting a problem.

debug_info

FieldMeaning
query, refined_queryYour question, and the self-contained version the agent answered (follow-ups are rewritten to stand alone).
selected_db_id, selected_db_nameThe database the agent chose, when the agent has several.
sql_queryThe SQL that was run. Only when the agent's Settings → Answers shows SQL.
selected_tablesTables the query used. Only with sql_query.
db_resultcolumns (name and type), rows (one object per row, keyed by column name), row_count and truncated. Only when the agent shows results.

When a result has more than 50 rows, db_result.rows carries a 10-row preview and debug_info.export_url is a pre-signed link to the full result as CSV.

If the agent hides SQL or results in its settings, those fields are left out even when you ask for debug_info. That setting is the agent owner's choice and the API enforces it.

chart_output

JSON
{
  "chart_suggestion": "Column Chart",
  "chart_data": {
    "data": [
      { "category": "2025-01-01", "value": 216.0 },
      { "category": "2025-02-01", "value": 211.0 }
    ],
    "metadata": {
      "title": "Orders Placed by Month in 2025",
      "x_axis": { "label": "Month", "field": "month" },
      "y_axis": { "label": "Number of Orders", "field": "order_count" },
      "legend": { "show": false, "position": null },
      "colors": ["#3498db", "#e74c3c"]
    }
  },
  "metadata": null
}

chart_data.data is ready to hand to a charting library: one point per category. Asking for a chart in the question ("Show a bar chart") makes one more likely; the agent still picks the type that suits the data.

Rating an answer

Send a thumbs up or down for a turn with POST /v1/agents/{agent_id}/feedback, using the chat_id from the answer. Ratings appear in the app's analytics. See the Chat reference.

Writing good questions

  • Name the measure and the period. "Revenue by month in 2025" beats "how are sales".
  • Use the words your data uses. If the table says region, ask about regions.
  • Follow up instead of repeating context. Send "and for 2024?" to the same session_id.
  • Teach the agent your vocabulary. Table and column descriptions and example questions, set in the app or through the API reference, make answers more accurate.