> ## Documentation Index
> Fetch the complete documentation index at: https://docs.llm.report/llms.txt
> Use this file to discover all available pages before exploring further.

# User Analytics

> Get detailed analytics about your users such as cost per user, and more.

<video className="block rounded-xl shadow-lg" src="https://cdn.llm.report/users-demo.mp4" alt="Users demo" autoPlay loop muted />

## User Analytics

Attach a user ID to your requests to get detailed analytics about your users.

Just swap out `https://api.openai.com` for `https://api.openai.withlogging.com` and add `X-User-Id` header to your requests.

<CodeGroup>
  ```javascript node theme={null}
  import { Configuration, OpenAIApi } from "openai";

  const configuration = new Configuration({
    apiKey: process.env.OPENAI_API_KEY,
    basePath: "https://api.openai.withlogging.com/v1",
    baseOptions: {
      headers: {
        "X-Api-Key": `Bearer ${process.env.LLM_REPORT_API_KEY}`,
        "X-User-Id": `myuser@example.com`,
      },
    },
  });

  const openai = new OpenAIApi(configuration);

  const completion = await openai.createChatCompletion({
    model: "gpt-3.5-turbo",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "Hello world" },
    ],
  });
  ```

  ```javascript javascript theme={null}
  fetch("https://api.openai.withlogging.com/v1/chat/completions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
      "X-Api-Key": `Bearer ${process.env.LLM_REPORT_API_KEY}`,
      "X-User-Id": `myuser@example.com`,
    },
    body: JSON.stringify({
      model: "gpt-3.5-turbo",
      messages: [{ role: "user", content: "Hello world" }],
    }),
  });
  ```

  ```python python theme={null}
  import os
  import openai

  openai.api_key = os.getenv("OPENAI_API_KEY")
  openai.api_base = "https://api.openai.withlogging.com/v1"

  completion = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
      {"role": "user", "content": "Hello!"}
    ],
    headers={
      "X-Api-Key": "Bearer " + os.getenv("LLM_REPORT_API_KEY"),
      "X-User-Id": "myuser@example.com",
    }
  )

  print(completion.choices[0].message)
  ```

  ```bash bash theme={null}
  curl https://api.openai.withlogging.com/v1/chat/completions  \\
    -H "Content-Type: application/json" \\
    -H "Authorization: Bearer $OPENAI_API_KEY" \\
    -H "X-Api-Key: Bearer $LLM_REPORT_API_KEY" \\
    -H "X-User-Id: myuser@example.com" \\
    -d '{
      "model": "gpt-3.5-turbo",
      "messages": [{"role": "user", "content": "Hello!"}]
    }'
  ```
</CodeGroup>
