# Real-Time Profile Lookup

Profile lookup helps you investigate how Real-Time ID stitching resolved a profile. A Treasure Workflow submits one or more identity selectors, and Real-Time writes a result for each input row to the `profile_lookup` table in the parent segment's real-time database, `cdp_audience_<parent_segment_id>_rt`.

Use lookup for targeted debugging. It is not intended for exporting the ID graph in bulk. The result contains the IDs currently associated with the resolved profile and its **persisted real-time attributes**. It does not include batch attributes or dynamically evaluated attributes.

## What a Lookup Returns

| Column | Description |
|  --- | --- |
| `time` | Lookup processing time, in Unix seconds. |
| `reactor_instance_id` | Real-Time instance that processed the lookup. |
| `lookup_row_index` | Zero-based index of the input row within the request. |
| `lookup_selectors` | Identity selectors supplied in the input row, excluding `td_rt_lookup_id`. |
| `current_rid` | RID of the resolved profile. Absent when no selector matches. |
| `realtime_attributes` | Persisted real-time attributes of the resolved profile. Empty when there is no match. |
| `current_id_attributes` | All IDs currently associated with the resolved profile, as `key:value` strings, sorted by association timestamp. Empty when there is no match. |
| `current_id_timestamps` | Unix timestamps in seconds for the corresponding entries in `current_id_attributes`, in the same order. Empty when there is no match. |
| `td_rt_lookup_id` | Optional correlation ID supplied by the workflow. |


If a profile was merged into another profile, the IDs moved to the retained RID have timestamps corresponding to the merge time. These timestamps describe when an association was updated; they are not necessarily when an ID was first seen.

When multiple selectors in one input row resolve to different profiles, the lookup returns the oldest RID, which is the RID a stitching operation would retain. Use the fewest selectors needed to identify the profile.

## Run a Lookup from Treasure Workflow

You need the parent segment ID, its Real-Time instance ID, and the importer endpoint for your deployment stage and site. The importer endpoint is reachable from Treasure Workflow within the Treasure AI platform. Contact Treasure AI Support if you need the instance ID or help identifying the correct endpoint.

Store an API key in the workflow project's **Secrets** tab as `td.apikey`. For this workflow, the secret value must be a complete authorization value in the form `TD1 <account_id>/<api_key>`.

The following example looks up one profile by its configured `td_client_id` key. It uses the **production US** endpoint as an example. Replace `XXXX`, the instance ID, and the endpoint to match your deployment stage and site. Consult Treasure AI Support if you are unsure which endpoint to use. The optional `td_rt_lookup_id` value makes it easier to find the result later.

```yaml
_export:
  reactor_api_endpoint: "https://bulk-storage-importer-api-production-aws-us-east-1.internal.treasuredata.com"
  reactor_instance: "aYYYYnZ"
  td:
    database: cdp_audience_XXXX
    engine: presto

+profile_lookup:
  td>:
  query: |
    SELECT
      'td_client_id:12345' AS result,
      'td_rt_lookup_id:my-lookup-job' AS lookup_id
  result_url: |
    {
      "type": "rest",
      "method": "POST",
      "authorization": "${secret:td.apikey}",
      "endpoint": "${reactor_api_endpoint}/internal/lookup-profile",
      "headers": "{\"x-reactor-instance-name\": \"${reactor_instance}\"}"
    }
```

Use a key configured for your Real-Time instance. Each selector has the form `key:value`; the optional `td_rt_lookup_id:value` is metadata, not a selector. The request accepts up to five input rows. Run targeted lookups at approximately one request per second per importer instance rather than using this workflow for bulk extraction.

After the workflow completes, query the results in **Data Workbench**:

```sql
SELECT
  time,
  td_rt_lookup_id,
  reactor_instance_id,
  lookup_row_index,
  lookup_selectors,
  current_rid,
  realtime_attributes,
  current_id_attributes,
  current_id_timestamps
FROM cdp_audience_XXXX_rt.profile_lookup
WHERE td_rt_lookup_id = 'my-lookup-job'
ORDER BY time DESC
```

### Production Importer Endpoints

These endpoints apply to production. Other deployment stages use different endpoints; use the endpoint that matches both your stage and site.

| Site | Endpoint |
|  --- | --- |
| US | `https://bulk-storage-importer-api-production-aws-us-east-1.internal.treasuredata.com` |
| EU (eu01) | `https://bulk-storage-importer-api-production-eu01-eu-central-1.internal.treasuredata.com` |
| Tokyo | `https://bulk-storage-importer-api-production-aws-tokyo-ap-northeast-1.internal.treasuredata.com` |


For the identity changes that led to the current graph, see [Real Time Identity Log Tables](/products/customer-data-platform/real-time/real-time-identity-log-tables). Profile lookup shows the current state; the identity log tables show changes over time.