Quick start for a developer
Call a machine tool from your own program: one HTTPS request per call, an agent token per program.
Preview. The /api/v1 routes with agent tokens ship with the next server release. The TypeScript and Python SDKs are not published yet.
Before you start
- A machine online on your page, and an agent token for your program from the Agents tab, in the
environment as
CMDOP_TOKEN. Never put the token in a URL or in code you commit.
Steps
-
List the machines:
curl -sS "https://<contour>.cmdop.ai/api/v1/machines" \ -H "Authorization: Bearer $CMDOP_TOKEN" -
Call a tool. The answer is
{"ok": <result>}or{"error": {"code", "message"}}:curl -sS -X POST "https://<contour>.cmdop.ai/api/v1/call" \ -H "Authorization: Bearer $CMDOP_TOKEN" \ -H "Content-Type: application/json" \ -d '{"machine":"<machine>","tool":"sys_info","args":{}}' -
From TypeScript, the same call with
fetch:const res = await fetch(`https://${contour}.cmdop.ai/api/v1/call`, { method: "POST", headers: { Authorization: `Bearer ${process.env.CMDOP_TOKEN}`, "Content-Type": "application/json" }, body: JSON.stringify({ machine, tool: "sys_info", args: {} }), }); const answer = (await res.json()) as { ok?: unknown; error?: { code: string; message: string } }; if (answer.error) throw new Error(`${answer.error.code}: ${answer.error.message}`); -
Stream a command’s output with
POST /api/v1/call/stream: one JSON line per piece of output, then the answer as the last line.
Check
Step 2 answers {"ok": {...}} with the machine’s operating system and user. On an error, act on
error.code: Errors.
Next
- Every route: HTTP API. Every tool: Tools.
- Using CMDOP inside your product: embed CMDOP.