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

# Event Ingestion

> Send usage events from your application to track customer consumption and power billing.

Events are the foundation of usage-based billing. Send events when billable actions occur, and meters aggregate them into charges.

<Card title="API Reference - Events Ingestion" icon="code" href="/api-reference/usage-events/ingest-events">
  Complete API documentation with examples and response codes.
</Card>

## Event Structure

<Accordion title="Required Fields">
  <ParamField body="event_id" type="string" required>
    Unique identifier. Use UUIDs or combine customer ID + timestamp + action.
  </ParamField>

  <ParamField body="customer_id" type="string" required>
    Dodo Payments customer ID. Must be a valid existing customer.
  </ParamField>

  <ParamField body="event_name" type="string" required>
    Event type that matches your meter's event name (case-sensitive). Examples: `api.call`, `image.generated`
  </ParamField>
</Accordion>

<Accordion title="Optional Fields">
  <ParamField body="timestamp" type="string">
    ISO 8601 timestamp. Defaults to server time if omitted. Include for accurate billing with delayed/batch events.
  </ParamField>

  <ParamField body="metadata" type="object">
    Additional properties for aggregation and filtering:

    * Numeric values: `bytes`, `tokens`, `duration_ms`
    * Filters: `endpoint`, `method`, `quality`

    ```javascript theme={null}
    metadata: {
      endpoint: "/v1/orders",
      method: "POST",
      tokens: 1024
    }
    ```
  </ParamField>
</Accordion>

## Sending Events

<CodeGroup>
  ```javascript Single Event theme={null}
  await fetch('https://test.dodopayments.com/events/ingest', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.DODO_PAYMENTS_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      events: [{
        event_id: "api_call_1234",
        customer_id: "cus_abc123",
        event_name: "api.call",
        metadata: { endpoint: "/v1/orders" }
      }]
    })
  });
  ```

  ```javascript Batch Events theme={null}
  await fetch('https://test.dodopayments.com/events/ingest', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.DODO_PAYMENTS_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      events: [
        { event_id: "call_1", customer_id: "cus_abc", event_name: "api.call" },
        { event_id: "call_2", customer_id: "cus_abc", event_name: "api.call" },
        { event_id: "call_3", customer_id: "cus_abc", event_name: "api.call" }
      ]
    })
  });
  ```

  ```python Python theme={null}
  import requests

  requests.post(
      'https://test.dodopayments.com/events/ingest',
      headers={'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'},
      json={'events': [{'event_id': 'call_1', 'customer_id': 'cus_abc', 'event_name': 'api.call'}]}
  )
  ```

  ```curl cURL theme={null}
  curl -X POST 'https://test.dodopayments.com/events/ingest' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{"events": [{"event_id": "call_1", "customer_id": "cus_abc", "event_name": "api.call"}]}'
  ```
</CodeGroup>

<Tip>
  Batch up to 1,000 events per request for better performance. The API enforces a hard limit of 1,000 events per call.
</Tip>

## Ingestion Blueprints

Ready-made event patterns for common use cases. Start with a proven blueprint instead of building from scratch.

<CardGroup cols={2}>
  <Card title="LLM Blueprint" icon="brain-circuit" href="/developer-resources/ingestion-blueprints/llm">
    Track AI token usage across OpenAI, Anthropic, Groq, Gemini, and more.
  </Card>

  <Card title="API Gateway Blueprint" icon="cloud" href="/developer-resources/ingestion-blueprints/api-gateway">
    Meter API requests with endpoint filtering and rate limiting support.
  </Card>

  <Card title="Object Storage Blueprint" icon="box-archive" href="/developer-resources/ingestion-blueprints/object-storage">
    Track file uploads and storage consumption for cloud storage services.
  </Card>

  <Card title="Stream Blueprint" icon="tower-broadcast" href="/developer-resources/ingestion-blueprints/stream">
    Measure streaming bandwidth for video, audio, and real-time data.
  </Card>

  <Card title="Time Range Blueprint" icon="clock" href="/developer-resources/ingestion-blueprints/time-range">
    Bill by elapsed time for serverless functions and compute instances.
  </Card>

  <Card title="View All Blueprints" icon="copy" href="/features/usage-based-billing/ingestion-blueprints">
    See all available blueprints with detailed implementation guides.
  </Card>
</CardGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Use Unique Event IDs">
    Use deterministic IDs to prevent duplicates: `${customerId}_${action}_${timestamp}`
  </Accordion>

  <Accordion title="Implement Retries">
    Retry on 5xx errors with exponential backoff. Don't retry 4xx errors.
  </Accordion>

  <Accordion title="Include Timestamps">
    Omit for real-time events. Include for delayed/batch events for accuracy.
  </Accordion>

  <Accordion title="Monitor Delivery">
    Track success rates and queue failed events for retry.
  </Accordion>
</AccordionGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Events not appearing">
    * Event name must exactly match meter (case-sensitive)
    * Customer ID must exist
    * Check meter filters aren't excluding events
    * Verify timestamps are recent
  </Accordion>

  <Accordion title="Authentication errors (401)">
    Verify API key is correct and use format: `Bearer YOUR_API_KEY`
  </Accordion>

  <Accordion title="Validation errors (400)">
    Ensure all required fields are present: `event_id`, `customer_id`, `event_name`
  </Accordion>

  <Accordion title="Metadata not aggregating">
    * Metadata keys must match meter's "Over Property" exactly
    * Use numbers, not strings: `tokens: 150` not `tokens: "150"`
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Create Meters" icon="sliders" href="/features/usage-based-billing/meters">
    Define how your events are aggregated into billable quantities with filters and aggregation functions.
  </Card>

  <Card title="Ingestion Blueprints" icon="copy" href="/features/usage-based-billing/ingestion-blueprints">
    Use ready-made blueprints for common use cases like LLM tracking, API gateways, and storage.
  </Card>

  <Card title="Complete Tutorial" icon="code" href="/developer-resources/usage-based-billing-build-ai-image-generator">
    Build a full AI image generator with usage-based billing from scratch.
  </Card>

  <Card title="API Reference" icon="terminal" href="/api-reference/usage-events/ingest-events">
    Complete API documentation with all parameters, response codes, and interactive testing.
  </Card>
</CardGroup>
