Skip to main content

Overview

Track costs and monitor usage for OpenAI’s API (GPT-4, GPT-3.5, o1) by routing your requests through LLM Ops. This guide shows you how to integrate using Python, JavaScript, or cURL.
Security Guarantee: LLM Ops does not store your API keys, request prompts, or response content in the analytics database—only metadata needed for cost analytics. The proxy must forward request bodies to OpenAI to complete the call; optional operational logging may exist in your deployment environment.

Quick Start

The OpenAI official SDKs expect base_url (or baseURL) to include the /v1 path segment (e.g. https://api.openai.com/v1). Point that at the LLM Ops API host:
  • Original: https://api.openai.com/v1
  • LLM Ops (SDK base_url / baseURL): https://api.llm-ops.cloudidr.com/v1
  • cURL: use the full URL https://api.llm-ops.cloudidr.com/v1/chat/completions
This differs from the Anthropic integration: Claude’s SDK uses a host without /v1; OpenAI’s SDK uses a base URL with /v1.

API Keys

You’ll need two credentials:
  1. OpenAI API Key - Your API key from platform.openai.com
  2. Cloudidr Key - Your tracking token from the LLM Ops dashboard (tokens are typically prefixed with trk_)
The marketing site llmfinops.ai points at the same product; the dashboard URL above is the canonical app host. Set them as environment variables:

Integration Examples

Install SDK

Basic Example

With Metadata (Department/Team/Agent Tracking)

Streaming Example

Function Calling Example


Cost Tracking Headers

Add these headers to organize your costs by department, team, or agent:

Supported Models

All OpenAI models are supported. See the Supported Models page for the complete list of available models and pricing.

What Gets Tracked

LLM Ops automatically captures: Token usage - Prompt, completion, and total tokens
Cost - Real-time cost calculation
Latency - Request duration (TTFT, total time)
Model - Which OpenAI model was used
Metadata - Department, team, agent
Errors - Failed requests and error types
Function calls - Tool/function usage tracking
What We DON’T Track:
  • ❌ Customer API keys
  • ❌ Request content (prompts)
  • ❌ Response content (completions)
We only persist metadata needed for cost analytics in our application database.

View Your Data

After making requests, view your costs in the LLM Ops Dashboard:
  • Agent Explorer - See costs by agent/application
  • Department Breakdown - Compare department spending
  • Team Analysis - Track team-level costs
  • Model Comparison - Compare costs across models
  • Time Series - Track spending over time
  • Cost Optimization - Get recommendations for cheaper models

Migration from Direct API

Switching from direct OpenAI API to LLM Ops is a two-line change:
Everything else stays the same - no code changes needed!

Cost Optimization Tips

Use the LLM Ops dashboard to identify which agents can switch to cheaper models:
  • Track cost per request by model
  • Compare quality vs. cost trade-offs
  • Identify high-volume, low-complexity tasks
Perfect candidates for model switching appear in the Agent Explorer.
Function calling adds token overhead:
  • Track function call frequency per agent
  • Identify redundant or unnecessary calls
  • Optimize function descriptions to reduce tokens
LLM Ops tracks tool usage separately from chat completion.
OpenAI’s prompt caching can reduce costs for repeated system prompts:
  • Track cache hit rates in dashboard
  • Identify agents with repeated prompts
  • Structure prompts for maximum cache benefit
LLM Ops shows cache savings in cost breakdowns when applicable.

Troubleshooting

Check these common issues:
  • ✅ For OpenAI SDKs, set base_url / baseURL to https://api.llm-ops.cloudidr.com/v1 (OpenAI expects the /v1 prefix).
  • ✅ For cURL, call https://api.llm-ops.cloudidr.com/v1/chat/completions.
  • ✅ Confirm the header name is X-Cloudidr-Key (not X-Cloudidr-Token) on every request.
  • ✅ Check that your OpenAI API key is valid.
Two separate keys are needed:
  • Your OpenAI API key (for GPT access)
  • Your Cloudidr tracking token (for cost tracking)
Make sure both are set correctly and not swapped.
Wait a few moments:
  • Cost data may take 10-30 seconds to appear in dashboard
  • Check the correct time range in dashboard filters
  • Verify requests are returning 200 OK status

Next Steps

View Dashboard

See your OpenAI API costs in real-time

Supported Models

View all supported OpenAI models

Anthropic Integration

Add cost tracking for Claude models

Set Budgets

Configure spending alerts and limits