Skip to content

API quickstart

Resolve a PR, generate a guide, and read the result from a script.

This walk-through generates a guide for example/project#42 from a shell script: resolve the PR to a changeset, start a run, wait for it to finish, and read the guide.

Before you start

Link to this section

You need curl, jq, uuidgen and a signed-in CLI. Theseus must already know the PR: the resolve call looks up existing changesets and doesn't register new ones, so generate a guide for the PR once in the app or CLI if you haven't.

Each request block below runs in a subshell that stops on the first HTTP or JSON failure, without changing your shell's options. Go on to the next step only when the previous one succeeds.

1. Create a scoped token

Link to this section

Replace example-team with your workspace:

theseus token create --name "PR automation" \
  --scope read --scope runs:write --workspace example-team

Approve the request in the browser, then load the printed secret into THESEUS_API_TOKEN from your secret store. Don't paste it into a committed script. Authentication and scopes covers repository restrictions and revocation.

2. Resolve the PR

Link to this section

Replace the repository, PR number and workspace with your own:

(
set -eu
curl --fail-with-body --get \
  -H "Authorization: Bearer $THESEUS_API_TOKEN" \
  --data-urlencode "repository=example/project" \
  --data-urlencode "pr=42" \
  --data-urlencode "workspace=example-team" \
  https://app.theseus.dev/api/v1/changesets/resolve > changeset.json
jq '{id, repository: .repository.id, latest_guide, behind_head}' changeset.json
)

The response has the changeset id, repository.id, the app url and latest_guide, the newest ready guide. behind_head: true means the PR has commits that guide doesn't cover; null means there's no ready guide to compare yet. not_found means no changeset you can see matches: check the workspace and your access.

3. Start a run

Link to this section

A run spends one guide from the workspace's allowance, so make retries safe with an Idempotency-Key. Create the key once, for this run only. The command refuses to overwrite an existing key file:

(umask 077; set -euC; uuidgen > theseus-run-key.txt)

If you can't tell whether the request succeeded, rerun only the block below: the same key returns the same run and spends nothing more. To start another run on purpose, delete the key file or work in a new directory.

(
set -eu
repository_id=$(jq -er '.repository.id | select(type == "string" and startswith("rep_"))' changeset.json)
test -s theseus-run-key.txt
run_key=$(cat theseus-run-key.txt)
curl --fail-with-body --request POST \
  -H "Authorization: Bearer $THESEUS_API_TOKEN" \
  -H "Idempotency-Key: $run_key" \
  -H "Content-Type: application/json" \
  --data '{}' \
  "https://app.theseus.dev/api/v1/repositories/$repository_id/changesets/pr/42/runs" > run.json
jq '{id, status, guide_id}' run.json
)

Use the same PR number as step 2. A 202 means the run was accepted, not that the guide is ready:

{
  "id": "run_01ARZ3NDEKTSV4RRFFQ69G5FAV",
  "status": "queued",
  "error": null,
  "changeset_id": "set_01K6Z3M4N5P6Q7R8S9T0V1W2X3",
  "guide_id": "ver_01K6Z3M4N5P6Q7R8S9T0V1W2X3",
  "created_at": "2026-10-08T12:00:00Z",
  "finished_at": null
}

The start-run reference lists conflicts and plan limits.

4. Wait for the run, then read the guide

Link to this section
(
set -eu
run_id=$(jq -er '.id | select(type == "string" and length > 0)' run.json)
curl --fail-with-body \
  -H "Authorization: Bearer $THESEUS_API_TOKEN" \
  "https://app.theseus.dev/api/v1/runs/$run_id" > run-status.json
jq '{status, error, guide_id}' run-status.json
)

Repeat while status is queued or running, backing off between checks to stay under the rate limit. failed comes with an error. Once it's succeeded, read the guide:

(
set -eu
guide_id=$(jq -er 'select(.status == "succeeded") | .guide_id | select(type == "string" and length > 0)' run-status.json)
curl --fail-with-body \
  -H "Authorization: Bearer $THESEUS_API_TOKEN" \
  "https://app.theseus.dev/api/v1/guides/$guide_id"
)

This returns the guide from your run, even if a later push starts another. From here:

  • List the guide's changes, or open the url from changeset.json to review in the app.
  • Subscribe to events instead of polling.