Logs API
Search your tenant's execution log messages and read log sessions from code.
The Logs API reads your tenant's execution logs: the log messages that Agents, Actions, and Triggers write, and the log sessions that group them. The Console's log views use it, and the CLI's ctxl logs command uses it to search stored log messages. ctxl logs --follow instead shows new messages as they arrive, through the Notifications API. Use the Logs API from scripts and tools that need log data outside the Console. For example, a support script can find recent error messages and then read the other messages from the same session.
To search logs in the Console, see Logs.
What you can do
- Search log messages by level, time range, session, or other fields, or with a Contextual Log Query Language (CLQL) query.
- List log sessions and read one session. A session groups the messages from one run, such as one execution of an Action.
- Check the logs backlog, which is the number of log messages waiting to be stored. Administrators can also clear the backlog. Clearing it discards the waiting messages: they are never stored, so you can't search them. Not every tenant supports clearing. In a tenant that doesn't, the request returns
405.
The reference also lists operations that write and flush log sessions. Contextual services use the write operations to record logs from Agents, Actions, and Triggers.
The Observability API reference also lists POST /logs. That operation is not implemented and returns 501. Use the Logs API to read logs.
Base URL and reference
- API base URL:
https://logs.<tenant-id>.my.contextual.io/api/v1 - Swagger reference: Logs API reference
- Raw OpenAPI: openapi.json
Replace <tenant-id> with the tenant ID from your Tenant Workspace URL. On the API base URL, the hostname identifies your tenant, so the x-org-id header is optional. If you send it, its value must match the hostname.
The OpenAPI document uses the relative server /api/v1. When you import it into an API client or AI tool, set the server to the API base URL.
Authentication and permissions
See Authentication and Permissions for credential and token guidance. Send the access token in the Authorization: Bearer <access-token> header. A request without a valid token returns 401.
The Console and the CLI call this API with the signed-in person's token. The default Owner, Admin, and Logs Viewer roles let people view logs in the Console.
The backlog operations check for a log permission. A caller without it gets 403. In the default roles:
| Task | Default roles that allow it |
|---|---|
| View the logs backlog | Owner, Admin, and Logs Viewer |
| Clear the logs backlog | Owner and Admin |
Log messages can contain data that your solution processes. Give log access only to people and systems that need it.
Request and response details
GET /logstakes search parameters in the query string.POST /$page/logstakes the same parameters as top-level properties of a JSON body, with the same names, such as"exactSearch.level". Use it for long CLQL queries.- Filter log messages with these parameters:
exactSearch.<field>: one value or a comma-separated list. For example,exactSearch.level=error,fatal. Fields includelevel,sessionId,source,kind(trigger,action, orexecution), andsubKind.from.createdAtandto.createdAt: the start (inclusive) and end (exclusive) of a time range. Use an ISO 8601 UTC time, such as2026-10-27T00:00:00Z, or a relative time, such asnow-24h.search.query: a CLQL query.
- Lists return results in
items. To get the next page, send the response'snextPageTokenaspageToken, with the same filters andorderBy. Continue until a response has nonextPageToken. AnextPageTokendoes not mean that more results exist: the next page can be empty. - To page through log messages, set
orderBytocreatedAt:descorcreatedAt:asc. Without a sort, a log search returns anextPageTokenonly if the request also setsincludeTotal=true. - Send the filter parameters and
orderByunchanged. Use a plain HTTP request, as in the example request, or a client that supports these parameters. - Each message in search results has an
id,createdAt,level(fatal,error,warn,info, ordebug), andmessage. It also has fields from the session that wrote it, such assessionId,source,kind, andtypeId. Fields such assubKindandinstanceIdappear only when the writer sets them.messageis an object, and its content depends on the writer. Search results do not include a_metaDataobject. - Searches return only messages within your tenant's log retention period. See Logs.
- This API does not stream new messages. To watch logs as they arrive, use Live Tail in the Console.
- When you form a request, replace
[\$]in a reference path with a literal$. For example,/[\$]page/logsbecomes/$page/logs. In a shell command, put a URL that contains$pagein single quotes, or write\$page, so that the shell doesn't replace$pagewith a variable's value. - Requests can be rate limited for each caller. When a limit applies, responses include
RateLimitandRateLimit-Policyheaders, and a request over the limit returns429.
Example request
This request gets up to 50 error and fatal messages from the past 24 hours, newest first:
curl --get "https://logs.<tenant-id>.my.contextual.io/api/v1/logs" \
--header "Authorization: Bearer <access-token>" \
--data-urlencode "exactSearch.level=error,fatal" \
--data-urlencode "from.createdAt=now-24h" \
--data-urlencode "orderBy=createdAt:desc" \
--data-urlencode "pageSize=50"
Replace <access-token> with your access token. A successful response has status 200 and the matching messages in items.