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

# Metadata

PromptLayer allows you to attach multiple key value pairs as metadata to a request. In the dashboard, you can look up requests and analyze analytics using metadata.

We recommend using this for things like session IDs, user IDs, or error messages. Metadata is useful to help you use the [advanced search](/why-promptlayer/advanced-search) or understand the Analytics page.

## Add metadata when running a prompt

Pass metadata directly into `client.run()` when you already know the request context, such as the user, session, or feature that triggered the prompt.

```python Python theme={null}
response = client.run(
    prompt_name="cake-recipe",
    input_variables={"cake_type": "Chocolate", "serving_size": "8"},
    tags=["production", "recipe-feature"],
    metadata={
        "user_id": "user_123",
        "session_id": "sess_abc"
    }
)

client.track.score(request_id=response["request_id"], score=95)
```

Your metadata and tags appear in the log details, letting you filter and search by user or feature.

<Frame>
  <img src="https://mintcdn.com/promptlayer/2Nw4D0YQ3AERsqEA/new-quickstart-images/metadata-search.png?fit=max&auto=format&n=2Nw4D0YQ3AERsqEA&q=85&s=47ca4b7b678fcade8aa60b57700ec6e2" alt="Log with metadata" width="890" height="1184" data-path="new-quickstart-images/metadata-search.png" />
</Frame>

## Add metadata after a request

Use `track.metadata()` when you need to attach or update metadata after a request has already run.

[Endpoint Reference](/reference/track-metadata)

<CodeGroup>
  ```python Python theme={null}
  promptlayer_client.track.metadata(
    request_id=pl_request_id,
    metadata={
        "user_id":"1abf2345f",
        "post_id": "2cef2345f"
    }
  )
  ```

  ```js JavaScript theme={null}
  promptLayerClient.track.metadata({
    request_id: pl_request_id,
    metadata: {
        "user_id":"1abf2345f",
        "post_id": "2cef2345f"
    }
  })
  ```

  ```java Java theme={null}
  ```

  ```bash REST theme={null}
  curl --request POST \
    --url https://api.promptlayer.com/rest/track-metadata \
    --header 'Content-Type: application/json' \
    --header 'X-API-KEY: pl_<YOUR API KEY>' \
    --data '{
      "request_id": "<REQUEST ID>",
      "metadata": {
        "user_id":"1abf2345f",
        "post_id": "2cef2345f"
      }
    }'
  ```
</CodeGroup>

Things to note:

1. Currently keys and values need to be strings in PromptLayer.
2. If you track a key that was already tracked before for a specific request\_id, the value that corresponds to that key will be replaced.

***

Once metadata is added, you will then be able to see it in the web UI.

<img src="https://mintcdn.com/promptlayer/jUVR1Bx755pIFGwB/images/metadata-ui.png?fit=max&auto=format&n=jUVR1Bx755pIFGwB&q=85&s=240bbb2b1105d461328cd5f70fb67d20" alt="score" width="596" height="652" data-path="images/metadata-ui.png" />

Metadata is optimized for high-cardinality, request-specific values such as user IDs, session IDs, and error messages. For a smaller set of categories, such as environment, app, feature, or pipeline stage, use [tags](/features/prompt-history/tagging-requests) instead.
