Fauna Core API
Download OpenAPI specification:Download
You can use the Fauna Core HTTP API to:
- Run Fauna Query Language (FQL) queries
- Perform change data capture (CDC)
- Subscribe to real-time events
The Fauna client drivers, Fauna Dashboard, and Fauna CLI use the Core API to access data in Fauna databases.
Fauna Core API endpoints use https://db.fauna.com as the base URL.
For example, the full URL for the /query/1
(Query)
endpoint is https://db.fauna.com/query/1
.
Fauna routes requests to a database based on the secret used for authentication. All requests and queries run in the context of a single database.
You authenticate requests to Fauna Core API endpoints using an
authentication
secret.
You pass the authentication secret as a bearer token in the
Authorization
request header.
Get an authentication secret
Fauna supports several secret types. For testing, you can create a key, which is a type of secret:
Log in to the Fauna Dashboard.
On the Explorer page, create a database.
In the database's Keys tab, click Create Key.
Choose a Role of server.
Click Save.
Copy the Key Secret. The secret is scoped to the database.
The Query endpoint lets you run Fauna Query Language (FQL) queries.
Query endpoint
Runs an FQL query against a specific database.
Every query is an independently authenticated request to the Query endpoint. The Fauna client drivers, Fauna Dashboard, and Fauna CLI use the Query endpoint to run queries.
In Fauna, every query is a
transaction, run in the context of
a single database. Fauna routes and authorizes queries using an
authentication secret,
scoped to a specific database. You pass the authentication secret as a
bearer token in the Authorization
request header.
Data format
The Query endpoint's X-Format
request header specifies the data format used to encode FQL
values in:
- Query results.
- FQL query arguments passed in the
arguments
parameter or within objects passed to thequery
parameter. - Abort values returned by abort errors.
See the Wire protocol docs.
Error handling
Error responses from the Query API include error codes.
Fauna error codes are part of the API contract and are safe to write programmatic logic against. You should first handle errors based on error code, rather than HTTP status code.
See Error handling.
Authorizations:
header Parameters
Authorization required | string Example: Bearer <FAUNA_SECRET> A Fauna authentication secret, passed as a bearer token. See Authentication for more details. |
X-Format | string Data format used to encode FQL values as JSON (and the reverse) in:
Accepts For more information, see Wire Protocol. |
X-Last-Txn-Ts | integer If set, acts as the minimum snapshot time against which the query executes. Fauna's client drivers set this value as the last |
X-Linearized | boolean If true, strictly serializes read-only queries that don't involve indexes. Queries that include writes are already strictly serialized. |
X-Max-Contention-Retries | integer Maximum number of times to retry the query due to transaction contention. |
X-Query-Tags | string A string-encoded set of query tags. Query tags let you instrument queries to better identify their source
and context in Fauna
Logs. Query
tags are returned in the response's You provide query tags as a list of
Keys and values may only support
Queries that include invalid tags return an A query can't include more than 25 query tags. Each key must be less than or equal to 40 bytes. Each value must be less than or equal to 80 bytes. The full header can't exceed 3000 bytes. |
X-Query-Timeout-Ms | integer Maximum runtime for the request in milliseconds. |
X-Typecheck | boolean Enable or disable typechecking for the query. Defaults to the typechecking configuration for the database. |
Request Body schema: application/jsonrequired
required | object or string FQL query to run. Accepts an object or a string. Use |
arguments | object Object containing variables to interpolate into the The key of each object property is the name of the variable,
referenced in the Variable names must be valid FQL identifiers. Variable values should
be encoded using the data
format
specified in the |
Responses
Request samples
- Payload
- curl - Simple query
- curl - Query object
- curl - Query string
{- "query": {
- "fql": [
- "Product.all().where(.stock ==",
- {
- "value": {
- "@int": "10"
}
}, - ")"
]
}
}
Response samples
- 200
- 400
- 401
- 409
- 429
- 440
- 500
- 502
- 503
- 504
{- "data": {
- "data": {
- "id": "410212968961146957",
- "coll": {
- "@mod": "Product"
}, - "ts": {
- "@time": "2099-07-29T14:26:37.650Z"
}, - "name": "cups",
- "description": "Translucent 9 Oz, 100 ct",
- "price": {
- "@int": 698
}, - "stock": {
- "@int": 100
}, - "category": {
- "@ref": {
- "id": "410212968956952653",
- "coll": {
- "@mod": "Category"
}
}
}
}
}, - "static_type": "Set<Product>",
- "summary": "",
- "txn_ts": 1727892962009660,
- "stats": {
- "compute_ops": 1,
- "read_ops": 18,
- "write_ops": 0,
- "query_time_ms": 215,
- "contention_retries": 0,
- "storage_bytes_read": 2158,
- "storage_bytes_write": 0,
- "rate_limits_hit": [ ]
}, - "schema_version": 1727880352326000
}
Event endpoints lets you consume events from an event source. An event source emits an event whenever tracked changes are made to a database.
You can consume the events in two ways:
Event Feeds: Make asynchronous requests that poll the event source for paginated events using the Event Feed endpoint.
Event Streams: Establish a real-time subscription that pushes events to your application through an open connection to the Event Stream endpoint.
Event Feed endpoint
The Event Feed endpoint is in beta. To use the Event Feed endpoint, you must have a Pro or Enterprise plan.
Asynchronously gets events from an event source as a paginated Event Feed.
Authorizations:
header Parameters
Authorization required | string Example: Bearer <FAUNA_SECRET> A Fauna authentication secret, passed as a bearer token. See Authentication for more details. |
X-Query-Timeout-Ms | integer Maximum runtime for the request in milliseconds. |
Request Body schema: application/jsonrequired
token required | string The event source token determines:
|
cursor | string Cursor for a previous event. If provided, the event source replays any events that occurred after the cursor (exclusive). You can reuse cursors across event sources with identical queries in the same database. You can't pass both If you don't provide a |
start_ts | integer Stream start time in microseconds since the Unix epoch.
This is typically a previous event's You can't pass both If you don't provide a If |
page_size | integer Maximum number of events returned per page. Must be in the range 1 to 16000 (inclusive). Defaults to 16. |
Responses
Request samples
- Payload
- curl
{- "token": "<EVENT_SOURCE>",
- "cursor": "gsGabc123",
- "start_ts": 1710968002310000,
- "page_size": 10
}
Response samples
- 200
- 400
- 401
{- "events": [
- {
- "type": "update",
- "data": {
- "@doc": {
- "id": "412095363338469409",
- "coll": {
- "@mod": "Product"
}, - "ts": {
- "@time": "2099-10-18T21:54:07.340Z"
}, - "name": "cups",
- "description": "Translucent 9 Oz, 100 ct",
- "price": {
- "@int": "698"
}, - "stock": {
- "@int": "99"
}, - "category": {
- "@ref": {
- "id": "412095363334275105",
- "coll": {
- "@mod": "Category"
}
}
}
}
}, - "txn_ts": 1729288447340000,
- "cursor": "gsGCGmcS2P8aFEP9AAA=",
- "stats": {
- "read_ops": 1,
- "storage_bytes_read": 171,
- "compute_ops": 1,
- "processing_time_ms": 3,
- "rate_limits_hit": [ ]
}
}
], - "cursor": "gsGCGmcS2P8aFEP9AAA=",
- "has_next": false,
- "stats": {
- "read_ops": 9,
- "storage_bytes_read": 481,
- "compute_ops": 1,
- "processing_time_ms": 7,
- "rate_limits_hit": [ ]
}
}
Event Stream endpoint
Subscribe to real-time events from an event source. See Event Streams.
The Event Stream endpoint maintains an open connection and pushes events to the client as they occur.
Authorizations:
header Parameters
Authorization required | string Example: Bearer <FAUNA_SECRET> A Fauna authentication secret, passed as a bearer token. See Authentication for more details. |
X-Query-Timeout-Ms | integer Maximum runtime for the request in milliseconds. |
Request Body schema: application/jsonrequired
token required | string The event source token determines:
|
cursor | string Cursor for a previous event. If provided, the event source replays any events that occurred after the cursor (exclusive). You can reuse cursors across event sources with identical queries in the same database. You can't pass both If you don't provide a |
start_ts | integer Stream start time in microseconds since the Unix epoch.
This is typically a previous event's You can't pass both If you don't provide a For Event Streams, If |
Responses
Request samples
- Payload
- curl
{- "token": "<EVENT_SOURCE>",
- "cursor": "gsGabc123",
- "start_ts": 1710968002310000
}
Response samples
- 200
- 400
- 401
{- "type": "update",
- "data": {
- "@doc": {
- "id": "412095363338469409",
- "coll": {
- "@mod": "Product"
}, - "ts": {
- "@time": "2099-10-18T22:12:58.440Z"
}, - "name": "cups",
- "description": "Translucent 9 Oz, 100 ct",
- "price": {
- "@int": "698"
}, - "stock": {
- "@int": "100"
}, - "category": {
- "@ref": {
- "id": "412095363334275105",
- "coll": {
- "@mod": "Category"
}
}
}
}
}, - "txn_ts": 1729289578440000,
- "cursor": "gsGCGmcS3WoaGjneAAA=",
- "stats": {
- "read_ops": 1,
- "storage_bytes_read": 320,
- "compute_ops": 1,
- "processing_time_ms": 0,
- "rate_limits_hit": [ ]
}
}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!