Concepts

State

A durable key-value store that runs share: named stores, keys and JSON values, versions with compare-and-set, expiry, the agent's state tools and what state costs.

State is a durable key-value store that runs share. A run starts in an empty machine, so it cannot remember anything on its own. With state, a run can read what an earlier run saved and write what the next one needs: what a scheduled run saw last time, a cursor, a list of items already handled.

Stores, keys and values

State is kept in named stores, like workflows are kept under names: letters, digits, dot, dash and underscore. A store holds entries. Each entry has a key and a value.

PartRule
StoreA name of letters, digits, ., - and _. A store exists once it has an entry.
KeyAny text, up to 512 bytes. URL-encode it in an API path.
ValueAny JSON, up to 1 MiB.
VersionA number that counts the entry's writes, starting at 1. It is returned with every read and write.
ttl_secondsOptional. The entry is deleted after that many seconds.

Changing an entry safely

Two runs, or a run and your code, can write the same entry at once. To keep one from overwriting the other, pass if_version when you write: the write happens only if the entry is still at that version. if_version: 0 means create only, when the entry does not exist yet. On a mismatch the answer is 409, and you read the entry again and retry. Deleting takes if_version too.

State in a run

Set state to a store name in a run request or a saved workflow. The agent is then told about the store and given four tools:

ToolWhat it does
state_getReads a key. The key may be missing, as on the first run.
state_setWrites a key with any JSON value.
state_deleteRemoves a key.
state_listLists the keys, optionally those with a prefix.

The agent reads and writes only the store named in state. A run without state has no state tools.

Example: report only what is new

A scheduled job that checks a page every morning should tell you about new items, not the same list each day. Keep what was already reported in state. The saved example workflow example-watch-page does this: it fetches the page, reads the links it reported before from the state entry whose key is the page's URL, reports the items whose links are not in it, then writes every link on the page now under the same key. The first run reports everything and says so in first_run.

Saved definition
prompt: |
  Watch the page at the input's url for new items. Fetch it and list its items,
  each with its title and link. Read the state entry whose key is the url with
  state_get: it holds the links reported before (missing on the first run).
  Report only the items whose links are not in it. Then save every link on the
  page now with state_set under the same key. Set first_run to true when there
  was no state entry.
web: true
shell: false
state: example-watch-page
output_schema:
  type: object
  required: [first_run, new_items]
  properties:
    first_run: { type: boolean }
    new_items:
      type: array
      items:
        type: object
        required: [title, url]
        properties:
          title: { type: string }
          url: { type: string }

Put it on a schedule, and add notify so that a saved connection to your chat or webhook is told when it finishes. New organizations already have this workflow; add_example_workflows or POST /v1/examples adds it to any other.

Reading and writing state yourself

You can read and change state from your own code, the dashboard or an MCP client, for example to seed a store or reset one.

RESTMCP tool
GET /v1/statelist_state
GET /v1/state/{store}list_state
GET /v1/state/{store}/entries/{key}get_state
PUT /v1/state/{store}/entries/{key}set_state
DELETE /v1/state/{store}/entries/{key}delete_state
GET, PUT, DELETE /v1/state/{store}/entry?key=…The same three operations, with the key in the query string
DELETE /v1/state/{store}Deletes a whole store

An entry can also be addressed with the key in the query string: GET, PUT or DELETE /v1/state/{store}/entry?key=<url-encoded key>, with the same bodies and answers. Prefer it for keys that contain slashes, or two in a row, such as URLs.

Write an entry only if it does not exist
curl -X PUT "$EPHEMERAL_URL/v1/state/example-watch-page/entry?key=https%3A%2F%2Fnews.example.com%2F" \
  -H "Authorization: Bearer $EPHEMERAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value": ["https://news.example.com/a"], "if_version": 0}'

See the Files and state API for every field.

Retention and limits

  • An entry stays until you delete it, its ttl_seconds passes, or the organization's retention policy deletes it. The policy's state_days counts from the entry's last write. Owners and admins set it with PUT /v1/storage/policy.
  • An entry's own ttl_seconds takes precedence over the policy.
  • Any member can read and write state. Do not put secrets in it; use a connection.

What state costs

On the hosted service, state is billed with storage, and each write costs a little:

PartPrice
Stored keys and values$0.04 per GB-month, the same as files
Writes$0.01 per 1,000 writes. Reads and listing are free.

A write the agent makes inside a run counts toward that run's cost and its budget. Writes you make through the API are charged to your credits with your storage. See budgets and billing, including what happens when storage cannot be paid. Self-hosted installations are not charged.

Zero data retention
Zero data retention covers what Ephemeral records about a run: its events, output and definition. Files and state a run is told to save are your storage, kept as your retention settings say.
esc

Nothing matches “”.