Kafka Consumer integration

Publish usage events directly to M360's tenant Kafka topic so they can be rated and billed.

Kafka Consumer integration

Overview

You send usage to M360 by publishing JSON usage events to a Kafka topic dedicated to your tenant. M360 reads each event, validates it, rates it against your pricing, and records the charges for billing.

This guide covers what you need to integrate as a producer: the topic to publish to, the event format, how events are processed, and how to troubleshoot. M360 provisions and operates the topics and consumers. You do not need to create topics or manage consumer groups.

If you submit usage through the HTTP endpoint instead of Kafka, see Realtime rating.

Connection summary

ItemValue
TransportApache Kafka
Message keyString (recommended, see Producer recommendations)
Message valueUTF-8 JSON, 1 MiB maximum
TopicOne per tenant: inference-usage_{tenantId}
PartitionsSet by M360 (10 by default)
Connection detailsBootstrap servers, network access and credentials are provided by your M360 contact

Prerequisites and onboarding

Start publishing only after M360 confirms your tenant is ready. Events published before that point may not be billed.

  1. Billing is enabled for your tenant. M360 creates your usage topic, with the correct partition count, when billing is turned on. Do not publish before then. If your cluster auto-creates the topic on first publish, it gets the broker default partition count instead.
  2. Usage tracking is configured. Your tenant needs usage tracking set up in M360 before events can be read.
  3. You have your tenant ID. This UUID forms your topic name. M360 provides it.
  4. You have connection details. Bootstrap servers, network access, and any credentials come from your M360 contact.
  5. M360 confirms the consumer is running. On a new tenant, M360 reads only events published after its consumer first starts. Earlier events on the topic are skipped unless M360 runs a backfill.

Need to load historical usage that was published early? Ask M360 for a backfill before or right after go-live.

Topics

Publish all usage events for your tenant to a single topic: inference-usage_{tenantId}. Note the underscore before the tenant ID.

Example: inference-usage_3f2a9c1e-5b7d-4e8a-9c21-7d4e5f6a8b90

One topic covers all your organizations. Each event carries its own organizationId, and M360 routes it to the right organization.

Do not create or change the topic. M360 provisions it, including its partition count. The default is 10 partitions. Contact M360 if you need more throughput.

Topic names can differ by environment. Sandbox and production may use different prefixes or clusters. Confirm the exact topic name for each environment with M360.

Retention is managed by M360. Events are normally consumed within seconds, and retention is sized to cover outages and replay.

Usage event format

Each message value is one JSON object describing one usage event. Fields not listed here are ignored. Each message must be 1 MiB or smaller.

FieldTypeRequiredDescription
externalTransactionIdstringYesYour unique ID for this event. M360 uses it to detect duplicates.
organizationIdUUIDYesThe organization the usage belongs to.
serviceIdUUIDYesThe M360 service being metered.
eventTimestampISO-8601 instant (UTC)YesWhen the usage happened, for example 2026-11-25T10:15:30Z.
billingAccountRefstringYesThe billing account to charge.
dimensionsobject of string to stringYes, non-emptyAttributes used for pricing, for example model and direction.
quantitynumberNoAmount consumed, for example tokens.
orgUnitIdstringNoOrganization unit, if you track usage below organization level.
serviceInstanceIdstringNoSpecific service instance.
priceUnitLabelstringNoLabel for the priced unit.
virtualKeyIdstringNoThe virtual or API key the usage came through.

Example event

{
  "externalTransactionId": "evt-0001",
  "organizationId": "11111111-1111-1111-1111-111111111111",
  "serviceId": "22222222-2222-2222-2222-222222222222",
  "eventTimestamp": "2026-11-25T10:15:30Z",
  "billingAccountRef": "ACC-1001",
  "dimensions": { "model": "gpt-4o", "direction": "input" },
  "quantity": 1520
}

An event that is not valid JSON, or that is missing a required field, is skipped and logged as an ingestion error. It is not retried, so it will not block later events. Correct the event and publish it again with the same externalTransactionId.

Producer recommendations

The most important rule: give every event a stable, unique externalTransactionId. That makes retries safe on both sides.

  • Idempotency. M360 deduplicates on externalTransactionId. Resending an event with the same ID does not double-bill, so retry freely on errors or timeouts.
  • Never reuse IDs. Two different usage events with the same ID are treated as one, and the second is dropped as a duplicate.
  • Durable delivery. Use acks=all with idempotent writes enabled (enable.idempotence=true in Java clients; the default in many clients) and producer retries, so events survive broker failover.
  • Wait for the acknowledgement. Treat an event as delivered only after the broker acknowledges it. A produce timeout of about 10 seconds, followed by a retry, works well.
  • Partitioning. Round-robin or keyed partitioning both work. M360 does not depend on ordering, so choose what spreads load evenly. If you set a key, externalTransactionId is a good choice.
  • Throughput. Batch and compress: compression.type=lz4, linger.ms of 5 to 20, and batches up to 1 MiB.
  • Message size. Keep each event under 1 MiB. Larger messages are rejected.
  • Timestamps. Send eventTimestamp in UTC and set it to when usage occurred, not when you published it.
  • Encoding. Send the value as UTF-8 JSON. Keep one event per message.

How M360 processes your events

Events are processed in near real time, in batches, with at-least-once delivery inside M360 and deduplication on externalTransactionId.

  • Two stages. Each event is ingested (stored as usage) and rated (priced into charges). Both stages read the same topic independently.
  • Parallel, unordered processing. Partitions are processed in parallel, so events are not handled in publish order across partitions. Billing results do not depend on arrival order.
  • Organization routing. Each batch is split by organizationId, and each organization's events are processed under that organization.
  • Invalid events are skipped. Events that fail parsing or validation are logged as pipeline errors and do not hold up valid events.
  • Transient failures are retried. Short outages on the M360 side are retried automatically. Because retries replay whole batches, deduplication ensures you are not charged twice.
  • Start position. A newly set-up tenant starts from the newest events on the topic. See Prerequisites and onboarding.

Billing alerts

You do not need to publish anything for billing alerts. M360 uses a separate internal topic per tenant, billing-alert_{tenantId}, to send alert notifications such as threshold emails. Each alert is sent once, and M360 tracks delivery to avoid duplicate emails.

Troubleshooting

Most issues come from onboarding timing or invalid payloads. When contacting M360 support, include your tenant ID, topic name, and example externalTransactionId values.

SymptomLikely causeWhat to do
Topic does not existBilling is not yet enabled for your tenantAsk M360 to enable billing. The topic is created then.
Events published but never consumedWrong topic name (prefix, environment, or tenant ID) or wrong clusterConfirm the exact topic name and bootstrap servers with M360.
Events published but never billed on a new tenantEvents were sent before M360's consumer first startedAsk M360 for a backfill, or republish them with the same IDs.
Topic has the wrong partition count or processing is slowTopic was auto-created by your first publish before M360 provisioned itContact M360 to provision the topic correctly.
Publish rejected as too largeMessage over 1 MiBReduce the payload, for example fewer or shorter dimensions.
Some events missing from billingInvalid JSON or a missing required fieldCheck each event against the field table, fix it, and republish with the same ID.
An event was billed once but sent twiceExpected: deduplication on externalTransactionIdNo action needed.
Two different events, only one billedBoth used the same externalTransactionIdUse a unique ID per event and republish the missing one with a new ID.
Charges under the wrong organizationWrong organizationId in the eventCorrect the ID in your producer. Contact M360 to adjust past charges.
Cannot connect to the clusterNetwork access or connection detailsConfirm bootstrap servers and access with your M360 contact.