# Instrument Your Code

The fastest, lowest-maintenance way to send cost data to Revenium is the SDK plus your existing provider client (OpenAI, Anthropic, LiteLLM, etc.). The SDK handles the metering payload — including required fields and attribution — so you don't need to construct it yourself.

### Send Data via the SDK

The Revenium Python SDK wraps your existing provider clients with a single line of code:

```python
from openai import OpenAI
from revenium_middleware.openai import meter

client = meter(OpenAI())  # all completions are now metered to Revenium
```

For other languages and providers (LiteLLM, OpenRouter, Anthropic, Google), see [SDK Setup](/integrations/sdk-setup.md). The SDKs document the full set of supported fields, attribution metadata, and language-specific patterns in their READMEs and example libraries — treat them as the canonical reference for what to send.

### Already on OpenTelemetry?

If your stack already emits OpenTelemetry, you don't need to add Revenium-specific instrumentation. Revenium accepts OTLP traces, metrics, and logs directly — point your OTel collector at the Revenium OTLP endpoint and your existing spans flow in, with span identifiers carrying over without remapping. For setup details, endpoints, and authentication, see [OTLP Integration](/integrations/otlp-integration.md).

### Enrich Calls with Business Attribution

Out of the box, the SDK sends model, token counts, and cost. To unlock the full dashboard — cost by customer, cost by product, agent ROI, trace analytics — pass attribution alongside each call:

* **`organizationName`** — the customer account (parent company). Accepts `organizationId` as an alias.
* **`productName`** — the commercial tier or SKU the customer is on. Accepts `productId` as an alias.
* **`subscriber`** — sub-object identifying the end customer: `{ id, email, credential: { name, value } }`.
* **`agent`** — the specific agent making the call. Powers per-agent cost views and the Tool Registry.
* **`traceId`** — links sequential AI calls into a single workflow for Trace Analytics.
* **`taskType`** — categorises what the agent was doing (qualification, support, code review, etc.).

The more attribution you send, the more dimensions become available in dashboards, alerts, and cost controls. For the complete field list including subscription, quality scoring, and cost-control fields, see [SDK Setup → Usage Metadata](/integrations/sdk-setup.md#usage-metadata).

### What You Can Meter

Revenium accepts more than just LLM completions. Send any combination of these event types — each has its own pricing curves and its own dashboard slice, so spend never collapses into a single number:

| Event type           | What it captures                                                                                               | Reference                                                                                                           |
| -------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **AI completions**   | LLM API calls — OpenAI, Anthropic, Bedrock, Google, and the long tail of providers                             | [SDK Setup](/integrations/sdk-setup.md) · [API Reference](https://revenium.readme.io/reference/meter_ai_completion) |
| **Tool events**      | Agent tool and function-call invocations — often as expensive or more than the LLM call itself                 | [Monitor Agent Tool Usage](/instrument-your-agents/monitor-agent-tool-usage.md)                                     |
| **Agent outcomes**   | Terminal business result of an agent run — CONVERTED, DEFLECTED, ESCALATED, CUSTOM, with optional dollar value | [AI Outcomes](/instrument-your-agents/agent-outcomes.md)                                                            |
| **Image generation** | Image workloads (DALL·E, Stable Diffusion, fal.ai, provider-native vision)                                     | [API Reference](https://revenium.readme.io/reference/meter_ai_images)                                               |
| **Audio operations** | Speech-to-text, text-to-speech, transcription                                                                  | [API Reference](https://revenium.readme.io/reference/meter_ai_audio)                                                |
| **Video operations** | Video generation, analysis, captioning pipelines                                                               | [API Reference](https://revenium.readme.io/reference/meter_ai_video)                                                |
| **Custom events**    | Arbitrary consumption units — OCR pages, retrieval rows scanned, document enrichments                          | [API Reference](https://revenium.readme.io/reference/meter_event)                                                   |

Multimodal workloads benefit most from the dedicated endpoints — they apply the correct pricing curves automatically. Use custom events only when the unit you bill on doesn't fit a structured type.

### Beyond Standard Tokens: Quality & Custom Metrics

Most teams start with tokens and latency. As AI workloads mature, two more dimensions become valuable:

* **Response quality measurement.** Cost and latency tell you what you spent — they don't tell you whether the output was any good. The SDK can carry a quality score per call, sourced from whatever evaluation logic you trust: RAGAS-style retrieval evaluation, LLM-as-a-judge pipelines, downstream user feedback, or a human review queue. Once recorded, dashboards correlate quality against cost, model choice, agent, and customer — so you can see whether the cheaper model is actually losing you revenue, or whether one agent's outputs are systematically weaker than another's.
* **Custom consumption metrics.** Some workloads are billed or evaluated in units that aren't tokens, audio seconds, or image counts — pages parsed by an OCR pipeline, rows scanned by a retrieval index, documents enriched by an extraction agent. Revenium accepts arbitrary numeric metrics alongside the standard event, so these workloads show up in cost-by-product and per-customer dashboards alongside LLM spend. Particularly useful when you're charging customers for an outcome rather than for tokens.

### Direct API Integration

If you can't use the SDK (unsupported language, custom proxy, etc.), see the [API Reference](https://revenium.readme.io) for the raw payload schema across all the event types listed above.

### Related

* [SDK Setup](/integrations/sdk-setup.md) — provider wrappers, language coverage, the canonical field reference
* [Provider Integrations](/integrations/provider-integrations.md) — OpenAI, Anthropic, LiteLLM, OpenRouter, fal.ai
* [OTLP Integration](/integrations/otlp-integration.md) — for stacks already on OpenTelemetry
* [AI Outcomes](/instrument-your-agents/agent-outcomes.md) — close the ROI loop
* [Monitor Agent Tool Usage](/instrument-your-agents/monitor-agent-tool-usage.md) — meter tool calls alongside LLM calls
* [API Reference](https://revenium.readme.io) — raw HTTP API for direct integrations


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.revenium.io/track-and-control-costs/instrument-your-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
