Available for: Python and TypeScript.
wrapOpenRouter() (TypeScript) to trace every call, regardless of which underlying model is used — or patch the openai module with patch_openrouter() (Python), since OpenRouter uses an OpenAI-compatible API.
Installation
openai package as the client in both languages.
Setup
In Python,
patch_openrouter() is an alias for patch_openai() — it monkey-patches the openai module’s chat completions method globally rather than wrapping a single client instance. This means: (1) any openai.OpenAI() client in your process is traced after calling it, whether it points at OpenRouter’s base_url or not; (2) traced events are tagged provider: "openai", not provider: "openrouter"; and (3) cost is calculated from token counts and generic pricing, not from OpenRouter’s own reported cost. The TypeScript wrapOpenRouter() wraps only the client instance you pass it, tags events provider: "openrouter", and prefers OpenRouter’s actual reported cost (see below). There is currently no separate Python codepath that gives OpenRouter-specific cost or provider tagging — patch_openrouter() and patch_openai() are the same function.Example
What gets captured
Cost reporting accuracy in TypeScript depends on whether OpenRouter returns cost data in the response. For most popular models it does. For custom or fine-tuned routes, token-based calculation is used as a fallback.

