From f0f022b3b864e3736bd236ff626dcfe089fb9b1b Mon Sep 17 00:00:00 2001 From: junhsss Date: Sat, 7 Nov 2026 09:57:46 +0900 Subject: [PATCH] docs: use the SDK in the Commands API guide and drop beta labels --- .../docs/overview/commands-api/overview.mdx | 190 +++++++++++------- content/docs/overview/mcp.mdx | 6 - .../steel-local-vs-steel-cloud.mdx | 4 +- lib/agent-instructions.ts | 2 +- 4 files changed, 118 insertions(+), 84 deletions(-) diff --git a/content/docs/overview/commands-api/overview.mdx b/content/docs/overview/commands-api/overview.mdx index 8cff7b4f..98809632 100644 --- a/content/docs/overview/commands-api/overview.mdx +++ b/content/docs/overview/commands-api/overview.mdx @@ -10,21 +10,30 @@ The Commands API drives a session's browser with high-level commands. Take a sna :::callout type: info -### Beta -The Commands API is in beta. Commands, fields, and limits may change. Share feedback on [Discord](https://discord.gg/steel-dev). +`sessions.commands` needs `steel-sdk` 0.21.0 or later, in TypeScript and Python. ::: -```bash curl -wcn -curl -X POST https://api.steel.dev/v1/sessions/$SESSION_ID/commands \ - -H "steel-api-key: $STEEL_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "commands": [ - { "command": "navigate", "url": "https://example.com" }, - { "command": "snapshot", "interactive": true } - ] - }' + + +```typescript !! Typescript -wcn +const reply = await client.sessions.commands(session.id, { + commands: [ + { command: "navigate", url: "https://example.com" }, + { command: "snapshot", interactive: true }, + ], +}); +``` + +```python !! Python -wcn +reply = client.sessions.commands( + session.id, + commands=[ + {"command": "navigate", "url": "https://example.com"}, + {"command": "snapshot", "interactive": True}, + ], +) ``` + The response has one result per command. The snapshot lists the elements on the page, each with a ref. @@ -43,9 +52,23 @@ The response has one result per command. The snapshot lists the elements on the Send a ref back to act on its element. Pass `next` as `after`, so Steel knows which page state you saw. -```json Request -wcn -{ "after": "op_4f8k2m9q1x", "commands": [{ "command": "click", "target": "e1" }] } + + +```typescript !! Typescript -wcn +await client.sessions.commands(session.id, { + after: "op_4f8k2m9q1x", + commands: [{ command: "click", target: "e1" }], +}); +``` + +```python !! Python -wcn +client.sessions.commands( + session.id, + after="op_4f8k2m9q1x", + commands=[{"command": "click", "target": "e1"}], +) ``` + ### When to use it @@ -60,7 +83,7 @@ You can mix them. A Playwright script and the Commands API can drive the same se ### Quickstart -Create a session, run commands on it, then release it. The SDKs do not have a commands method yet, so these examples call the endpoint over HTTP. +Create a session, run commands on it, then release it. @@ -69,87 +92,62 @@ import Steel from "steel-sdk"; const client = new Steel(); -async function runCommands(sessionId: string, body: object) { - const response = await fetch( - `https://api.steel.dev/v1/sessions/${sessionId}/commands`, - { - method: "POST", - headers: { - "steel-api-key": process.env.STEEL_API_KEY!, - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - }, - ); - return response.json(); -} - const session = await client.sessions.create(); try { - const opened = await runCommands(session.id, { + const opened = await client.sessions.commands(session.id, { commands: [ { command: "navigate", url: "https://example.com" }, { command: "snapshot", interactive: true }, ], }); + if (!("results" in opened)) throw new Error("Expected command results"); console.log(opened.results[1].snapshot); - const clicked = await runCommands(session.id, { + const clicked = await client.sessions.commands(session.id, { after: opened.next, commands: [{ command: "click", target: { role: "link", name: "Learn more" } }], observe: { mode: "snapshot", interactive: true }, }); - console.log(clicked.page.url); - console.log(clicked.observe.snapshot); + if (!("results" in clicked)) throw new Error("Expected command results"); + console.log(clicked.page?.url); + console.log(clicked.observe?.snapshot); } finally { await client.sessions.release(session.id); } ``` ```python !! Python -wcn -import os - -import httpx from steel import Steel client = Steel() - -def run_commands(session_id: str, body: dict) -> dict: - response = httpx.post( - f"https://api.steel.dev/v1/sessions/{session_id}/commands", - headers={"steel-api-key": os.environ["STEEL_API_KEY"]}, - json=body, - timeout=60, - ) - return response.json() - - session = client.sessions.create() try: - opened = run_commands(session.id, { - "commands": [ + opened = client.sessions.commands( + session.id, + commands=[ {"command": "navigate", "url": "https://example.com"}, {"command": "snapshot", "interactive": True}, ], - }) - print(opened["results"][1]["snapshot"]) - - clicked = run_commands(session.id, { - "after": opened["next"], - "commands": [{"command": "click", "target": {"role": "link", "name": "Learn more"}}], - "observe": {"mode": "snapshot", "interactive": True}, - }) - print(clicked["page"]["url"]) - print(clicked["observe"]["snapshot"]) + ) + print(opened.results[1].snapshot) + + clicked = client.sessions.commands( + session.id, + after=opened.next, + commands=[{"command": "click", "target": {"role": "link", "name": "Learn more"}}], + observe={"mode": "snapshot", "interactive": True}, + ) + print(clicked.page.url) + print(clicked.observe.snapshot) finally: client.sessions.release(session.id) ``` -The click uses a locator, so the example does not depend on a ref number. An agent usually reads the snapshot and sends the ref it picked. +The click uses a locator, so the example does not depend on a ref number. An agent usually reads the snapshot and sends the ref it picked. In TypeScript, the response type also covers the answer to a `dialog` command, so check for `results` before you read them. ### Snapshots and refs @@ -257,11 +255,14 @@ A failed command still returns `200`. Its error is in `results`, and the executi Every response has a `next` value. Send it as `after` in your next request. A retried request with the same `after` and commands then runs only once. If another Commands API client changed the session in between, the response sets `epochChanged: true`. -```typescript Typescript -wcn + + +```typescript !! Typescript -wcn let after: string | undefined; -async function step(commands: object[]) { - const reply = await runCommands(session.id, { after, commands }); +async function step(commands: Steel.Command[]) { + const reply = await client.sessions.commands(session.id, { after, commands }); + if (!("results" in reply)) throw new Error("Expected command results"); after = reply.next; if (reply.epochChanged) { console.log("Another client changed the page. Take a new snapshot."); @@ -270,18 +271,50 @@ async function step(commands: object[]) { } ``` +```python !! Python -wcn +from steel import omit + +after = omit + + +def step(commands): + global after + reply = client.sessions.commands(session.id, after=after, commands=commands) + after = reply.next + if reply.epoch_changed: + print("Another client changed the page. Take a new snapshot.") + return reply +``` + + ### Retry safely -Send a random `Idempotency-Key` header with each request, and reuse it when you retry that request. A retry with the same key returns the stored result with `replayed: true` instead of running the commands again. +Send a random `Idempotency-Key` with each request, and reuse it when you retry that request. A retry with the same key returns the stored result with `replayed: true` instead of running the commands again. + + + +```typescript !! Typescript -wcn +import { randomUUID } from "node:crypto"; -```bash curl -wcn -curl -X POST https://api.steel.dev/v1/sessions/$SESSION_ID/commands \ - -H "steel-api-key: $STEEL_API_KEY" \ - -H "Content-Type: application/json" \ - -H "Idempotency-Key: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d" \ - -d '{ "commands": [{ "command": "click", "target": "e4" }] }' +const reply = await client.sessions.commands(session.id, { + commands: [{ command: "click", target: "e4" }], + "idempotency-key": randomUUID(), +}); ``` +```python !! Python -wcn +import uuid + +reply = client.sessions.commands( + session.id, + commands=[{"command": "click", "target": "e4"}], + idempotency_key=str(uuid.uuid4()), +) +``` + + +The SDKs retry `429` and `503` responses on their own, two times by default, with the same key. Without a key or `after`, a retry after a `503` can run the commands twice. + | Status | Code | What to do | | --- | --- | --- | | `503` | `delivery_failed` | Steel could not reach the browser, so the commands may or may not have run. Retry with the same key. | @@ -338,11 +371,18 @@ Answer it with the `dialog` command. Pass `text` to answer a prompt. Then download the file from the session's files: -```bash curl -wcn -curl https://api.steel.dev/v1/sessions/$SESSION_ID/files/report.csv \ - -H "steel-api-key: $STEEL_API_KEY" \ - -o report.csv + + +```typescript !! Typescript -wcn +const response = await client.sessions.files.download(session.id, "report.csv"); +const csv = await response.text(); +``` + +```python !! Python -wcn +response = client.sessions.files.download("report.csv", session_id=session.id) +csv = response.text() ``` + ### Next steps diff --git a/content/docs/overview/mcp.mdx b/content/docs/overview/mcp.mdx index d8938d4b..8dae1922 100644 --- a/content/docs/overview/mcp.mdx +++ b/content/docs/overview/mcp.mdx @@ -8,12 +8,6 @@ publishedAt: "2026-11-05" The Steel MCP server gives any MCP client cloud browsers. An agent can read a page in one call, or start a session and click, type, and fill forms in a real browser. Steel hosts the server, so there is nothing to install or run. -:::callout -type: info -### Beta -The MCP server is in beta. Tools, fields, and limits may change. Share feedback on [Discord](https://discord.gg/steel-dev). -::: - ```bash Claude Code -wcn claude mcp add --transport http steel https://mcp.steel.dev/mcp ``` diff --git a/content/docs/overview/self-hosting/steel-local-vs-steel-cloud.mdx b/content/docs/overview/self-hosting/steel-local-vs-steel-cloud.mdx index 38f16879..cab18b7f 100644 --- a/content/docs/overview/self-hosting/steel-local-vs-steel-cloud.mdx +++ b/content/docs/overview/self-hosting/steel-local-vs-steel-cloud.mdx @@ -15,8 +15,8 @@ llm: true | Credentials | Not supported | Supported with the Credentials API | | Extensions | Supported by loading in `api/extensions/` | Supported by using the Extensions API | | Files | Not supported | Supported by the Files API | -| Commands API | Off by default. Set `ENABLE_COMMANDS_API=true` | Supported by the Commands API (beta) | -| MCP Server | Not supported | Hosted at `https://mcp.steel.dev/mcp` (beta) | +| Commands API | Off by default. Set `ENABLE_COMMANDS_API=true` | Supported by the Commands API | +| MCP Server | Not supported | Hosted at `https://mcp.steel.dev/mcp` | The defining factor between running Steel locally and using Steel Cloud is concurrency. diff --git a/lib/agent-instructions.ts b/lib/agent-instructions.ts index 5cd81d17..a10b970c 100644 --- a/lib/agent-instructions.ts +++ b/lib/agent-instructions.ts @@ -46,7 +46,7 @@ export const AGENT_INSTRUCTIONS = `# Steel Documentation await browser.close(); await client.sessions.release(session.id); \`\`\` -- For agent-style browser control over plain HTTP, use the Commands API (beta). Take a snapshot, then act on the refs in it: +- For agent-style browser control over plain HTTP, use the Commands API. Take a snapshot, then act on the refs in it: \`\`\` curl -X POST https://api.steel.dev/v1/sessions/SESSION_ID/commands \\ -H "steel-api-key: YOUR_KEY" \\