API Reference

Realtime rating

Submit usage events to the realtime billing rating pipeline.

Realtime rating

Endpoint: POST /v1/ingest/usage

The realtime rating API accepts a usage event and publishes it to the tenant's billing pipeline. The event is ingested as a UsageEvent and rated asynchronously. Use Rated transactions to read the resulting transaction.

Authentication

Send a valid MPilot Bearer token. The token must contain:

  • tenantId — selects the tenant-specific usage topic.
  • morgId — used as the organization context for the usage event.

Submit a usage event

POST /v1/ingest/usage
Authorization: Bearer YOUR_API_TOKEN
Content-Type: application/json
curl -sS -X POST "https://YOUR_AI_GATEWAY_HOST/v1/ingest/usage" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "usage-event-001",
    "message": {
      "externalTransactionId": "usage-event-001",
      "serviceId": "e6cbd28a-f34c-482e-8da5-34e21dbd5eb7",
      "eventTimestamp": "2026-09-10T12:30:00Z",
      "billingAccountRef": "ACC-1001",
      "dimensions": {
        "Input_Tokens": "1000",
        "Output_Tokens": "250",
        "Model": "gpt-4o"
      },
      "quantity": 1250,
      "serviceInstanceId": "service-instance-001",
      "priceUnitLabel": "tokens"
    }
  }'

Request body

FieldRequiredDescription
keyNoKafka record key. Using the external transaction ID is recommended.
messageYesUsage event submitted to the rating pipeline. Must be a JSON object.
message.externalTransactionIdYesUnique producer identifier for the usage event.
message.serviceIdYesUUID of the billing service to rate.
message.eventTimestampYesTime the usage occurred, in ISO 8601 format.
message.billingAccountRefYesExternal ID of the billing account.
message.dimensionsYesNon-empty map of rating dimension names to string values. Names must match the service's configured dimensions.
message.quantityNoUsage volume supplied to rating.
message.serviceInstanceIdNoExternal service-instance identifier.
message.priceUnitLabelNoPrice unit label associated with the usage.

externalTransactionId, serviceId, eventTimestamp, billingAccountRef, and a non-empty dimensions map are required by the downstream billing pipeline. Organization context comes from morgId in the token.

Response

Response 200

{
  "status": "published",
  "topic": "inference-usage_7d2f6c90-4b0a-4cf7-9c58-8f9e18f83a11",
  "partition": 3,
  "offset": 1842
}

A successful response confirms that Kafka accepted the event. Rating and persistence happen asynchronously; it does not confirm that the event was successfully rated.

Errors

{
  "is_bifrost_error": false,
  "status_code": 400,
  "error": {
    "message": "organizationId is required in the message or as morgId in the token"
  },
  "extra_fields": {}
}
StatusWhen
400Invalid JSON, missing message, missing morgId in the token, or gateway Kafka configuration is unavailable.
401Bearer token is missing, invalid, expired, or lacks tenantId.
413Request body exceeds 1 MiB.
502The gateway could not publish the event to Kafka.
504Kafka publishing exceeded the request timeout.

Payload validation and account/service resolution happen downstream. Invalid events may be accepted by this endpoint and then skipped by the billing pipeline; use a unique externalTransactionId for tracking and retries.