# Send Vercel log drains to S3 or your own bucket

Vercel keeps [runtime logs](https://vercel.com/docs/logs/runtime) for a limited time that depends on the plan. A drain sends every log line to Send2Bucket as it is written, and Send2Bucket delivers the lines to a bucket or table you own, for as long as you keep them.

:::note
We sent requests shaped like the documented [Vercel log drain payload](https://vercel.com/docs/drains/reference/logs) to a local Send2Bucket node writing to S3-compatible storage, and ran the check request and the DuckDB queries (DuckDB 2.0) on the objects it wrote. The Vercel dashboard steps follow [Using Drains](https://vercel.com/docs/drains/using-drains) and were not run against Vercel.
:::

## How it works

```text
Vercel ──JSON or NDJSON──▶ /v1/events/vercel ──▶ your stream's destination
```

- Each log line becomes one record with `signal` `log`, kept as Vercel sent it: `id`, `source`, `level`, `message`, `path`, `statusCode`, the `proxy` object and the rest. [Delivery format](../delivery-format.md#log-drains) describes the line.
- A `200` means the records are stored durably and will be delivered at least once. See [Delivery semantics](../delivery-semantics.md).
- Drains need a Vercel Pro or Enterprise plan, and Vercel bills drained data by the GB.

## 1. Create a stream and a key

Create an ingestion stream in the [dashboard](pathname:///app/), add a destination, and copy the stream's API key and ID. A key for one stream needs no stream ID in the drain.

## 2. Add the drain

Vercel drains can send custom headers, so the key goes in `Authorization`.

1. In your Vercel team's settings, open **Drains** and add a drain with the **Logs** data type and a custom endpoint.
2. Endpoint: `https://api.send2bucket.com/v1/events/vercel`. Either format, JSON or NDJSON, works.
3. Custom headers, one per line:

   ```text
   Authorization: Bearer <key>
   S2b-Stream: <stream_id>
   ```

   Leave out `S2b-Stream` if the key writes to one stream.

Vercel tests the endpoint when you save the drain; the test needs the key to be valid. Send2Bucket does not check `x-vercel-signature`, so the key header is what authenticates the drain.

## 3. Check the endpoint

Before Vercel sends anything, check the key and stream with one request. It stores one record, and the answer is a `200` with an empty body:

```bash
curl -i https://api.send2bucket.com/v1/events/vercel \
  -H "Authorization: Bearer $S2B_API_KEY" \
  -H "S2b-Stream: <stream_id>" \
  --data-binary '{"id":"check","level":"info","message":"hello from curl"}'
```

A `401` means the key is wrong or revoked; a `403` or `400` names the stream problem; a `409` means the stream has no destination. The [API reference](../api-reference.md#log-drains) lists every error.

## 4. Query the logs

[DuckDB](../querying/duckdb.md) reads the objects in place. This view keeps the drained logs:

```sql
INSTALL httpfs; LOAD httpfs;
CREATE SECRET s2b (TYPE s3, PROVIDER credential_chain, REGION '<region>');

CREATE VIEW drains AS
SELECT * FROM read_json(
  's3://<bucket>/<prefix>/s2b/stream=*/date=*/hour=*/*.ndjson.gz',
  format = 'newline_delimited',
  hive_partitioning = true,
  columns = {v: 'INTEGER', delivery_batch_id: 'VARCHAR', batch_id: 'VARCHAR',
             received_at: 'TIMESTAMPTZ', signal: 'VARCHAR',
             resource: 'JSON', scope: 'JSON', data: 'JSON'})
WHERE signal = 'log';
```

Errors by source and path:

```sql
SELECT data->>'$.source' AS source, data->>'$.path' AS path, count(*) AS errors
FROM drains
WHERE data->>'$.level' IN ('error', 'fatal')
GROUP BY ALL
ORDER BY errors DESC;
```

Paths that answered with a server error. `proxy.statusCode` is the status of the request Vercel served; build logs have no `proxy`, and background regeneration reports `-1`:

```sql
SELECT data->>'$.proxy.path' AS path,
       (data->>'$.proxy.statusCode')::INTEGER AS status,
       count(*) AS requests
FROM drains
WHERE (data->>'$.proxy.statusCode')::INTEGER >= 500
GROUP BY ALL
ORDER BY requests DESC;
```

Function invocations that crashed without a response have `statusCode` `-1`:

```sql
SELECT received_at, data->>'$.path' AS path, data->>'$.message' AS message
FROM drains
WHERE data->>'$.source' = 'lambda' AND (data->>'$.statusCode')::INTEGER = -1
ORDER BY received_at DESC
LIMIT 20;
```

In an Iceberg or DuckLake table, the same line is in the `payload` column with `signal_type` `log`; see [Table columns](../delivery-format.md#table-columns).

## Notes

- **Size**: Vercel sends up to 1 MB per request; a request can be up to 8 MiB decompressed.
- **Billing**: each record's JSON as stored is the number billed. See [Plans and billing](../plans-and-billing.md).
- **Retries**: Vercel's retries are not deduplicated. To drop repeats, key on Vercel's `id` in your query. See [Retries](../api-reference.md#retries).
- **Other platforms**: [Log drains](./log-drains.md) covers Heroku, Supabase, Netlify, Cloudflare, Fastly and others.
