Add files to your Postgres branches via Neon Object Storage, our S3-compatible object store
/APIs & SDKs/Logs/Query branch logs
POST/projects/{project_id}/branches/{branch_id}/logs/querybeta

Query 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.

Markdown for AI context

Quick start

REST API - curl
curl "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches/$BRANCH_ID/logs/query" \
  -X POST \
  -H "Authorization: Bearer $NEON_API_KEY"
Also available in
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 ID
project_id
string

The Neon project ID

Branch ID
branch_id
string

The Neon branch ID

Request body

No field is required.

Since
since
string

A length of time as a count and a unit, for example 30m, 6h, or 7d. Valid units are ms, s, m, h, and d.

Limit
limit
integerdefault: 100

Maximum number of log records to return per page.

min: 1, max: 1000

Cursor
cursor
string

Opaque 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 order
sort_order
stringdefault: desc

Order matching records by timestamp. desc, the default, returns the newest records first.

ascdesc
Source
source
string

The Neon service that emitted the log record.

functionstoragepg_endpoint
Service name
service_name
string

Match the OpenTelemetry service.name resource attribute exactly.

≥1 chars

Scope name
scope_name
string

Match the OpenTelemetry instrumentation scope name exactly.

≥1 chars

Minimum severity
minimum_severity
string

An OpenTelemetry severity level. A minimum severity includes every higher level in this order: trace, debug, info, warn, error, fatal.

tracedebuginfowarnerrorfatal
Severity text
severity_text
string

Match the OpenTelemetry severity text exactly.

≥1 chars

Body contains
body_contains
string

Match 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 ID
trace_id
string

Match 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.

Logql
logql
string

Escape 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 time
start_time
string

Inclusive 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 time
end_time
string

Exclusive end of the query window. Defaults to the current time.

Response

200

Logs matching the supplied filters

Depth
"is_truncated": (boolean),req
"next_cursor": (string),

Errors

400

The query could not be served as written. The body is always ProjectBranchLogsInvalidQuery — see reason for the exact cause.

404

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.

default

General error

This endpoint can return the standard Neon API error response.

Response fields

  • message Required. Human-readable error message.
  • code Required. Machine-readable error code.
  • request_id Optional. Request identifier for debugging. You can provide one with the X-Request-ID header.

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.

Was this page helpful?

On this page

Copy neon init command