Skip to content

An open-source, faster Devin alternative

TypeScript

docs(agent-sessions): tab the remaining examples — TypeScript SDK (default) + REST

Igor Zalutski6b5d9cbb6bcc
diff --git a/docs/agent-sessions/agents.mdx b/docs/agent-sessions/agents.mdx
index 32ebed5a..ad916009 100644
--- a/docs/agent-sessions/agents.mdx
+++ b/docs/agent-sessions/agents.mdx
@@ -5,7 +5,23 @@ description: "Reusable agent configuration"
An **agent** is reusable configuration: `name`, `prompt`, `model`, and [`runtime`](/agent-sessions/runtimes). Every [session](/agent-sessions/sessions) runs on an agent, so create one first, then start as many sessions on it as you like.
-```http
+<CodeGroup>
+
+```ts TypeScript
+import { OpenComputer } from "@opencomputer/sdk";
+
+const oc = new OpenComputer({ apiKey: process.env.OPENCOMPUTER_API_KEY! });
+
+const agent = await oc.agents.create({
+ name: "reviewer",
+ runtime: "claude",
+ model: "anthropic/claude-opus-4-8",
+ prompt: "Review the repo. Run tests. Summarize risks.",
+ key: "sk-ant-...",
+});
+```
+
+```http REST
POST https://api.opencomputer.dev/v3/agents
Authorization: Bearer $OPENCOMPUTER_API_KEY
Content-Type: application/json
@@ -19,6 +35,8 @@ Content-Type: application/json
}
```
+</CodeGroup>
+
Pass your Anthropic `key` inline and it's stored as a [credential](/agent-sessions/authentication#model-credentials) and attached to the agent — sessions run the model on it. Already have a credential? Reference it with `credential: "cred_…"` instead, or omit both to use your org default. Optionally set default [`limits`](/agent-sessions/sessions#limits) (`tokens`/`turn_seconds`/`turns`) too; sessions inherit them.
<Tip>Keep the org key and model key on your backend. Only return session-scoped client tokens to browsers.</Tip>
diff --git a/docs/agent-sessions/authentication.mdx b/docs/agent-sessions/authentication.mdx
index 4e3a94e7..402b92bc 100644
--- a/docs/agent-sessions/authentication.mdx
+++ b/docs/agent-sessions/authentication.mdx
@@ -9,7 +9,20 @@ Durable Agent Sessions use three credential types.
Your account key. Use it server-side for all **management** calls — creating agents, starting sessions, registering webhooks, managing credentials.
-```http
+<CodeGroup>
+
+```ts TypeScript
+import { OpenComputer } from "@opencomputer/sdk";
+
+const oc = new OpenComputer({ apiKey: process.env.OPENCOMPUTER_API_KEY! }); // org key, server-side only
+
+const session = await oc.sessions.create({
+ agent: "agt_...",
+ input: "Run the tests and summarize failures.",
+});
+```
+
+```http REST
POST https://api.opencomputer.dev/v3/sessions
Authorization: Bearer $OPENCOMPUTER_API_KEY
Content-Type: application/json
@@ -17,6 +30,8 @@ Content-Type: application/json
{ "agent": "agt_...", "input": "Run the tests and summarize failures." }
```
+</CodeGroup>
+
<Warning>Never ship the org API key to a browser or mobile client — it can do anything on your account. Use a client token instead.</Warning>
## Client tokens
@@ -25,7 +40,18 @@ A **session-scoped, short-lived** token with `read` + `steer` scope — safe to
You get one back from `POST /v3/sessions`, and can mint more:
-```http
+<CodeGroup>
+
+```ts TypeScript
+const session = await oc.sessions.get("sess_...");
+
+const clientToken = await session.mintClientToken({
+ scopes: ["read", "steer"],
+ ttlSeconds: 3600,
+});
+```
+
+```http REST
POST https://api.opencomputer.dev/v3/sessions/sess_.../client-tokens
Authorization: Bearer $OPENCOMPUTER_API_KEY
Content-Type: application/json
@@ -33,6 +59,8 @@ Content-Type: application/json
{ "scopes": ["read", "steer"], "ttl": 3600 }
```
+</CodeGroup>
+
Browser pattern: your backend creates the session with the org key, then hands the `client_token` to the browser, which uses it directly for the SSE stream and steer calls.
<Warning>A client token isn't free to hand out: each `steer` starts a turn, which **consumes tokens on your Anthropic key** for the session it's scoped to. Mint short-lived tokens, and rely on the session's [limits](/agent-sessions/sessions#limits) (`tokens`/`turn_seconds`/`turns`) to cap exposure.</Warning>
@@ -52,7 +80,17 @@ Sessions run the model on **your own Anthropic key**. It's held in OpenComputer'
The easiest way to add one is inline when you [create an agent](/agent-sessions/agents) (`"key": "sk-ant-…"`). The standalone resource below is for reusing one key across agents, setting an org default, and rotating/removing keys:
-```http
+<CodeGroup>
+
+```ts TypeScript
+await oc.credentials.create({
+ provider: "anthropic",
+ key: "sk-ant-...",
+ name: "prod",
+});
+```
+
+```http REST
POST https://api.opencomputer.dev/v3/credentials
Authorization: Bearer $OPENCOMPUTER_API_KEY
Content-Type: application/json
@@ -60,7 +98,18 @@ Content-Type: application/json
{ "provider": "anthropic", "key": "sk-ant-...", "name": "prod" }
```
-```http
+</CodeGroup>
+
+<CodeGroup>
+
+```ts TypeScript
+await oc.credentials.setDefault({
+ provider: "anthropic",
+ credential: "cred_...",
+});
+```
+
+```http REST
PUT https://api.opencomputer.dev/v3/credentials/default
Authorization: Bearer $OPENCOMPUTER_API_KEY
Content-Type: application/json
@@ -68,6 +117,8 @@ Content-Type: application/json
{ "credential": "cred_..." }
```
+</CodeGroup>
+
**Resolution** per session: the agent's credential → your org default for the provider. (No platform-billed fallback yet — bring a key.)
<Note>Additional model providers, model hot-swap, and platform-billed usage are coming soon — they use this same credential shape, so your setup won't change.</Note>
diff --git a/docs/agent-sessions/messaging.mdx b/docs/agent-sessions/messaging.mdx
index 92aeb151..16ca5143 100644
--- a/docs/agent-sessions/messaging.mdx
+++ b/docs/agent-sessions/messaging.mdx
@@ -9,7 +9,16 @@ description: "Steer a session, and the shared message envelope"
Send a message to a running or idle session; it wakes and continues with its prior context. Minimal form is just text:
-```http
+<CodeGroup>
+
+```ts TypeScript
+import { connectSession } from "@opencomputer/sdk";
+
+const live = await connectSession({ sessionId, clientToken });
+await live.steer("also check the CI config", { idempotencyKey: "msg_01" });
+```
+
+```http REST
POST https://api.opencomputer.dev/v3/sessions/sess_.../messages
Authorization: Bearer $CLIENT_TOKEN
Content-Type: application/json
@@ -20,6 +29,8 @@ Content-Type: application/json
}
```
+</CodeGroup>
+
Pass `idempotency_key` so retries (flaky network, double-click) are de-duplicated — applied at most once **per session**, so the same key is safe to reuse across different sessions.
## Message envelope
diff --git a/docs/agent-sessions/sessions.mdx b/docs/agent-sessions/sessions.mdx
index e2a861e4..15057645 100644
--- a/docs/agent-sessions/sessions.mdx
+++ b/docs/agent-sessions/sessions.mdx
@@ -31,11 +31,23 @@ A session also carries `last_turn = { id, state, yield_reason?, result_event_id?
Do not infer completion from prose. Await the **`turn.completed`** event (on the [stream](/agent-sessions/events) or a [webhook](/agent-sessions/webhooks)), then fetch the answer:
-```http
+<CodeGroup>
+
+```ts TypeScript
+import { OpenComputer } from "@opencomputer/sdk";
+
+const oc = new OpenComputer({ apiKey: process.env.OPENCOMPUTER_API_KEY! });
+const session = await oc.sessions.get("sess_...");
+const { lastTurn, result } = await session.result();
+```
+
+```http REST
GET https://api.opencomputer.dev/v3/sessions/sess_.../result
Authorization: Bearer $OPENCOMPUTER_API_KEY
```
+</CodeGroup>
+
Response:
```json
diff --git a/docs/agent-sessions/webhooks.mdx b/docs/agent-sessions/webhooks.mdx
index 9a55700d..adcd31cf 100644
--- a/docs/agent-sessions/webhooks.mdx
+++ b/docs/agent-sessions/webhooks.mdx
@@ -7,7 +7,23 @@ Register a **destination** and a session's [events](/agent-sessions/events) are
## Destinations
-```http
+<CodeGroup>
+
+```ts TypeScript
+import { OpenComputer } from "@opencomputer/sdk";
+
+const oc = new OpenComputer({ apiKey: process.env.OPENCOMPUTER_API_KEY! });
+const session = await oc.sessions.get(sessionId);
+
+await session.destinations.create({
+ url: "https://your.app/oc-webhook",
+ secret: "whsec_...",
+ level: "user",
+ includeRaw: false,
+});
+```
+
+```http REST
POST https://api.opencomputer.dev/v3/sessions/sess_.../destinations
Authorization: Bearer $OPENCOMPUTER_API_KEY
Content-Type: application/json
@@ -20,6 +36,8 @@ Content-Type: application/json
}
```
+</CodeGroup>
+
`level` is the visibility threshold (`user` default, or `progress`); `types` is an optional event-type allow-list (default: all — which **includes the terminal `turn.completed`**); `include_raw: false` strips `body.raw` from the delivered Event. To get only completions, set `types: ["turn.completed"]`.
| Method · Path | Purpose |