---
title: "Query"
method: POST
path: "/ai/query"
tags: ["agent"]
---

# Query

`POST /ai/query`

## Request

- Base URL: `https://api.dialogbrain.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.dialogbrain.com/ai/query`
- Auth: none declared

AI query endpoint using NEW Planner/Executor workflow.

New Plan-First Workflow (Phases 1 & 2):
1. Create execution plan from query
2. Return plan for user approval (via WebSocket)
3. Execute plan after approval
4. Stream progress via WebSocket

This replaces the old AIService.stream_with_tools() approach.

SECURITY: user_id is extracted from JWT token (cannot be spoofed).

Args:
    request: Query request
    user: Current user (from JWT)
    db: Database session

Returns:
    Plan details and approval status

## Request body

- SrcApiAgentQueryRequest: Request for simple query to AI agent.
  - `query` string, required
  - `session_id` string, required
  - `model` string, nullable
  - `context` object, nullable
  - `use_rag` boolean, nullable

## Response `200`

Successful Response

- QueryResponse: Response from AI agent query.
  - `response` string, required
  - `actions` object[], nullable

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/dialogbrain/apis/dialogbrain-v2-api-gateway.md) · [All operations](https://skmtc.dev/dialogbrain/apis/dialogbrain-v2-api-gateway/llms.txt) · [OpenAPI document](https://skmtc.dev/dialogbrain/apis/dialogbrain-v2-api-gateway/revisions/77bef09a9209?raw)
