Skip to content
RehearsalDocs

TypeScript SDK

The TypeScript client in the rehearsal-kit npm package. Every resource and method, with its arguments and the API operation it calls.

The rehearsal-kit package on npm is the TypeScript edition of the Python package: the same client, the same rehearsal command and the same MCP server. It needs Node.js 20 or later, and works with npm, pnpm and bun.

npm install rehearsal-kit
import { Rehearsal } from "rehearsal-kit";

const rh = new Rehearsal();
const run = await rh.evaluations.create("<wv_id>", ["<profile_id>"], ["dev"], 2);
for await (const event of rh.runs.events(run.run_id)) console.log(event.type, event.summary);
console.log((await rh.runs.get(run.run_id)).summary);

Every method returns a promise of the JSON of the API's answer. As in Python, the client adds no types of its own for answers, so a field that the API adds is there at once. Method names are the Python names in camelCase: rh.applications.importCatalog is rh.applications.import_catalog.

The client

new Rehearsal({ apiKey, baseUrl, timeout, fetch })
OptionMeaning
apiKeyThe key. Without it: the environment variable REHEARSAL_API_KEY, then the sign-in that rehearsal login saved
baseUrlThe server. Without it: REHEARSAL_URL, then the saved sign-in, then https://rehearsalkit.xyz
timeoutSeconds to wait for one request
fetchA fetch function to use instead of the global one, for example in tests

With no key anywhere, the constructor throws an Error that says how to sign in.

Errors

A request that the server refuses throws RehearsalError. It has two fields: status, the HTTP status, and detail, the server's message. Errors lists them.

import { RehearsalError } from "rehearsal-kit";

try {
  await rh.evaluations.create("<wv_id>", ["<profile_id>"]);
} catch (error) {
  if (error instanceof RehearsalError && error.status === 402) console.log(error.detail); // the plan does not cover it: do not retry
  else throw error;
}

Any operation

MethodDoes
rh.get(path, params?)A GET. Resolves to the JSON
rh.post(path, body)A POST with a JSON body. Resolves to the JSON
rh.stream(path, cursor = 0)An async iterator of a stream's events. It reconnects from the last event after a lost connection; leaving the loop closes it
rh.download(path)A file, such as an exported artifact, as a Uint8Array

rh.applications

rh.applications.create

rh.applications.create(name: string, source: Json, images: Record<string, string> = {}, policies = "")

Adds an application. source is {"kind": "git", "url": ..., "commit": ...}, and images maps each service to a pinned image.

Calls POST /v1/applications.

rh.applications.importCatalog

rh.applications.importCatalog()

Adds the eight sample applications. Returns them as a list.

Calls POST /v1/applications/import-catalog.

rh.applications.list

rh.applications.list()

The applications of the project.

Calls GET /v1/applications.

rh.applications.get

rh.applications.get(appId: string)

One application.

Calls GET /v1/applications/<app_id>.

rh.applications.uploadSource

rh.applications.uploadSource(appId: string, archive: string)

Uploads a .tar.gz of the source, for an application added with the source kind upload.

Calls POST /v1/applications/<app_id>/source.

rh.worlds

rh.worlds.build

rh.worlds.build(applicationId: string, options: Json = {})

Starts a build. It spends model budget. Options are the fields of the request body, for example scenario_target=8 and budget_usd=6. Returns job_id and world_version_id.

Calls POST /v1/world-builds.

rh.worlds.makeAgent

rh.worlds.makeAgent(worldVersionId: string, options: { name?: string; rounds?: number; repeats?: number } = {})

Agent Factory: drafts an agent from a published world, hardens it with the fix loop and proves it on held-out jobs. Returns job_id and episodes; the finished job's result has every score and artifact_id, the zip to download.

Calls POST /v1/factory.

rh.worlds.list

rh.worlds.list()

The worlds, each with its versions.

Calls GET /v1/worlds.

rh.worlds.reportIncident

rh.worlds.reportIncident(wvId: string, incident: string)

Turns a production incident (what was asked, what the agent did, what should have happened) into a job in this world. The job is validated like any other and, once valid, joins the dev split, so later evaluations and gates check for it. Returns the job to follow.

Calls POST /v1/world-versions/<wv_id>/incidents.

rh.worlds.library

rh.worlds.library()

Ready-made worlds from the world library: the latest published version of each, with its job counts and tools. Any workspace can evaluate an agent on them, or make one, without building a world.

Calls GET /v1/library.

rh.worlds.version

rh.worlds.version(wvId: string)

One world version.

Calls GET /v1/world-versions/<wv_id>.

rh.worlds.scenarios

rh.worlds.scenarios(wvId: string)

The jobs of a world version.

Calls GET /v1/world-versions/<wv_id>/scenarios.

rh.worlds.validate

rh.worlds.validate(wvId: string)

Re-checks a published world. It spends model budget. Returns a job.

Calls POST /v1/world-versions/<wv_id>/validate.

rh.worlds.bundle

rh.worlds.bundle(wvId: string, includeImages = false)

Exports a world version as a bundle file. Returns a job.

Calls POST /v1/world-versions/<wv_id>/bundle.

rh.jobs

rh.jobs.get

rh.jobs.get(jobId: string)

One server job: status, spent_usd, completed_phases, result, error.

Calls GET /v1/jobs/<job_id>.

rh.jobs.command

rh.jobs.command(jobId: string, command: Command | string)

pause, resume, stop or retry.

Calls POST /v1/jobs/<job_id>/commands.

rh.jobs.events

rh.jobs.events(jobId: string, cursor = 0)

The job's events, one at a time, until the job ends. It reconnects after a lost connection.

Calls GET /v1/jobs/<job_id>/events.

rh.jobs.wait

rh.jobs.wait(jobId: string, options: { timeoutS?: number; pollS?: number } = {})

Asks every few seconds until the job has ended, and returns it. Raises TimeoutError after timeout_s.

rh.profiles

rh.profiles.create

rh.profiles.create(name: string, systemPrompt = "", fields: Json = {})

Creates an agent profile. More fields go as keywords, for example model=... or driver="external".

Calls POST /v1/agent-profiles.

rh.profiles.list

rh.profiles.list()

The agent profiles, every version.

Calls GET /v1/agent-profiles.

rh.profiles.autofix

rh.profiles.autofix(profileId: string, runId: string, options: { rounds?: number; repeats?: number } = {})

Starts the fix loop on a finished run: rounds of propose and rehearse on train and dev, then the best version against the original on held-out jobs. Returns job_id and episodes; the finished job's result has every round.

Calls POST /v1/autofix.

rh.evaluations

rh.evaluations.create

rh.evaluations.create(worldVersionId: string, profileIds: string[], splits?: string[] | null, repeats?: number | null, fields: Json = {})

Starts a run. It spends model budget. Returns run_id and episodes.

Calls POST /v1/evaluations.

rh.evaluations.compare

rh.evaluations.compare(runA: string, runB?: string | null)

Compares the agents in one run, or two runs on the same world version.

Calls GET /v1/compare.

rh.runs

rh.runs.get

rh.runs.get(runId: string)

One run, with its status and summary.

Calls GET /v1/runs/<run_id>.

rh.runs.episodes

rh.runs.episodes(runId: string)

The episodes of a run.

Calls GET /v1/runs/<run_id>/episodes.

rh.runs.failures

rh.runs.failures(runId: string)

Why episodes failed, per agent: named causes, each with its count, what it means, its usual fix, example episodes and the checks that failed. Needs evaluator access.

Calls GET /v1/runs/<run_id>/failures.

rh.runs.episode

rh.runs.episode(epId: string)

One episode in full.

Calls GET /v1/episodes/<ep_id>.

rh.runs.events

rh.runs.events(runId: string, cursor = 0)

The run's events, one at a time, until the run ends.

Calls GET /v1/runs/<run_id>/events.

rh.runs.intervene

rh.runs.intervene(epId: string, body: Json)

Changes a running episode by hand. The keywords are the fields of the request body, for example kind="customer_message", text=....

Calls POST /v1/episodes/<ep_id>/interventions.

rh.runs.command

rh.runs.command(runId: string, command: Command | string)

pause, resume or stop, for every part of the run.

Calls POST /v1/runs/<run_id>/commands.

rh.external

rh.external.observation

rh.external.observation(epId: string)

The turn that waits for your agent in an episode, if one does.

Calls GET /v1/episodes/<ep_id>/observation.

rh.external.act

rh.external.act(epId: string, actor: string, tool: string, args: Json, idempotencyKey: string, waitS = 120)

Sends one action and waits for its result, which it returns. Raises TimeoutError after wait_s; ask again with the same key.

Calls POST /v1/episodes/<ep_id>/actions, then GET /v1/episodes/<ep_id>/actions/<idempotency_key>.

The command and the MCP server

The package installs the same rehearsal command as the Python package, with the same commands, arguments and exit codes; see CLI. Commands that run a server (serve, worker, up, migrate, bootstrap, users, openapi, prices) need the Python server package. rehearsal mcp, or npx -y rehearsal-kit mcp, runs the MCP server with the same tools. To embed it: import { buildServer } from "rehearsal-kit/mcp".

The saved sign-in

Both packages read and write the same file, so signing in with either one signs in the other. Both functions are exported by rehearsal-kit.

FunctionDoes
configPath()Where the file is: ~/.config/rehearsal/config.json, or the path in REHEARSAL_CONFIG
savedLogin()The saved url and api_key, or an empty object
Generated from the code of rehearsal-kit 0.1.4.

Was this page helpful?

On this page

Was this page helpful?