4.6. REST API#
The QuasarDB REST server, qdb_rest, gives HTTP access to a QuasarDB cluster.
A client needs an HTTP library and no QuasarDB client library.
This page describes version 2 of the API, which the server serves below /api/v2.
The API has routes for these tasks:
Get and renew access tokens.
Run queries in the QuasarDB query language or in SQL.
Create, list, describe and delete tables.
Write rows to tables and read rows from tables.
Attach tags to tables and find tables by tag.
Read the statistics of the cluster nodes.
To install and configure the server, see qdb_rest. To connect an application or tool through the Arrow Flight SQL standard, see Arrow Flight SQL.
4.6.1. Requirements#
Before you start, make sure that:
You have access to a running QuasarDB cluster.
A
qdb_restserver runs and connects to that cluster.You have an HTTP client. The examples on this page use curl .
The examples on this page use a server that listens on https://127.0.0.1:40443.
This is the default address of the HTTPS listener.
4.6.2. Conventions#
These rules apply to each example and to each route on this page.
- Certificates
A server without a configured certificate generates a self-signed certificate at each start. The
-kflag tellscurlto accept that certificate. Omit the flag when the server has a certificate that your computer trusts.- Request bodies
A query is the request body, as plain text. Send it with
Content-Type: text/plainorContent-Type: application/sql. The-dflag ofcurlsets a different content type, and the server then answers status 415. The examples set the header explicitly and send the body with--data-binary.- Response formats
The
Acceptheader selects the format of a result. JSON is the default. See Response formats.- Request identifiers
Each response has an
X-Request-Idheader. The server writes the same identifier in its log lines for that request. When a request has anX-Request-Idheader, the server uses that value.- Errors
The status code of a response tells you if the request succeeded. A response with status 200 never contains an error. See Errors.
4.6.3. Authentication#
Each data route needs an access token. You get an access token from the login route. The server checks your credentials against the cluster before it issues a token.
A QuasarDB cluster operates in a secure mode or in an insecure mode. If you do not know the mode of your cluster, ask your system administrator.
4.6.3.1. Insecure cluster#
An insecure cluster has no users. Send an empty JSON object to the login route:
curl -k -X POST https://127.0.0.1:40443/api/v2/auth/login \
-H 'Content-Type: application/json' \
-d '{}'
The server answers with an access token and a refresh token:
{
"access_token": "eyJhbGciOiJkaXIiLCJlbmMi...",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "eyJhbGciOiJkaXIiLCJlbmMi..."
}
expires_in is the validity of the access token, in seconds.
4.6.3.2. Secure cluster#
A secure cluster needs these two parameters:
A username.
The secret key of that user.
Your user security file contains these two parameters as a JSON object:
{
"username": "tintin",
"secret_key": "SIMC1BQCOgjU7rkMoMP3gVQACA6JcxRwLhok/5bgS0J8="
}
This object is the body of the login request. You can send the file itself:
curl -k -X POST https://127.0.0.1:40443/api/v2/auth/login \
-H 'Content-Type: application/json' \
--data-binary @user_private.key
The response is the same as for an insecure cluster. When the cluster refuses the credentials, the server answers status 401.
The server holds the public key of the cluster in its configuration, so a client does not send it. For more information about users and keys, see the security manual.
4.6.3.3. Use the access token#
Send the access token in the Authorization header of each request:
Authorization: Bearer <access_token>
The examples that follow read the token from a shell variable:
TOKEN=<access_token>
The server does not accept a token in the URL or in a cookie.
4.6.3.4. Renew the tokens#
By default, an access token is valid for 15 minutes and a refresh token is valid for 14 days. The system administrator can change the two durations in the server configuration.
To get a new access token, send the refresh token to the refresh route:
curl -k -X POST https://127.0.0.1:40443/api/v2/auth/refresh \
-H 'Content-Type: application/json' \
-d '{"refresh_token": "<refresh_token>"}'
The response has the same fields as the login response, with a new access token and a new refresh token. The validity of the new refresh token starts at the time of the refresh. Use the new refresh token for the subsequent refresh.
The refresh route does not connect to the cluster. The server accepts a refresh token only on the refresh route. When the refresh token expires, the route answers status 401. Then send your credentials to the login route again.
4.6.3.5. Session#
The session route shows the user, the cluster and the token of the current request:
curl -k https://127.0.0.1:40443/api/v2/session \
-H "Authorization: Bearer $TOKEN"
{
"username": "tintin",
"cluster": {"uri": "qdb://127.0.0.1:2836", "secured": true},
"token": {
"typ": "access",
"iat": 1794389541,
"exp": 1794390441,
"jti": "01a1c9f3-80f8-793f-ad47-3b114905ffa6",
"auth_time": 1794389541
},
"server": {"version": "3.15.0.dev0"}
}
The times are in seconds since the Unix epoch.
iat is the time the server issued the token and exp is the time the token expires.
auth_time is the time of the login that started the session.
For an anonymous user, username is empty.
4.6.3.6. Logout#
The logout route answers status 204:
curl -k -X POST https://127.0.0.1:40443/api/v2/auth/logout \
-H "Authorization: Bearer $TOKEN"
The server keeps no session state. Thus a token stays valid until it expires, also after a logout. Discard the access token and the refresh token in your client after the logout.
4.6.4. Queries#
The query route runs one query and returns its result.
The query is the body of a POST request to /api/v2/query.
For the query language, see the query language documentation.
This example calculates the total traded volume of a table:
curl -k -X POST https://127.0.0.1:40443/api/v2/query \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/plain' \
--data-binary 'SELECT sum(volume) FROM trades'
[{"columns":[{"name":"sum(volume)","type":"int64","data":[495]}]}]
The maximum size of a query is 1 MiB.
4.6.4.1. Response formats#
The query route and the row reader return a result in one of four formats.
The Accept header of the request selects the format.
|
Format |
|---|---|
|
JSON, one object for each batch of rows, with one array for each column |
|
Newline-delimited JSON, one object for each row |
|
CSV with a header row |
|
Arrow IPC stream |
The server uses the first media type in the header that it knows.
The server returns JSON when the header is absent or contains no media type that it knows.
The server ignores q weights.
The examples that follow show the result of SELECT * FROM trades in the three text formats.
4.6.4.1.1. JSON#
[
{
"columns": [
{"name": "$timestamp", "type": "timestamp", "data": ["2026-01-05T09:30:00.000000000Z", "2026-01-05T09:30:01.500000000Z", "2026-01-05T09:30:02.000000000Z"]},
{"name": "$table", "type": "utf8", "data": ["trades", "trades", "trades"]},
{"name": "price", "type": "float64", "data": [101.25, 101.5, 101.4]},
{"name": "volume", "type": "int64", "data": [300, 120, 75]},
{"name": "exchange", "type": "utf8", "data": ["XNAS", "XNYS", "XNAS"]},
{"name": "note", "type": "utf8", "data": ["open", null, null]}
]
}
]
The body is an array of results.
The server sends a large result as more than one element of the array.
All elements have the same columns, and a client appends the data arrays in sequence.
The server writes the body without the line breaks that this example shows.
4.6.4.1.2. NDJSON#
{"$timestamp":"2026-01-05T09:30:00.000000000Z","$table":"trades","price":101.25,"volume":300,"exchange":"XNAS","note":"open"}
{"$timestamp":"2026-01-05T09:30:01.500000000Z","$table":"trades","price":101.5,"volume":120,"exchange":"XNYS","note":null}
{"$timestamp":"2026-01-05T09:30:02.000000000Z","$table":"trades","price":101.4,"volume":75,"exchange":"XNAS","note":null}
Each line is one row. A result without rows is an empty body.
4.6.4.1.3. CSV#
$timestamp,$table,price,volume,exchange,note
2026-01-05T09:30:00.000000000Z,trades,101.25,300,XNAS,open
2026-01-05T09:30:01.500000000Z,trades,101.5,120,XNYS,
2026-01-05T09:30:02.000000000Z,trades,101.4,75,XNAS,
The first line is the header. A result without rows is the header only. An empty field is a null value.
4.6.4.1.4. Arrow#
The body is a stream in the Arrow IPC streaming format. Each Arrow library can read it. Use this format for large results and when you need the full precision of each value.
4.6.4.2. Values in the text formats#
JSON, NDJSON and CSV write values as this table shows.
Value |
Text |
|---|---|
Timestamp |
RFC 3339 in UTC with nine fractional digits, for example |
Integer |
A number |
Floating point |
A number. NaN and the infinities are |
String and symbol |
The text of the value |
Blob |
Base64 with padding |
Null |
|
Note
Many JSON parsers read each number as a 64-bit floating point value. Such a parser loses digits of an integer larger than 253. Use the Arrow format when you need each digit.
The type of a column in the JSON format is the name of its Arrow type.
A double column of a table has type float64 in a result.
A string column and a symbol column have type utf8, and a blob column has type binary.
4.6.4.3. SQL queries#
The server contains an SQL engine, DuckDB with the Quasar extension.
A query that starts with #sql and a space runs in that SQL engine.
The Quasar OLAP page describes the SQL that this engine supports.
Each other query runs in the QuasarDB query engine.
In SQL, the cluster is the catalog qdb.
Thus the table trades has the name qdb.trades:
curl -k -X POST https://127.0.0.1:40443/api/v2/query \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/plain' \
-H 'Accept: text/csv' \
--data-binary '#sql SELECT exchange, sum(volume) AS volume FROM qdb.trades GROUP BY exchange ORDER BY exchange'
exchange,volume
XNAS,375
XNYS,120
The request and the response formats are the same as for a QuasarDB query.
The server does not make a difference between uppercase and lowercase in the #sql prefix.
These rules apply to SQL queries:
The query runs with the credentials of your token, so the permissions of your user apply.
When the body contains more than one statement, the server runs each statement and returns the last result.
An SQL result can contain types that the text formats cannot write, for example a list. The server then answers status 500. Cast the column to a scalar type in the query, or request the Arrow format.
The server limits the number of users that run SQL at the same time. At the limit, the server answers status 503 with a
Retry-Afterheader.
4.6.4.4. Compression#
The server compresses a response when the request has an Accept-Encoding header.
The server supports gzip and zstd.
It uses the first of gzip, zstd and identity in the header and ignores q weights.
With curl, the --compressed flag requests a compressed response and decompresses it:
curl -k --compressed -X POST https://127.0.0.1:40443/api/v2/query \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/plain' \
--data-binary 'SELECT * FROM trades'
4.6.5. Tables#
4.6.5.1. Create a table#
To create a table, send its description to POST /api/v2/tables:
curl -k -i -X POST https://127.0.0.1:40443/api/v2/tables \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"name": "trades",
"shard_size": 86400000,
"columns": [
{"name": "price", "type": "double"},
{"name": "volume", "type": "int64"},
{"name": "exchange", "type": "symbol", "symtable": "exchanges"},
{"name": "note", "type": "string"}
]
}'
Field |
Description |
|---|---|
|
The name of the table. |
|
The shard size in milliseconds. This field is mandatory. |
|
The columns, in sequence. Do not include |
|
One of |
|
The symbol table of a |
The server answers status 201 with an empty body.
The Location header contains the path of the new table:
HTTP/2 201
location: /api/v2/tables/trades
When a table with that name exists, the server answers status 409.
4.6.5.2. List the tables#
GET /api/v2/tables returns the names of the tables.
The optional prefix parameter keeps only the names that start with its value:
curl -k 'https://127.0.0.1:40443/api/v2/tables?prefix=tra' \
-H "Authorization: Bearer $TOKEN"
{"tables":["trades"]}
4.6.5.3. Describe a table#
GET /api/v2/tables/{name} returns the description of one table:
curl -k https://127.0.0.1:40443/api/v2/tables/trades \
-H "Authorization: Bearer $TOKEN"
{
"name": "trades",
"shard_size": 86400000,
"ttl": 0,
"columns": [
{"name": "$timestamp", "type": "timestamp"},
{"name": "price", "type": "double"},
{"name": "volume", "type": "int64"},
{"name": "exchange", "type": "symbol", "symtable": "exchanges"},
{"name": "note", "type": "string"}
],
"tags": []
}
The fields are those of the create request, with $timestamp as the first column.
ttl is the time to live of the data in milliseconds, and 0 means that the table has no time to live.
tags contains the tags of the table.
When the table does not exist, the server answers status 404.
4.6.5.4. Delete a table#
DELETE /api/v2/tables/{name} deletes a table and its data:
curl -k -X DELETE https://127.0.0.1:40443/api/v2/tables/trades \
-H "Authorization: Bearer $TOKEN"
The server answers status 204. When the table does not exist, the server answers status 404.
Warning
You cannot restore a deleted table.
4.6.6. Rows#
4.6.6.1. Write rows#
POST /api/v2/rows writes the rows of the request body to their tables.
One request can contain rows for more than one table.
Each row has these two columns in addition to its data columns:
$tableis the name of the table that receives the row.
$timestampis the timestamp of the row.
This is a CSV body with three rows for the table trades:
$table,$timestamp,price,volume,exchange,note
trades,2026-01-05T09:30:00Z,101.25,300,XNAS,open
trades,2026-01-05T09:30:01.5Z,101.5,120,XNYS,
trades,2026-01-05T09:30:02Z,101.4,75,XNAS,
Send the file with its content type:
curl -k -X POST https://127.0.0.1:40443/api/v2/rows \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/csv' \
--data-binary @rows.csv
{"rows":3,"tables":1,"parse_ms":1,"push_ms":8}
The response gives the number of rows and tables that the server wrote.
parse_ms and push_ms are the durations in milliseconds to read the body and to write the rows.
The Content-Type header selects the format of the body.
The server accepts the four formats that it returns: text/csv, application/x-ndjson, application/json and application/vnd.apache.arrow.stream.
For each other type, the server answers status 415.
Thus you can send the result of a query that contains $table and $timestamp to this route without a change.
These rules apply to the body:
The maximum size of the body is 64 MiB. Divide a larger dataset into more than one request.
Each table must exist. If one table does not exist, the server answers status 404 and writes no rows.
A column that the body does not contain gets a null value.
In the text formats, an empty field is a null value. The text formats cannot contain an empty string.
In an Arrow body, the type of each column must be the same as the type of the table column.
4.6.6.1.1. Options#
URL parameters set the options of the write operation.
Parameter |
Values |
Description |
|---|---|---|
|
|
How the cluster writes the rows. The default is |
|
|
What the cluster does with a row that is a duplicate. Without this parameter, the cluster does not deduplicate. |
|
A list of column names, with commas between them |
The columns that identify a duplicate. Mandatory with |
With push-mode=async, the cluster accepts the rows and writes them to the tables later.
In that mode, push_ms is the time until the cluster accepted the rows.
Thus the row reader and an SQL query can return the rows a short time after the response.
This example drops each row that has the same timestamp as a row in the table:
curl -k -X POST 'https://127.0.0.1:40443/api/v2/rows?deduplication-mode=drop&deduplication-columns=$timestamp' \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/csv' \
--data-binary @rows.csv
4.6.6.1.2. Compressed bodies#
The route accepts a body with Content-Encoding: gzip or Content-Encoding: zstd:
gzip rows.ndjson
curl -k -X POST https://127.0.0.1:40443/api/v2/rows \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/x-ndjson' \
-H 'Content-Encoding: gzip' \
--data-binary @rows.ndjson.gz
The limit of 64 MiB applies to the compressed body.
4.6.6.2. Read rows#
GET /api/v2/tables/{name}/rows returns the rows of one table without a query.
The Accept header selects the format, as for a query.
Parameter |
Description |
|---|---|
|
A list of column names, with commas between them. The response contains these columns in this sequence. Without this parameter, the response contains |
|
The start of the time range, in RFC 3339. The range includes this time. |
|
The end of the time range, in RFC 3339. The range does not include this time. |
Set start and end together.
Without them, the server returns all rows of the table.
This example reads two columns of the rows in a range of two seconds:
curl -k 'https://127.0.0.1:40443/api/v2/tables/trades/rows?columns=price,volume&start=2026-01-05T09:30:00Z&end=2026-01-05T09:30:02Z' \
-H "Authorization: Bearer $TOKEN" \
-H 'Accept: text/csv'
price,volume
101.25,300
101.5,120
When the table does not exist, the server answers status 404. An unknown column and an incorrect range give status 400.
4.6.8. Cluster statistics#
GET /api/v2/cluster returns the statistics of each node of the cluster.
GET /api/v2/cluster/nodes/{id} returns the statistics of one node.
The id of a node is its address, in the format <ip>:<port>:
curl -k https://127.0.0.1:40443/api/v2/cluster \
-H "Authorization: Bearer $TOKEN"
This example shows one node:
{
"nodes": [
{
"id": "127.0.0.1:2836",
"engine_build_date": "2026-10-19T09:54:38.000000000Z",
"engine_version": "3.15.0.dev0",
"hardware_concurrency_count": 16,
"memory": {
"resident_bytes": 272214102,
"resident_count": 722018,
"physmem": {"used_bytes": 50981109760, "total_bytes": 51539607552},
"vm": {"used_bytes": 32317030400, "total_bytes": 140737488338944}
},
"network": {
"current_users_count": 0,
"partitions_count": 16,
"sessions": {"available_count": 509, "unavailable_count": 3, "max_count": 512}
},
"chord.node_id": "0-0-0-1",
"operating_system": "Darwin 27.2.0 amd64",
"persistence": {"read_bytes": 13316208813, "written_bytes": 121850329491},
"requests": {"out_bytes": 594816935, "successes_count": 22161984, "total_count": 22601003},
"startup_epoch": 1793605178
}
]
}
The nodes are in the sequence of their id.
The route for one node returns one such object without the nodes array.
Status |
Meaning |
|---|---|
404 |
The cluster has no node with that address. |
503 |
The server cannot connect to the node. |
On a secure cluster, the permissions of your user control access to the statistics.
4.6.9. Health probes#
The two probes need no token and return an empty body.
Route |
Response |
|---|---|
|
Status 200 when the server process runs. |
|
Status 200 when the server can connect to the cluster, and status 503 when it cannot. |
The server also serves the two probes without the version, at /api/status/liveness and /api/status/readiness.
4.6.10. Errors#
Each error response of the API has the content type application/problem+json and this body (RFC 9457 ):
{
"status": 400,
"title": "Bad Request",
"detail": "query_execute_arrow (operation=query_execute_arrow, query=SELECT * FROM missing): An entry matching the provided alias cannot be found."
}
status is the HTTP status code and title is the standard text of that code.
detail describes this error.
When the cluster or the SQL engine refuses a request, detail contains the message of the cluster or the engine.
The status code tells you where the cause of the error is.
Status |
Cause |
|---|---|
400 |
The cluster or the SQL engine refused the request. Examples are an incorrect query, an unknown table in a query and an operation that your user is not permitted to do. The server also answers 400 for an incorrect body or parameter. |
401 |
The token is absent, incorrect or expired, or the cluster refused the credentials. Get a new token. |
404 |
The table, tag or node in the path does not exist. |
409 |
A table with that name already exists. |
413 |
The body is larger than the limit. |
415 |
The server does not support the |
500 |
The REST server failed. |
503 |
The server cannot connect to the cluster, or it is at a limit. When the response has a |
A response with status 401 has a WWW-Authenticate header, except on the login route.
The value is Bearer when the request had no token.
The value is Bearer error="invalid_token" when the server did not accept the token.
An unknown path gives status 404 and an incorrect method gives status 405. These two responses have a plain text body.
A response can stop before its end when an error occurs after the server sent the first bytes. A JSON body that stops early is not valid JSON, so a JSON parser detects it.
4.6.11. Routes#
Method |
Path |
Task |
|---|---|---|
POST |
|
Get an access token and a refresh token |
POST |
|
Renew the tokens |
POST |
|
End the session |
GET |
|
Show the session |
POST |
|
Run a query |
GET |
|
List the tables |
POST |
|
Create a table |
GET |
|
Describe a table |
DELETE |
|
Delete a table |
GET |
|
Read rows |
POST |
|
Write rows |
PUT |
|
Attach a tag |
DELETE |
|
Detach a tag |
GET |
|
List the entries of a tag |
POST |
|
Find entries |
GET |
|
Read the statistics of all nodes |
GET |
|
Read the statistics of one node |
GET |
|
Liveness probe |
GET |
|
Readiness probe |