/projects/{project_id}/branches/{branch_id}/logs/querybetaQuery branch logs
Returns logs emitted by services running on the specified branch,
ordered by timestamp according to sort_order.
All supplied filters are combined with AND: a record is returned only
when it matches every filter. minimum_severity and severity_text are
independent filters, so setting both requires a record to clear the
severity floor and match the exact severity text.
Supply logql instead of the structured filters to run a raw LogQL
expression. Combining it with any structured filter is rejected rather
than silently ignored; limit, sort_order, and the time window still
apply, because those bound the query rather than form part of the
expression.
Give the window either as since — a duration ending at end_time, or
at the current time when end_time is omitted — or as an explicit
start_time. Supplying both is rejected.
A single response holds at most 1,000 records. When is_truncated is
true, pass the returned next_cursor back as cursor to fetch the
next page, repeating the time range and every filter unchanged.
If no time range is supplied, the query covers the previous hour. The
maximum supported time range is seven days. end_time is exclusive.
Note: This endpoint is currently in Private Beta.
Quick start
curl "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches/$BRANCH_ID/logs/query" \
-X POST \
-H "Authorization: Bearer $NEON_API_KEY"import { createNeonClient, raw } from '@neon/sdk';
const neon = createNeonClient({ apiKey: process.env.NEON_API_KEY });
const { data } = await raw.queryProjectBranchLogs({
client: neon.client,
path: {
project_id: process.env.PROJECT_ID,
branch_id: process.env.BRANCH_ID
}
});Parameters
project_idThe Neon project ID
branch_idThe Neon branch ID
Request body
No field is required.
sinceA length of time as a count and a unit, for example 30m, 6h, or
7d. Valid units are ms, s, m, h, and d.
limitMaximum number of log records to return per page.
min: 1, max: 1000
cursorOpaque pagination cursor returned as next_cursor by a previous
call. Resume the query after the last record of the previous page,
repeating the time range and every filter unchanged.
sort_orderOrder matching records by timestamp. desc, the default, returns
the newest records first.
sourceThe Neon service that emitted the log record.
service_nameMatch the OpenTelemetry service.name resource attribute exactly.
≥1 chars
scope_nameMatch the OpenTelemetry instrumentation scope name exactly.
≥1 chars
minimum_severityAn OpenTelemetry severity level. A minimum severity includes every
higher level in this order: trace, debug, info, warn, error,
fatal.
severity_textMatch the OpenTelemetry severity text exactly.
≥1 chars
body_containsMatch records whose rendered message contains this case-sensitive
substring.
Records with a structured body are matched against their JSON
rendering, so the substring meets JSON syntax rather than prose: a
bare key name such as operation matches every record carrying that
key, and http_status: 200 matches none, because the rendering
contains "http_status":200 with no space.
≥1 chars
trace_idMatch records associated with this OpenTelemetry trace ID. W3C Trace Context defines a trace ID as 32 lowercase hex digits, and that is what is stored, so an uppercase value is rejected rather than silently matching nothing.
logqlEscape hatch for selections the structured filters cannot express: a raw LogQL expression, evaluated against this branch's log stream.
Only stream selectors and line filters are accepted — no
aggregations and no parser stages. Supplying this alongside any
structured filter is rejected with conflicting_filters rather than
silently ignoring one of them. limit, sort_order, and the time
window still apply.
This field passes the underlying query language through to the caller, so unlike the rest of this contract it may change as that backend changes. Prefer the structured filters where they suffice.
≥1 chars
start_timeInclusive beginning of the query window. Mutually exclusive with
since. Defaults to one hour before end_time, or one hour before
the current time when both bounds are omitted.
end_timeExclusive end of the query window. Defaults to the current time.
Response
200Logs matching the supplied filters
Errors
The query could not be served as written. The body is always
ProjectBranchLogsInvalidQuery — see reason for the exact cause.
Logs are not available for this branch, or the project/branch was
not found. The body is always ProjectBranchLogsNotAvailable — see
reason for the exact cause.
General error
This endpoint can return the standard Neon API error response.
Response fields
messageRequired. Human-readable error message.codeRequired. Machine-readable error code.request_idOptional. Request identifier for debugging. You can provide one with theX-Request-IDheader.
Retry guidance
If no response is returned, the request may still have reached the server. This is why retry safety depends on the method and status code.
Idempotent methods (GET, HEAD, OPTIONS) are generally safe to retry after a network error or timeout. Non-idempotent methods (POST, PATCH, DELETE, PUT) can change state, so avoid automatic retries unless your workflow can tolerate duplicate effects.
Responses with 423 Locked or 503 Service Unavailable are safe to retry. 423 Locked means the resource is temporarily locked, usually because another operation is in progress.








