For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
  • Get Started
    • Quickstart: Build a Chat App
    • Enterprise Quickstart
    • Free Models Router
  • Working with Coding Agents
    • Automatic Code Review
    • Claude Code
    • Claude Desktop
    • Codex CLI
    • Cursor
    • Hermes Agent
    • Junie CLI
    • MCP Servers
    • OpenClaw 🦞
    • OpenCode
  • Building Agents
    • Add Human-in-the-Loop Controls
    • Build a Long-Horizon Agent
    • Build Your Own Agent TUI
    • Build Your Own Headless Agent
  • Video Generation
    • Choose a Video Generation Model
    • Generate and Download a Video from Text
    • Get Video Results with Webhooks
    • Guide a Video with Reference Images
    • Turn an Image into a Video
    • Use Provider-Specific Video Options
  • Evaluate & Optimize
    • Distillation
    • RAG with Embeddings & Rerank
    • Red Teaming
  • Administration
    • Activity Export
    • API Key Rotation
    • Crypto API
    • Organization Management
    • Usage Accounting
    • User Tracking
LogoLogo
ModelsChatRankingsDocs
On this page
  • What is User Tracking?
  • How It Works
  • Implementation Example
  • Best Practices
  • Choose Stable Identifiers
  • Consider Privacy
  • Be Consistent
Administration

User Tracking

Was this page helpful?
Previous

Changelog

A daily log of product changes, improvements, and new model releases on OpenRouter
Next
Built with

The OpenRouter API supports User Tracking through the optional user parameter, allowing you to track your own user IDs and improve your application’s reporting capabilities.

What is User Tracking?

User tracking enables you to specify an arbitrary string identifier for your end-users in API requests. This optional metadata helps OpenRouter understand your sub-users.

How It Works

Simply include a user parameter in your API requests with any string identifier that represents your end-user. This could be a user ID, email hash, session identifier, or any other stable identifier you use in your application.

1{
2 "model": "~openai/gpt-latest",
3 "messages": [
4 {"role": "user", "content": "Hello, how are you?"}
5 ],
6 "user": "user_12345"
7}

Implementation Example

1import { OpenRouter } from '@openrouter/sdk';
2
3const openRouter = new OpenRouter({
4 apiKey: '{{API_KEY_REF}}',
5});
6
7const response = await openRouter.chat.send({
8 model: '{{MODEL}}',
9 messages: [
10 {
11 role: 'user',
12 content: "What's the weather like today?",
13 },
14 ],
15 user: 'user_12345', // Your user identifier
16 stream: false,
17});
18
19console.log(response.choices[0].message.content);

Best Practices

Choose Stable Identifiers

Use consistent, stable identifiers for the same user across requests:

  • Good: user_12345, customer_abc123, account_xyz789
  • Avoid: Random strings that change between requests

Consider Privacy

When using user identifiers, consider privacy implications:

  • Use internal user IDs rather than exposing personal information
  • Avoid including personally identifiable information in user identifiers
  • Consider using anonymized identifiers for better privacy protection

Be Consistent

Use the same user identifier format throughout your application:

1# Consistent format
2user_id = f"app_{internal_user_id}"