Session Metadata
Attach your own key-value pairs to Steel sessions, change them during or after a run, and find sessions by them later.
Overview
Session metadata is a flat set of key-value pairs that you attach to a session. Use it to store your own identifiers, such as a job ID, a customer, or an environment. Steel returns metadata on every session response and shows it on the session page in the dashboard, so don't store secrets in it.
type: info
Session metadata needs steel-sdk 0.21.0 or later, in TypeScript and Python.
1import Steel from 'steel-sdk';23const client = new Steel();45const session = await client.sessions.create({6metadata: {7job_id: 'job-1042',8customer: 'acme',9attempt: 1,10},11});1213console.log(session.metadata);
Steel stores every value as a string. Numbers and booleans come back in their string form, so 1 comes back as "1":
1{2"job_id": "job-1042",3"customer": "acme",4"attempt": "1"5}
Update Metadata
updateMetadata changes only the keys that you send. Set a key to null to remove it. Keys that you leave out keep their values. You can update metadata while the session runs and after it ends.
1const { metadata } = await client.sessions.updateMetadata(session.id, {2metadata: {3outcome: 'success',4attempt: null,5},6});78console.log(metadata);
The response contains the merged metadata:
1{2"metadata": {3"job_id": "job-1042",4"customer": "acme",5"outcome": "success"6}7}
Each update is atomic. If two updates change different keys at the same time, Steel keeps both changes.
Replace Metadata
replaceMetadata replaces the whole object. Send an empty object to clear it. If two replacements arrive at the same time, the last one wins.
1await client.sessions.replaceMetadata(session.id, {2metadata: { job_id: 'job-1042', owner: 'data-team' },3});45await client.sessions.replaceMetadata(session.id, { metadata: {} });
Use updateMetadata unless you want to remove every key that you don't send.
| SDK method | Endpoint | Behavior |
|---|---|---|
updateMetadata (update_metadata in Python) | PATCH /v1/sessions/{id}/metadata | Merges the keys that you send. null removes a key. |
replaceMetadata (replace_metadata in Python) | PUT /v1/sessions/{id}/metadata | Replaces all keys. {} clears the metadata. |
Find Sessions by Metadata
Pass metadata to sessions.list to find sessions with matching values. Each value must match the stored string exactly. If you pass several keys, a session must match all of them.
1for await (const session of client.sessions.list({2metadata: { customer: 'acme', job_id: 'job-1042' },3})) {4console.log(session.id, session.status);5}
The SDK fetches every page for you. Over HTTP, send each key in bracket form and follow nextCursor until it is null:
1curl -G https://api.steel.dev/v1/sessions \2-H "steel-api-key: $STEEL_API_KEY" \3--data-urlencode "metadata[customer]=acme" \4--data-urlencode "metadata[job_id]=job-1042"
- Filter values are strings. Pass
attempt: '1'to match a value that you sent as1. - The list leaves out failed sessions unless you pass
statusorreleaseReason. See Find Past Sessions. - To find sessions in a job that hit a CAPTCHA or a bot block, add a
signalfilter. See Session Signals.
Limits
| Rule | Limit |
|---|---|
| Keys | Up to 50 per session |
| Size | Up to 8 KiB, measured as UTF-8 JSON |
| Key format | Starts with a letter. Uses only letters, digits, _, ., and -. Up to 64 characters. |
| Reserved keys | Keys that start with steel_ |
| Values | Strings up to 1024 characters, numbers, or booleans |
| Keys per update | Up to 100 in one updateMetadata call |
A request that breaks a rule fails with a 400 error that names the key. An update that would push the merged metadata past a limit fails and leaves the session unchanged.
Reach out to us on the #help channel on Discord or @steeldotdev.