# 5-Minute Quickstart

Get your AI API calls metered, monitored, and analyzed in minutes. Revenium acts as a zero-latency middleware—just install the SDK, set your keys, and wrap your client.

***

### <i class="fa-list-radio">:list-radio:</i> Prerequisites

Before you begin, you need a Revenium account to route your telemetry.

<a href="https://app.revenium.ai/" class="button primary">Sign in or Register</a>

Then navigate to [**Integrations**](https://app.revenium.ai/connections/sdk-setup) to get your API key

***

### 1. Install the SDK

{% tabs %}
{% tab title="Python" %}

```bash
pip install "revenium-python-sdk[openai]"
```

{% endtab %}

{% tab title="NodeJS" %}

```bash
npm install @revenium/middleware
```

{% endtab %}

{% tab title="Direct API" %}

```bash
curl -X POST "https://api.revenium.ai/meter/v2/ai/completions" \
    -H "Content-Type: application/json" \
    -H "x-api-key: YOUR_REVENIUM_API_KEY" \
    -d '{
      "transactionId": "<your-per-request-uuid>",
      "provider": "openai",
      "model": "gpt-4o-mini",
      "operationType": "CHAT",
      "inputTokenCount": 200,
      "outputTokenCount": 500,
      "totalTokenCount": 700,
      "stopReason": "END",
      "requestTime": "2026-05-22T00:00:00Z",
      "completionStartTime": "2026-05-22T00:00:01Z",
      "responseTime": "2026-05-22T00:00:02Z",
      "requestDuration": 2000,
      "organizationName": "acme-corp",
      "productName": "saas-app-gold-tier",
      "agent": "support-agent",
      "traceId": "conv-28a7e9d4"
    }'
```

{% hint style="info" %}
**`transactionId` is your correlation key.** Generate a UUID in your application *before* the AI call and send it to Revenium. Re-use it on retries — Revenium dedupes by `transactionId` so retries won't double-count. Send only one of `transactionId` or `spanId` per request.
{% endhint %}
{% endtab %}
{% endtabs %}

### 2. Set Environment Variables

Revenium automatically intercepts these variables from your environment to route your telemetry securely.

```bash
# Your Revenium Routing & Auth
# Metering key (rev_mk_*): metering-only scope used by the SDK + OTLP to emit metering events to Revenium.
export REVENIUM_METERING_API_KEY="your_revenium_api_key"
# Provider key: your standard provider API key used for the actual LLM call (swap for ANTHROPIC_API_KEY, etc. when using other providers).
export OPENAI_API_KEY="your_openai_api_key"
```

### 3. Wrap Your Client

Drop this into your existing logic. Revenium intercepts the call, calculates the exact token usage and cost, and forwards the request to OpenAI with zero added latency.

{% tabs %}
{% tab title="Python" %}

```python
import openai
import revenium_middleware.openai

response = openai.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {
            "role": "user",
            "content": "What is the meaning of life, the universe and everything?",
        },
    ],
    max_tokens=500,
    usage_metadata={
         "trace_id": "conv-28a7e9d4",
         "task_type": "summarize-customer-issue",
         "subscriber": {
             "id": "subscriberid-1234567890",
             "email": "user@example.com",
             "credential": {
                 "name": "engineering-api-key",
                 "value": "actual-api-key-value"
             }
         },
         "organization_name": "acme-corp",
         "subscription_id": "startup-plan-Q1",
         "product_name": "saas-app-gold-tier",
         "agent": "support-agent",
    },
)
print(response.choices[0].message.content)
```

{% endtab %}

{% tab title="NodeJS" %}

> Requires ESM — set `"type": "module"` in `package.json`, or wrap the call in an `async` function.

```typescript
import { Initialize, GetClient } from "@revenium/middleware/openai";

Initialize();
const openai = GetClient();

const response = await openai.chat().completions().create(
  {
    model: "gpt-4o-mini",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      {
        role: "user",
        content: "What is the meaning of life, the universe and everything?",
      },
    ],
    max_tokens: 500,
  },
  {
    traceId: "conv-28a7e9d4",
    taskType: "summarize-customer-issue",
    subscriber: {
      id: "subscriberid-1234567890",
      email: "user@example.com",
      credential: {
        name: "engineering-api-key",
        value: "actual-api-key-value",
      },
    },
    organizationName: "acme-corp",
    subscriptionId: "startup-plan-Q1",
    productName: "saas-app-gold-tier",
    agent: "support-agent",
  }
);

console.log(response.choices[0].message.content);
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**traceId is the field you plan around.** transactionId is auto-generated by the SDK (from the OpenAI response id) or by Revenium (if you omit it on a direct API call). What you control is `traceId` — use it to group multiple AI calls that belong to one user request, conversation, or workflow. Plan the traceId scheme that maps to your application's session / conversation / job ID.
{% endhint %}

***

### <i class="fa-hand-point-right">:hand-point-right:</i> Next Step: Take Control of Your AI Economics

Seeing a single request on your dashboard is just the beginning. Now that Revenium is connected, choose your next objective to move from basic observability to true economic control:

* [Attribute Your Usage](/track-and-control-costs/instrument-your-code.md)**:** Raw token counts are useless if you don't know *what* generated them. Learn how to inject `organizationName`, `productName`, `agent`, and `traceId` so you can track profit margins per customer and monitor exact agent execution paths.
* [Set Budgets & Alerts](/track-and-control-costs/set-budgets-and-alerts.md): Don't wake up to a massive provider bill. Set hard caps based on your tags and get pinged in Slack the second a customer or agent spikes your spend.
* [Monetize Your Apps](/monetize-your-ai/tutorial-build-usage-based-billing.md): Ready to turn compute costs into revenue? Use your new telemetry data to build automated, usage-based billing for your users.


---

# 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/get-started/quickstart/5-minute-quickstart.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.
