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
| Item | Value |
|---|---|
| Transport | Apache Kafka |
| Message key | String (recommended, see Producer recommendations) |
| Message value | UTF-8 JSON, 1 MiB maximum |
| Topic | One per tenant: inference-usage_{tenantId} |
| Partitions | Set by M360 (10 by default) |
| Connection details | Bootstrap 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.
- 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.
- Usage tracking is configured. Your tenant needs usage tracking set up in M360 before events can be read.
- You have your tenant ID. This UUID forms your topic name. M360 provides it.
- You have connection details. Bootstrap servers, network access, and any credentials come from your M360 contact.
- 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.
| Field | Type | Required | Description |
|---|---|---|---|
externalTransactionId | string | Yes | Your unique ID for this event. M360 uses it to detect duplicates. |
organizationId | UUID | Yes | The organization the usage belongs to. |
serviceId | UUID | Yes | The M360 service being metered. |
eventTimestamp | ISO-8601 instant (UTC) | Yes | When the usage happened, for example 2026-11-25T10:15:30Z. |
billingAccountRef | string | Yes | The billing account to charge. |
dimensions | object of string to string | Yes, non-empty | Attributes used for pricing, for example model and direction. |
quantity | number | No | Amount consumed, for example tokens. |
orgUnitId | string | No | Organization unit, if you track usage below organization level. |
serviceInstanceId | string | No | Specific service instance. |
priceUnitLabel | string | No | Label for the priced unit. |
virtualKeyId | string | No | The 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=allwith idempotent writes enabled (enable.idempotence=truein 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,
externalTransactionIdis a good choice. - Throughput. Batch and compress:
compression.type=lz4,linger.msof 5 to 20, and batches up to 1 MiB. - Message size. Keep each event under 1 MiB. Larger messages are rejected.
- Timestamps. Send
eventTimestampin 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.
| Symptom | Likely cause | What to do |
|---|---|---|
| Topic does not exist | Billing is not yet enabled for your tenant | Ask M360 to enable billing. The topic is created then. |
| Events published but never consumed | Wrong topic name (prefix, environment, or tenant ID) or wrong cluster | Confirm the exact topic name and bootstrap servers with M360. |
| Events published but never billed on a new tenant | Events were sent before M360's consumer first started | Ask M360 for a backfill, or republish them with the same IDs. |
| Topic has the wrong partition count or processing is slow | Topic was auto-created by your first publish before M360 provisioned it | Contact M360 to provision the topic correctly. |
| Publish rejected as too large | Message over 1 MiB | Reduce the payload, for example fewer or shorter dimensions. |
| Some events missing from billing | Invalid JSON or a missing required field | Check each event against the field table, fix it, and republish with the same ID. |
| An event was billed once but sent twice | Expected: deduplication on externalTransactionId | No action needed. |
| Two different events, only one billed | Both used the same externalTransactionId | Use a unique ID per event and republish the missing one with a new ID. |
| Charges under the wrong organization | Wrong organizationId in the event | Correct the ID in your producer. Contact M360 to adjust past charges. |
| Cannot connect to the cluster | Network access or connection details | Confirm bootstrap servers and access with your M360 contact. |
Related documentation
- Realtime rating: submit usage over HTTP instead of Kafka.
- Rated transactions: read the charges produced from your usage.
- Services: the metered services and their dimensions.