# API reference

Base URL: `https://api.send2bucket.com`. Existing clients can continue using `api.s2b.tznc.dev`. gRPC: `api.send2bucket.com:443` over TLS and HTTP/2. Timestamps are ISO 8601 in UTC with microseconds. Stream and organization IDs are UUIDs.

## Authentication

Every ingestion request carries an API key. Keys look like `s2b_ingest_` followed by 32 base62 characters.

| Transport | How to send the key |
|---|---|
| HTTP | `Authorization: Bearer <key>` (preferred) or `x-api-key: <key>` |
| gRPC | metadata `authorization: Bearer <key>` |

A key writes to the one or more ingestion streams (streams for short) it was assigned when created, all in one organization. To change a key's streams, create a new key and revoke the old one. A stream delivers to one destination, which other streams of the organization can share, and accepts data as soon as it has one: the first successful delivery verifies a new or changed destination.

### Choosing the stream

A request for one stream names it in the `S2b-Stream` header (gRPC metadata `s2b-stream`) with the stream's ID. A key for a single stream can leave it out: the request goes to that stream. The [batch format](#batch-format) names a stream on each record instead.

| Status | `error` | gRPC status | Meaning |
|---|---|---|---|
| `400` | `stream_required` | `INVALID_ARGUMENT` (3) | The key writes to several streams and the request names none. |
| `403` | `stream_forbidden` | `PERMISSION_DENIED` (7) | The key cannot write to the named stream, or it does not exist. Includes `stream_id`. |

## `POST /v1/events`

Accepts one JSON object or a JSON array of objects, written to [one stream](#choosing-the-stream), or the [batch format](#batch-format) to write to several streams in one request.

| Header | Value |
|---|---|
| `Content-Type` | `application/json` |
| `Content-Encoding` | `gzip`, `deflate` (zlib-wrapped or raw), `zstd` or `identity` (the default) |
| `S2b-Stream` | The stream's ID. See [Choosing the stream](#choosing-the-stream). |

The request is accepted or rejected as a whole. When any item is invalid, nothing is stored and nothing is billed.

A `204 No Content`, with an empty body, means the batch is stored durably and will be delivered. Each item's JSON as stored is the number billed ([how bytes are counted](./plans-and-billing.md#how-bytes-are-counted)).

### Errors

Errors are JSON with an `error` code and, for some codes, more fields.

| Status | `error` | Meaning |
|---|---|---|
| `400` | `invalid_json` | The body is not valid JSON. |
| `400` | `invalid_item` | The body, or an array item, is not a JSON object. |
| `400` | `number_out_of_range` | A number has more than 34 significant digits or an exponent beyond ±6144 (IEEE 754 decimal128). |
| `400` | `invalid_encoding` | The body cannot be decoded with its `Content-Encoding`. |
| `401` | `unauthorized` | Missing, unknown or revoked API key. |
| `409` | `destination_not_ready` | The stream has no destination. |
| `413` | `body_too_large` | The decompressed body is larger than 8 MiB. Includes `max_bytes`. |
| `415` | `unsupported_encoding` | `Content-Encoding` is not `gzip`, `deflate`, `zstd` or `identity`. |
| `429` | `quota_exceeded` | The organization's plan allowance would be exceeded. |
| `503` | `buffer_full` | Send2Bucket is temporarily at capacity. `Retry-After: 30`. |
| `503` | `destination_backlog` | The stream's undelivered backlog is at its limit. `Retry-After: 30`. |

A `429` tells you what is left and when the allowance resets:

```json
{"error":"quota_exceeded","plan":"free","remaining_bytes":1824,"resets_at":"2026-12-01T00:00:00.000000Z"}
```

A smaller request can still fit in `remaining_bytes`. Otherwise wait until `resets_at` or change plan. A workspace without Free, the trial or a live subscription answers every request with `"plan":"inactive"`, `remaining_bytes` 0 and `resets_at` null.

### Batch format

A body that is an object with only a `batch` key uses the batch format: each record names its stream, and its `data` is one JSON object, as in a plain request. An object with `batch` and any other key is a plain event.

```json
{"batch":[
  {"stream_id":"3f6c2a9e-8b1d-4e7a-9c55-0d2b7e41a8f3","data":{"type":"click"}},
  {"stream_id":"3f6c2a9e-8b1d-4e7a-9c55-0d2b7e41a8f3","data":{"type":"view"}}
]}
```

Records are committed as one batch per stream, all or none, and the answer is a `204` with an empty body. The key must be able to write to every stream named. `S2b-Stream` is ignored.

The length of each record's `data` as stored, without the `batch` wrapper, is the number billed. Errors are those above, plus:

| Status | `error` | Meaning |
|---|---|---|
| `400` | `invalid_batch` | `batch` is not an array with at least one record, or a record lacks a string `stream_id` or a `data` field. |
| `400` | `invalid_item` | As above, with the record's `index`. |
| `403` | `stream_forbidden` | The key cannot write to `stream_id`. |
| `409` | `destination_not_ready` | As above, with the `stream_id`. |
| `503` | `destination_backlog` | As above, with the `stream_id`. `Retry-After: 30`. |

## Log drains

Receivers for platforms that push their logs to a URL. Pick the endpoint by what the platform sends. Each record becomes one `log` line, as described in [Delivery format](./delivery-format.md#log-drains); [Log drains](./guides/log-drains.md) has the setup for each platform. Supabase's log drains send OpenTelemetry, so they go to [`POST /v1/logs`](#otlp-http).

| Endpoint | Body | Platforms |
|---|---|---|
| `POST /v1/events/json` | A JSON array of objects, NDJSON (one object per line, blank lines skipped), or one JSON object, which may span lines. | Netlify, Auth0, Akamai DataStream 2, Cloudflare Logpush, Fastly, Vector, the Fly.io log shipper |
| `POST /v1/events/vercel` | As `/v1/events/json`. | Vercel |
| `POST /v1/events/heroku` | `application/logplex-1`: syslog messages framed by octet counting. | Heroku |
| `POST /v1/events/firehose` | An Amazon Data Firehose HTTP endpoint delivery: JSON with base64 `records`. | CloudWatch Logs, VPC Flow Logs, AWS WAF and other Firehose sources |
| `POST /v1/events/pubsub` | A Pub/Sub push: a wrapped message with base64 `data`, or the data alone. | Google Cloud Logging, through a Pub/Sub topic |
| `POST /v1/events/convex` | A JSON array of Convex log events. | Convex |

### Drain keys and streams

A drain request carries the API key in the first of these that is present:

| Where | For |
|---|---|
| `api-key` query parameter | Platforms that only take a URL: Pub/Sub push, Convex |
| `Authorization: Bearer <key>` or `x-api-key: <key>` | Platforms that send custom headers |
| The HTTP Basic auth password, any username: `https://x:<key>@api.send2bucket.com/…` | Heroku, Akamai |

`/v1/events/firehose` takes the key only from `X-Amz-Firehose-Access-Key`, the access key of the Firehose stream. The `api-key` parameter wins over `Authorization`, where Pub/Sub may send its own token. A key in a URL can end up in the platform's logs, so use a header where the platform offers one.

The stream is the `S2b-Stream` header, else the `stream` query parameter, else the key's only stream ([Choosing the stream](#choosing-the-stream)).

### Drain requests and replies

- `Content-Encoding` is as for [`/v1/events`](#post-events). A gzip body sent without `Content-Encoding` is detected and decompressed.
- A request is accepted or rejected as a whole. A `200 OK` with an empty body means the records are stored durably and will be delivered.
- Connection tests store nothing: a request with no records, one that is only Cloudflare's `{"content":"tests"}` or Akamai's `{"access_validation":true}`, Convex's `verification` event, and CloudWatch Logs control messages.
- `GET /.well-known/fastly/logging/challenge` answers `*`, so any Fastly service may stream to the host; the API key still authenticates each request.
- Each record's JSON as stored is the number billed.
- Errors are those of [`/v1/events`](#event-errors). When a record, or a Heroku message, is not a JSON object or cannot be parsed, `invalid_item` carries its `index`.

`/v1/events/firehose` follows Firehose's contract instead: every reply, errors included, is JSON `{"requestId":"…","timestamp":…}`, with `errorMessage` on errors. Firehose retries every status except `413`. Base64 makes a request about a third larger than its records, so set the stream's buffer size to 5 MiB or less to stay under the 8 MiB request limit.

## Datadog clients

Receivers for Datadog's Agent, tracers, the OpenTelemetry Collector's `datadog` exporter, Vector's Datadog sinks and the browser logs SDK, which take `https://api.send2bucket.com/v1/events/datadog` in place of Datadog's intake. [Datadog clients](./guides/datadog.md) has the setup for each, and [Delivery format](./delivery-format.md#datadog) the lines they produce. Paths below are relative to `/v1/events/datadog`.

| Endpoint | Body | Stored | Reply |
|---|---|---|---|
| `POST /api/v2/logs`, `POST /v1/input` | A JSON array of logs, one log, or NDJSON | One `log` per log | `202 {}` |
| `POST /browser?ddforward=…` | The browser SDK's `proxy` request | Logs only | `202 {}` |
| `POST /api/v1/series`, `POST /api/v1/distribution_points` | `{"series":[…]}` | One `metric` per series | `202 {"status":"ok"}` |
| `POST /api/v2/series` | `{"series":[…]}`, or a `MetricPayload` protobuf with `Content-Type: application/x-protobuf` | One `metric` per series | `202 {"errors":[]}` |
| `POST /api/beta/sketches` | A `SketchPayload` protobuf | One `metric` per sketch | `202 {}` |
| `PUT` or `POST /v0.4/traces`, `/v0.5/traces` | A tracer's msgpack payload | One `span` per span | `200 {"rate_by_service":{}}` |
| `POST /api/v0.2/traces` | An `AgentPayload` protobuf, including string-table tracer payloads | One `span` per span | `202 {}` |
| `GET /api/v1/validate` | | | `200 {"valid":true}`, or `403` |
| `GET /info` | | | The trace endpoints above, so tracers use them and nothing else |
| `POST /api/intake/metrics/…` | Series or sketches API v3 | Nothing | `400` |
| Any other `POST` | Host metadata, check runs, events, APM stats, profiles, tracer telemetry, RUM | Nothing | `202 {}` |

### Datadog keys and streams

The key is the first of these that is present:

| Where | For |
|---|---|
| `DD-API-KEY` header | The Agent, the `datadog` exporter, Vector |
| A path segment right after `/v1/events/datadog/` that starts with `s2b_ingest_` | Tracers, which drop the query string and send no key |
| `Authorization: Bearer <key>` or `x-api-key: <key>` | Any other client |

The key is never read from the query string, so a key sent only there gets a `403`, with two exceptions that follow the clients: `/api/v1/validate` also reads `api_key`, where the Agent sends it for its readiness check, and the browser proxy takes the key from the `dd-api-key` parameter inside `ddforward`.

:::warning
A key in a path segment ends up wherever the URL is logged. Use one only for tracers that cannot send through an Agent, with a key for one stream, and rotate it often; see [Tracers without an Agent](./guides/datadog.md#tracers-without-an-agent).
:::

The stream is a path segment with the stream's ID, after the key segment if there is one, else as for [log drains](#drain-keys): `S2b-Stream`, the `stream` query parameter, or the key's only stream.

### Datadog replies and errors

- A missing, unknown or revoked key is `403 {"errors":["Forbidden"]}`, as Datadog answers, which the Agent logs and does not retry.
- Other errors are those of [`/v1/events`](#event-errors). A protobuf or msgpack body that does not decode is `400` with `invalid_protobuf` or `invalid_msgpack`.
- An empty logs body, `{}` or a payload with no series or spans stores nothing.
- Each record's JSON as stored is the number billed, whatever the format.
- `/browser` answers `Access-Control-Allow-Origin: *`, so any page may post to it.

## Sentry SDKs

A Sentry DSN of `https://<key>@api.send2bucket.com/v1/events/sentry/<stream_id>/1` makes a Sentry SDK send its envelopes here; leave out `<stream_id>/` for a key with one stream. [Sentry SDKs](./guides/sentry.md) has the setup, and [Delivery format](./delivery-format.md#sentry) the lines. Paths are relative to `/v1/events/sentry/<stream_id>`, and `<project>` is the DSN's last segment, which is ignored.

| Endpoint | Body | Stored |
|---|---|---|
| `POST /api/<project>/envelope/` | A Sentry envelope: a header line, then items, each an item header and a payload | One line per item, or per entry of a log, span or metric container |
| `POST /api/<project>/store/` | One event, as JSON or base64 JSON, as older SDKs send | One `event` line |
| `POST /api/<project>/integration/otlp/v1/traces`, `…/logs` | OTLP/HTTP, as for [`/v1/traces` and `/v1/logs`](#otlp-http) | OpenTelemetry records |
| `OPTIONS` on the envelope path | A browser's CORS preflight | Nothing |

The key is the DSN's public key, from the first of: `X-Sentry-Auth` or `Authorization: Sentry …` (`sentry_key=<key>`), the `sentry_key` query parameter that browser SDKs send, or the envelope header's `dsn`. The `dsn` is not stored.

### Sentry replies and errors

- `200` with `{"id":"<event_id>"}` when the envelope has an `event_id`, else `{}`. An envelope with no items stores nothing.
- Errors are `{"detail":"…"}` with the same text in `X-Sentry-Error`: `400` for an envelope that does not parse, `401` for a missing or wrong key, and the statuses of [`/v1/events`](#event-errors) for the rest.
- Over quota, the `429` carries `Retry-After` and `X-Sentry-Rate-Limits`, so SDKs stop sending until then.
- Every reply allows any origin and exposes `X-Sentry-Error`, `X-Sentry-Rate-Limits` and `Retry-After` to browser SDKs.
- `Content-Encoding` is `gzip` or `identity`; Brotli gets a `415`. Each record's `data` as stored, with its envelope and item headers, is the number billed.

## PostHog SDKs

A PostHog SDK whose host, `api_host` in the browser, is `https://api.send2bucket.com/v1/events/posthog` sends its events here, with the API key as its project token. [PostHog SDKs](./guides/posthog.md) has the setup, and [Delivery format](./delivery-format.md#posthog) the lines. Paths are relative to that host.

| Endpoint | Body | Reply |
|---|---|---|
| `POST /e/`, `/i/v0/e/`, `/batch/`, `/capture/`, `/track/`, `/engage/` | One event, an array, or `{"batch":[…]}`: JSON, gzip, base64, or a form's `data` field | `200 {"status":1}` |
| `POST /i/v1/analytics/events`, `/i/v1/ai/events` | Capture v1: `{"batch":[…]}`, with `Authorization: Bearer <key>` | `200 {"results":{"<uuid>":{"result":"ok"}}}` |
| `POST /s/` | Session recording snapshots, as for `/e/` | `200 {"status":1}` |
| `POST /flags/`, `/decide/` | | `200` with no flags |
| `GET /array/<key>/config` | | Remote config with everything off, or recordings on under `/recordings` |

The key is the `api_key`, `token` or `$token` of the batch or of its first event, or the event's `properties.token`, else `Authorization: Bearer <key>`. It is removed from the events before they are stored. The stream is a path segment with the stream's ID right after `/v1/events/posthog/`, else the key's only stream. A `recordings` segment, after the stream if any, turns session recording on in remote config.

### PostHog replies and errors

- Errors are those of [`/v1/events`](#event-errors). A body compressed with `lz64` gets a `415`.
- When the stream's allowance is spent, capture answers `200` with `quota_limited` (`["events"]`, or `["recordings"]` for `/s/`), as PostHog does. Capture v1 answers `402`, which v1 SDKs do not retry.
- Replies allow the request's origin with credentials, as PostHog's do, so posthog-js can send from any site.
- `Content-Encoding` is `gzip` or `identity`. Each event's JSON as stored is the number billed.

## OTLP/HTTP

| Signal | Endpoint |
|---|---|
| Logs | `POST /v1/logs` |
| Traces | `POST /v1/traces` |
| Metrics | `POST /v1/metrics` |

Send an `ExportLogsServiceRequest`, `ExportTraceServiceRequest` or `ExportMetricsServiceRequest`, and the stream in `S2b-Stream` ([Choosing the stream](#choosing-the-stream)). `Content-Encoding` is as for [`/v1/events`](#post-events). Either encoding works:

| `Content-Type` | Encoding |
|---|---|
| `application/x-protobuf` | Binary protobuf (`http/protobuf`). |
| `application/json` | The [OTLP JSON encoding](https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding) (`http/json`): hex trace and span IDs, 64-bit integers as strings or numbers. Unknown fields are ignored. |

The reply, errors included, uses the request's encoding. A JSON request is stored and billed exactly as its protobuf form would be, so the encoding does not change usage.

A `200` carries the matching `Export*ServiceResponse`, `{}` in JSON when nothing was rejected. A span or log record with a malformed trace ID or span ID is rejected permanently and reported in its `partial_success`, while the rest of the request is accepted. `rejected_log_records` and `rejected_spans` count those items, and `error_message` says why. Metrics are not rejected.

Errors use the same HTTP status codes as `/v1/events` (`400`, `401`, `403`, `409`, `413` above 8 MiB decompressed, `415` for any other `Content-Type`, `429`, `503` with `Retry-After`), with a `google.rpc.Status` body in the request's encoding. Standard OTLP exporters retry `429` and `503`.

## OTLP/gRPC

Send2Bucket serves the `Export` RPCs of `opentelemetry.proto.collector.logs.v1.LogsService`, `opentelemetry.proto.collector.trace.v1.TraceService` and `opentelemetry.proto.collector.metrics.v1.MetricsService` at `api.send2bucket.com:443`, with the stream in `s2b-stream` metadata. Limits and `partial_success` match OTLP/HTTP.

| gRPC status | Meaning |
|---|---|
| `OK` (0) | Accepted, with `partial_success` for rejected items. |
| `INVALID_ARGUMENT` (3) | The message cannot be decoded, or the key writes to several streams and no `s2b-stream` is given. |
| `PERMISSION_DENIED` (7) | The key cannot write to the `s2b-stream` named. |
| `RESOURCE_EXHAUSTED` (8) | Quota exceeded, or the request is larger than 8 MiB. |
| `FAILED_PRECONDITION` (9) | The stream has no destination. |
| `UNAVAILABLE` (14) | Send2Bucket or the stream's backlog is at capacity. Retryable. |
| `UNAUTHENTICATED` (16) | Missing, unknown or revoked API key. |

## Prometheus remote write

`POST /api/v1/write`, also served at `POST /v1/prometheus/write`, takes [remote write 1.0](https://prometheus.io/docs/specs/prw/remote_write_spec/) and [2.0](https://prometheus.io/docs/specs/prw/remote_write_spec_2_0/) with `Content-Encoding: snappy`:

| Version | `Content-Type` | Body |
|---|---|---|
| 1.0 | `application/x-protobuf` | `prometheus.WriteRequest` |
| 2.0 | `application/x-protobuf;proto=io.prometheus.write.v2.Request` | `io.prometheus.write.v2.Request` |

Name the stream in `S2b-Stream` ([Choosing the stream](#choosing-the-stream)). In Prometheus, `protobuf_message` picks 2.0; leave it out for 1.0:

```yaml
remote_write:
  - url: https://api.send2bucket.com/api/v1/write
    authorization:
      credentials: <key>
    headers:
      S2b-Stream: <stream_id>
    protobuf_message: io.prometheus.write.v2.Request
```

Each time series becomes one line with `signal` `series` ([Delivery format](./delivery-format.md#prometheus-series)). 2.0 lines also carry the series' metric type, help and unit, and sample start timestamps; 1.0 sends metadata separately, and it is not stored.

| Status | Meaning |
|---|---|
| `204` | Every series was stored. |
| `400` | Some series were rejected after the rest were stored, and the body names the reasons. Also returned for a body that is not a snappy-compressed request, or that has a label that is not UTF-8. |
| `415` | Another content type or encoding. `Accept` and `Accept-Encoding` list the supported ones. |

A series is rejected when a label name is empty or repeated, or, in 2.0, when it references a symbol that does not exist. Series have no size limit of their own. Senders do not retry a `400`, so the stored series are not sent twice.

2.0 responses carry `X-Prometheus-Remote-Write-Samples-Written`, `X-Prometheus-Remote-Write-Histograms-Written` and `X-Prometheus-Remote-Write-Exemplars-Written`: what was stored, `0` on errors.

Other errors use the same HTTP status codes as `/v1/events` (`401`, `403`, `409`, `413` above 8 MiB decompressed, `429`, `503` with `Retry-After`), with a plain-text body. Remote write senders retry `5xx`; retrying `429` is up to the sender.

## Retries

Send2Bucket does not deduplicate requests. A retry after a timeout or a lost response is a new batch: its records are stored and billed again. See [Delivery semantics](./delivery-semantics.md).

## Limits

| Limit | Value |
|---|---|
| Request body | 8 MiB after decompression, for JSON, log drains, Datadog clients, OTLP and remote write; items have no separate limit |
| Destinations per stream | 1 |
