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

# Ingest Events

> Ingest events for usage-based billing.



## OpenAPI

````yaml post /events/ingest
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.102.0
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
paths:
  /events/ingest:
    post:
      tags:
        - Events
      summary: Ingest events for usage-based billing and analytics
      description: >-
        This endpoint allows you to ingest custom events that can be used for:

        - Usage-based billing and metering

        - Analytics and reporting

        - Customer behavior tracking


        ## Important Notes:

        - **Duplicate Prevention**:
          - Duplicate `event_id` values within the same request are rejected (entire request fails)
          - Subsequent requests with existing `event_id` values are ignored (idempotent behavior)
        - **Rate Limiting**: Maximum 1000 events per request

        - **Time Validation**: Events with timestamps older than 1 hour or more
        than 5 minutes in the future will be rejected

        - **Metadata Limits**: Maximum 50 key-value pairs per event, keys max
        100 chars, values max 500 chars


        ## Example Usage:

        ```json

        {
          "events": [
            {
              "event_id": "api_call_12345",
              "customer_id": "cus_abc123",
              "event_name": "api_request",
              "timestamp": "2024-01-15T10:30:00Z",
              "metadata": {
                "endpoint": "/api/v1/users",
                "method": "GET",
                "tokens_used": "150"
              }
            }
          ]
        }

        ```
      operationId: ingest_events
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IngestEventsRequest'
        required: true
      responses:
        '200':
          description: Events ingested successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IngestEventsResponse'
        '400':
          description: >-
            Invalid request - validation errors, duplicate event IDs, or invalid
            timestamps
        '401':
          description: Unauthorized - invalid or missing API key
        '413':
          description: Payload too large - request exceeds maximum allowed size
        '422':
          description: Unprocessable entity - malformed JSON or schema validation errors
        '429':
          description: Too many requests - rate limit exceeded
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import DodoPayments from 'dodopayments';

            const client = new DodoPayments({
              bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.usageEvents.ingest({
              events: [
                {
                  customer_id: 'customer_id',
                  event_id: 'event_id',
                  event_name: 'event_name',
                },
              ],
            });

            console.log(response.ingested_count);
        - lang: Python
          source: |-
            import os
            from dodopayments import DodoPayments

            client = DodoPayments(
                bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
            )
            response = client.usage_events.ingest(
                events=[{
                    "customer_id": "customer_id",
                    "event_id": "event_id",
                    "event_name": "event_name",
                }],
            )
            print(response.ingested_count)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tresponse, err := client.UsageEvents.Ingest(context.TODO(), dodopayments.UsageEventIngestParams{\n\t\tEvents: dodopayments.F([]dodopayments.EventInputParam{{\n\t\t\tCustomerID: dodopayments.F(\"customer_id\"),\n\t\t\tEventID:    dodopayments.F(\"event_id\"),\n\t\t\tEventName:  dodopayments.F(\"event_name\"),\n\t\t}}),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.IngestedCount)\n}\n"
        - lang: Java
          source: >-
            package com.dodopayments.api.example;


            import com.dodopayments.api.client.DodoPaymentsClient;

            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;

            import com.dodopayments.api.models.usageevents.EventInput;

            import
            com.dodopayments.api.models.usageevents.UsageEventIngestParams;

            import
            com.dodopayments.api.models.usageevents.UsageEventIngestResponse;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

                    UsageEventIngestParams params = UsageEventIngestParams.builder()
                        .addEvent(EventInput.builder()
                            .customerId("customer_id")
                            .eventId("event_id")
                            .eventName("event_name")
                            .build())
                        .build();
                    UsageEventIngestResponse response = client.usageEvents().ingest(params);
                }
            }
        - lang: Kotlin
          source: >-
            package com.dodopayments.api.example


            import com.dodopayments.api.client.DodoPaymentsClient

            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient

            import com.dodopayments.api.models.usageevents.EventInput

            import
            com.dodopayments.api.models.usageevents.UsageEventIngestParams

            import
            com.dodopayments.api.models.usageevents.UsageEventIngestResponse


            fun main() {
                val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

                val params: UsageEventIngestParams = UsageEventIngestParams.builder()
                    .addEvent(EventInput.builder()
                        .customerId("customer_id")
                        .eventId("event_id")
                        .eventName("event_name")
                        .build())
                    .build()
                val response: UsageEventIngestResponse = client.usageEvents().ingest(params)
            }
        - lang: Ruby
          source: |-
            require "dodopayments"

            dodo_payments = Dodopayments::Client.new(
              bearer_token: "My Bearer Token",
              environment: "test_mode" # defaults to "live_mode"
            )

            response = dodo_payments.usage_events.ingest(
              events: [{customer_id: "customer_id", event_id: "event_id", event_name: "event_name"}]
            )

            puts(response)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Dodopayments\Client;
            use Dodopayments\Core\Exceptions\APIException;

            $client = new Client(
              bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
              environment: 'test_mode',
            );

            try {
              $response = $client->usageEvents->ingest(
                events: [
                  [
                    'customerID' => 'customer_id',
                    'eventID' => 'event_id',
                    'eventName' => 'event_name',
                    'metadata' => ['foo' => 'string'],
                    'timestamp' => new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                  ],
                ],
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using System.Collections.Generic;
            using DodoPayments.Client;
            using DodoPayments.Client.Models.UsageEvents;

            DodoPaymentsClient client = new();

            UsageEventIngestParams parameters = new()
            {
                Events =
                [
                    new()
                    {
                        CustomerID = "customer_id",
                        EventID = "event_id",
                        EventName = "event_name",
                        Metadata = new Dictionary<string, EventInputMetadata>()
                        {
                            { "foo", "string" }
                        },
                        Timestamp = DateTimeOffset.Parse("2019-12-27T18:11:19.117Z"),
                    },
                ],
            };

            var response = await client.UsageEvents.Ingest(parameters);

            Console.WriteLine(response);
components:
  schemas:
    IngestEventsRequest:
      type: object
      required:
        - events
      properties:
        events:
          type: array
          items:
            $ref: '#/components/schemas/EventInput'
          description: List of events to be pushed
          maxItems: 1000
          minItems: 1
    IngestEventsResponse:
      type: object
      required:
        - ingested_count
      properties:
        ingested_count:
          type: integer
          minimum: 0
    EventInput:
      type: object
      required:
        - event_id
        - customer_id
        - event_name
      properties:
        customer_id:
          type: string
          description: customer_id of the customer whose usage needs to be tracked
        event_id:
          type: string
          description: >-
            Event Id acts as an idempotency key. Any subsequent requests with
            the same event_id will be ignored
        event_name:
          type: string
          description: Name of the event
        metadata:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/EventMetadata'
              description: >-
                Custom metadata. Only key value pairs are accepted, objects or
                arrays submitted will be rejected.
        timestamp:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Custom Timestamp. Defaults to current timestamp in UTC.

            Timestamps that are older that 1 hour or after 5 mins, from current
            timestamp, will be rejected.
    EventMetadata:
      type: object
      title: EventMetadata
      description: >-
        Arbitrary key-value metadata. Values can be string, integer, number, or
        boolean.
      additionalProperties:
        oneOf:
          - type: string
            title: String
          - type: integer
            title: Integer
            format: int64
          - type: number
            title: Number
            format: double
          - type: boolean
            title: Boolean
        title: Event Metadata Value
        description: Metadata value can be a string, integer, number, or boolean
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````