> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.trace-db.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.trace-db.com/_mcp/server.

# Run native TraceQL query or command

POST http://127.0.0.1:8090/v1/traceql
Content-Type: application/json

Current TraceDB v1 product route. This OpenAPI artifact is generated from the checked-in route manifest.

Reference: https://docs.trace-db.com/api-reference/tracedb/query/post-traceql

## Authentication

- `Authorization` header (bearer token, required) — Required by gateway-managed routes; direct local engine development can use any token.

## Servers

- `http://127.0.0.1:8090` (Local tracedb-server, default)
- `https://api.trace-db.com` (Hosted TraceDB API)

## Request

### Headers

- `Idempotency-Key` (string, optional) — Optional local data-dir replay key scoped by method and path. Receipts are WAL/checkpoint-backed in the local engine. same key plus same raw request body replays the first successful response; same key with a different body returns 409 Conflict.

### Body (application/json)

This endpoint expects a TraceQlQueryRequest.

- `query` (string, optional)

## Response

### 200

Successful TraceDB response.

- `explain` (HybridExplain, optional) — Explain response.
- `next_cursor` (string, optional, nullable)
- `results` (list of HybridQueryRow, optional)

## Errors

### 400 Bad Request Error

Bad request or validation failure.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 401 Unauthorized Error

Unauthorized gateway request.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 404 Not Found Error

Route not found.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 409 Conflict Error

Idempotency key was reused with a different request body.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 429 Too Many Requests Error

Gateway rate limit exceeded.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 500 Internal Server Error

Engine or gateway failure.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 502 Bad Gateway Error

Gateway upstream failure.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

### 503 Service Unavailable Error

Service unavailable.

- `code` (string, optional) — Stable machine-readable error code when available; existing clients can continue to read error.
- `error` (string, optional)

## Types

### HybridExplain

Explain response.

- `access_path_timings` (list of AccessPathTiming, optional)
- `access_paths` (list of AccessPathExplain, optional)
- `candidate_budget` (integer, optional)
- `deduped_candidate_count` (integer, optional)
- `dirty_feature_count` (integer, optional)
- `early_stop_reason` (string, optional, nullable)
- `exact_fallback_triggered` (boolean, optional)
- `failed_feature_count` (integer, optional)
- `final_visibility_guard_count` (integer, optional)
- `final_visibility_guard_removed` (integer, optional)
- `freshness_mode` (string, optional)
- `fusion_method` (string, optional)
- `hot_overlay_searched` (boolean, optional)
- `lexical_cache_hits` (integer, optional)
- `lexical_cache_misses` (integer, optional)
- `lexical_indexed_documents` (integer, optional)
- `lexical_scored_documents` (integer, optional)
- `materialized_count` (integer, optional)
- `missing_feature_count` (integer, optional)
- `module_versions` (list of string, optional)
- `opened_candidate_streams` (list of string, optional)
- `pending_feature_count` (integer, optional)
- `phase_timings` (list of QueryPhaseTiming, optional)
- `planner_candidates` (list of Candidate, optional)
- `policy_epoch` (integer, optional)
- `read_epoch` (integer, optional)
- `returned_count` (integer, optional)
- `scalar_filter_applied` (boolean, optional)
- `scalar_filter_predicates` (list of string, optional)
- `scalar_filter_removed_records` (integer, optional)
- `scalar_filter_visible_records` (integer, optional)
- `schema_epoch` (integer, optional)
- `segments_scanned` (integer, optional)
- `selected_strategy` (string, optional, nullable)
- `skipped_access_paths` (list of string, optional)
- `tenant_mask_visible_records` (integer, optional)
- `text_candidates` (integer, optional)
- `vector_candidates` (integer, optional)

### HybridQueryRow

Hybrid query result row.

- `fields` (map from string to any, optional) — Record field map.
- `record_id` (string, optional)
- `score` (HybridScoreComponents, optional) — Hybrid query score components.
- `tenant_id` (string, optional)
- `version_id` (integer, optional)

### AccessPathTiming

Access path timing entry.

- `access_path_id` (string, optional)
- `build_ms` (double, optional)
- `open_ms` (double, optional)

### AccessPathExplain

Access path explain entry.

- `access_path_id` (string, optional)
- `candidates` (integer, optional)
- `opened` (boolean, optional)
- `visibility_checked_before_open` (boolean, optional)

### QueryPhaseTiming

Query phase timing entry.

- `elapsed_ms` (double, optional)
- `phase` (string, optional)

### Candidate

Planner candidate explain row.

- `freshness` (string, optional)
- `record_id` (string, optional)
- `score_components` (HybridScoreComponents, optional) — Hybrid query score components.
- `score_upper_bound` (double, optional, nullable)
- `source` (string, optional)
- `version_id` (integer, optional)
- `visibility_checked` (boolean, optional)

### HybridScoreComponents

Hybrid query score components.

- `final_score` (double, optional)
- `freshness_penalty` (double, optional, nullable)
- `lexical` (double, optional, nullable)
- `relational` (double, optional, nullable)
- `vector` (double, optional, nullable)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "explain": {
    "access_path_timings": [
      {
        "access_path_id": "ap_12345",
        "build_ms": 12.5,
        "open_ms": 8.3
      }
    ],
    "access_paths": [
      {
        "access_path_id": "ap_12345",
        "candidates": 5,
        "opened": true,
        "visibility_checked_before_open": true
      }
    ],
    "candidate_budget": 100,
    "deduped_candidate_count": 95,
    "dirty_feature_count": 3,
    "early_stop_reason": "max_candidates_reached",
    "exact_fallback_triggered": false,
    "failed_feature_count": 2,
    "final_visibility_guard_count": 10,
    "final_visibility_guard_removed": 2,
    "freshness_mode": "realtime",
    "fusion_method": "weighted_sum",
    "hot_overlay_searched": true,
    "lexical_cache_hits": 150,
    "lexical_cache_misses": 25,
    "lexical_indexed_documents": 5000,
    "lexical_scored_documents": 4800,
    "materialized_count": 120,
    "missing_feature_count": 1,
    "module_versions": [
      "v1.4.2",
      "v2.0.1"
    ],
    "opened_candidate_streams": [
      "stream_01",
      "stream_02"
    ],
    "pending_feature_count": 4,
    "phase_timings": [
      {
        "elapsed_ms": 35.7,
        "phase": "parsing"
      },
      {
        "elapsed_ms": 120.4,
        "phase": "planning"
      },
      {
        "elapsed_ms": 250.9,
        "phase": "execution"
      }
    ],
    "planner_candidates": [
      {
        "freshness": "2024-06-01T12:00:00Z",
        "record_id": "rec_98765",
        "score_components": {
          "final_score": 0.95,
          "freshness_penalty": 0.05,
          "lexical": 0.4,
          "relational": 0.3,
          "vector": 0.2
        },
        "score_upper_bound": 1,
        "source": "primary_index",
        "version_id": 3,
        "visibility_checked": true
      }
    ],
    "policy_epoch": 42,
    "read_epoch": 105,
    "returned_count": 10,
    "scalar_filter_applied": true,
    "scalar_filter_predicates": [
      "status = 'active'",
      "region = 'us-east-1'"
    ],
    "scalar_filter_removed_records": 15,
    "scalar_filter_visible_records": 985,
    "schema_epoch": 7,
    "segments_scanned": 12,
    "selected_strategy": "hybrid_vector_lexical",
    "skipped_access_paths": [
      "ap_54321",
      "ap_67890"
    ],
    "tenant_mask_visible_records": 1000,
    "text_candidates": 7,
    "vector_candidates": 3
  },
  "next_cursor": "cursor_abc123xyz",
  "results": [
    {
      "fields": {},
      "record_id": "rec_98765",
      "score": {
        "final_score": 0.95,
        "freshness_penalty": 0.05,
        "lexical": 0.4,
        "relational": 0.3,
        "vector": 0.2
      },
      "tenant_id": "tenant_001",
      "version_id": 3
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "http://127.0.0.1:8090/v1/traceql"

payload = {}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'http://127.0.0.1:8090/v1/traceql';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://127.0.0.1:8090/v1/traceql"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://127.0.0.1:8090/v1/traceql")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://127.0.0.1:8090/v1/traceql")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://127.0.0.1:8090/v1/traceql', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("http://127.0.0.1:8090/v1/traceql");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://127.0.0.1:8090/v1/traceql")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```