> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flexprice.io/llms.txt
> Use this file to discover all available pages before exploring further.

# High-Volume Ingestion

> Batch usage events with the bulk endpoint, the SDKs, or the Flexprice Collector, and keep a high-volume sender stable under load

One request per usage event works while volume is low. Once you send more than a few events per second, batch them: fewer requests, less overhead per event, and one retry covers many events. This page covers high-volume ingestion through the bulk endpoint, the SDKs, and the Flexprice Collector, and how to keep a sender stable when the network or Flexprice slows down.

## Batching usage events with the bulk endpoint

`POST /v1/events/bulk` takes the same event fields as a single event, in an `events` array:

* **Batch size:** 1 to 1000 events per request.
* **Body size:** up to 32 MiB. A larger body fails with `400` and the message "Request body exceeds the maximum size; split the batch into smaller requests".
* **Flush policy:** send a batch when it reaches 1000 events or after a fixed interval, such as one or two seconds, whichever comes first, so a quiet period doesn't hold events back.

### Recovering failed bulk requests

* **Invalid JSON, a timestamp that isn't RFC 3339, more than 1000 events, or an oversized body** reject the whole request before any event in it is accepted.
* **A missing `event_name` or `external_customer_id`, or a message that exceeds the message size limit,** can return `400` after other events in the array were accepted.

If the request failed before processing, fix it and resend. If the batch may have been partly accepted, resend each event that had an `event_id` and `timestamp` in the original request, with both values unchanged: a copy Flexprice already accepted is deduplicated. Correct missing required fields before resending.

If the `400` says `Event exceeds the maximum allowed message size`, split the events that had an `event_id` and `timestamp` into smaller requests and resend them with both original values. The response doesn't identify which events failed. If an event still returns the size error on its own, reduce its payload and resend it with those same values.

An event originally sent without an `event_id` or `timestamp` can't be deduplicated: resend it only if you can confirm it was never accepted. An event missing from the [Event Debugger](https://docs.flexprice.io/docs/event-ingestion/event-debugger.md) may still be processing. See [Idempotency and Deduplication](https://docs.flexprice.io/docs/event-ingestion/idempotency.md#resending-a-failed-bulk-request) for how to handle network errors, timeouts, and `5xx` responses.

## Batching usage events with the SDKs

Every SDK has a bulk method. Collect events in your worker and send them in one call:

```go Go theme={null}
resp, err := client.Events.IngestEventsBulk(ctx, types.BulkIngestEventRequest{
	Events: []types.IngestEventRequest{
		{
			EventName:          "api_request",
			ExternalCustomerID: "cust_123",
			EventID:            flexprice.String("req_9f3c"),
			Timestamp:          flexprice.String("2026-10-10T14:03:00Z"),
			Properties:         map[string]string{"bytes": "1024"},
		},
		{
			EventName:          "api_request",
			ExternalCustomerID: "cust_123",
			EventID:            flexprice.String("req_9f3d"),
			Timestamp:          flexprice.String("2026-10-10T14:03:05Z"),
			Properties:         map[string]string{"bytes": "2048"},
		},
	},
})
```

```python Python theme={null}
result = client.events.ingest_events_bulk(
    events=[
        {
            "event_name": "api_request",
            "external_customer_id": "cust_123",
            "event_id": "req_9f3c",
            "timestamp": "2026-10-10T14:03:00Z",
            "properties": {"bytes": "1024"},
        },
        {
            "event_name": "api_request",
            "external_customer_id": "cust_123",
            "event_id": "req_9f3d",
            "timestamp": "2026-10-10T14:03:05Z",
            "properties": {"bytes": "2048"},
        },
    ],
)
```

```typescript TypeScript theme={null}
const result = await flexprice.events.ingestEventsBulk({
  events: [
    {
      eventName: "api_request",
      externalCustomerId: "cust_123",
      eventId: "req_9f3c",
      timestamp: "2026-10-10T14:03:00Z",
      properties: { bytes: "1024" },
    },
    {
      eventName: "api_request",
      externalCustomerId: "cust_123",
      eventId: "req_9f3d",
      timestamp: "2026-10-10T14:03:05Z",
      properties: { bytes: "2048" },
    },
  ],
});
```

Retries are off by default in every SDK. Once every event carries an `event_id` and `timestamp`, enable retries when you create the client. See [Retrying failed SDK requests](https://docs.flexprice.io/developers/sdks/usage.md#retrying-failed-sdk-requests).

### How the Go SDK async client sends usage events

The Go SDK also has an async client (`client.NewAsyncClientWithConfig`) that queues events in process memory and sends them from background goroutines. Know how it delivers before you bill on it:

* It sends each event as its own `POST /v1/events` request, not through the bulk endpoint.
* It doesn't set an `event_id`. Pass your own with `EnqueueWithOptions`, or a resent event can't be recognized as a copy. When you leave out the timestamp, it stamps the event at enqueue time.
* An event whose send fails is dropped once the retries configured on the parent client (`WithRetryConfig`) run out. The failure is printed only when `Debug` is on.
* `Close()` returns without waiting for queued events to be sent, so events still in memory when the process exits can be lost.
* `Enqueue` blocks while the queue is full (`MaxQueueSize`, 1000 by default).

For usage you bill on, keep events on a durable queue and send them with `IngestEventsBulk` instead.

## Streaming usage events with the Flexprice Collector

If your usage already flows through Kafka or another stream, run the [Flexprice Collector](https://docs.flexprice.io/docs/collectors/overview) instead of writing a sender. It reads from the stream, transforms each message into a Flexprice event, batches events (10 events or 2 seconds by default), and retries failed requests with exponential backoff. To install it, see [Get Started](https://docs.flexprice.io/docs/collectors/get-started.md).

## Keeping a high-volume sender stable

* **Cap concurrency.** Send from a fixed pool of workers, each with one request in flight, instead of opening a request per event.
* **Back off on failure.** When every event had an `event_id` and `timestamp` in the original request, retry network errors, timeouts, and `5xx` responses with exponential backoff and jitter so that many workers don't retry in lockstep.
* **Let the queue absorb outages.** Keep events on a durable queue until Flexprice accepts them, size it for the longest outage you want to ride out, and alert on the age of the oldest event in it.
* **Watch processing lag.** A `202` means Flexprice accepted the events; metering runs asynchronously behind it. The [Event Monitoring](https://docs.flexprice.io/docs/event-ingestion/monitoring.md) endpoint returns `consumption_lag`, the number of accepted events still waiting to be processed in your environment.

> [card] [Send Usage Events with the API and SDKs](https://docs.flexprice.io/docs/event-ingestion/sending-events.md)
>
> Authentication, single and bulk requests, and the responses to handle.

> [card] [Backfill Past Usage](https://docs.flexprice.io/docs/event-ingestion/backfill.md)
>
> Load historical usage and get it onto draft or finalized invoices.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.