डेवलपर hub

Build with every
Swarme capability.

Discover tools, inspect exact schemas, get a price, and run safely through REST or MCP. The same capability contract powers both.

quote-before-run
GET  /api/capabilities?q=...
GET  /api/capabilities/{slug}
POST /api/capabilities/{slug}/quote
POST /api/capabilities/{slug}/run
GET  /api/capability-runs/{run_id}
01 · Core flow

खोज. Describe. Quote. Run.

GET /api/capabilities searches by natural-language query and category. Describe the selected slug before constructing input: its schema is the source of truth for फ़ील्ड, pricing, फ़ाइल requirements, and execution support.

  1. खोजFind candidates with ?q=संपीड़ित%20pdf.
  2. DescribeRead execution.machine_run_status and the input schema.
  3. QuoteConfirm price, wallet clearance, and save the returned quote_id.
  4. चलाएँSend the same input, quote ID, and a unique idempotency key.
curlSelect and copy
export SWARME_API_KEY="YOUR_SWARME_API_KEY"
export SWARME_BASE_URL="https://YOUR_SWARME_HOST"

curl "$SWARME_BASE_URL/api/capabilities?q=संपीड़ित%20pdf&limit=10"
curl "$SWARME_BASE_URL/api/capabilities/compress-pdf"

curl -X POST "$SWARME_BASE_URL/api/capabilities/uuid-generator/quote" \
  -H "Authorization: Bearer $SWARME_API_KEY" -H "Content-Type: application/json" \
  -d '{"input":{},"client_type":"api"}'

curl -X POST "$SWARME_BASE_URL/api/capabilities/uuid-generator/run" \
  -H "Authorization: Bearer $SWARME_API_KEY" \
  -H "Idempotency-Key: YOUR_UNIQUE_REQUEST_ID" -H "Content-Type: application/json" \
  -d '{"input":{},"client_type":"api","quote_id":"YOUR_QUOTE_ID"}'
02 · Controls

Authenticate with least privilege.

बनाएँ a scoped API key from Dashboard → Developers. Send Authorization: Bearer YOUR_SWARME_API_KEY. Never put a key in client-side code, URLs, logs, or a repository.

Scopes

Use only the needed scopes: capabilities:read, capabilities:quote, capabilities:run, uploads:write, artifacts:read, and billing:read.

Spend limits

Each client may have a USD cap. Check GET /api/account/balance before paid work; wallet or spend-limit failures are hard stops.

Idempotency

Use one stable Idempotency-Key per logical quote/run attempt. Replays return the original work; a key cannot safely represent different input. Paid API runs may require it.

Quotes

Quote immediately before execution and pass its quote_id. Surface the price or policy failure से the user.

03 · फ़ाइलें

Use short-lived अपलोड sessions.

बनाएँ a session for the selected slug, अपलोड raw bytes से its returned URL with the dedicated token, then supply अपलोड_id (or अपलोड_ids) in quote and run input. Validate filename, MIME type, and आकार against describe. Never reuse or log an अपलोड token.

curl · अपलोड sessionSelect and copy
# बनाएँ a session. Keep its अपलोड_token private.
curl -X POST "$SWARME_BASE_URL/api/capabilities/compress-pdf/upload-session" \
  -H "Authorization: Bearer $SWARME_API_KEY" -H "Content-Type: application/json" \
  -d '{"input":{"filename":"दस्तावेज़.PDF","content_type":"application/PDF","आकार_bytes":12345},"client_type":"api"}'

# Read अपलोड_url and अपलोड_token from the response, then:
curl -X PUT "YOUR_अपलोड_URL" -H "Authorization: Bearer YOUR_अपलोड_TOKEN" \
  -H "Content-Type: application/PDF" --data-binary @दस्तावेज़.PDF

# Quote and run with अपलोड_id; then poll /api/capability-runs/YOUR_RUN_ID.
04 · Lifecycle

Poll status; cancel cooperatively.

GET /api/capability-runs/{run_id}Read queued, running, retrying, completed, failed, or cancelled state.POST /api/capability-runs/{run_id}/cancelCancel queued work or request cooperative cancellation.GET /api/capability-runs/{run_id}/artifactsList permission-checked artifacts, then follow their डाउनलोड लिंक.

machine_run_status is a safety gate

The canonical values are supported, requires_worker, प्लान_only, and describe_only. supported executes in the declared mode. requires_worker preserves the worker-required response until that runtime is ready. प्लान_only returns a client प्लान without server processing. describe_only blocks quote/run. The legacy value runnable is accepted as supported for backward compatibility. Treat missing or unknown values as describe_only and re-describe before execution.

05 · MCP

The same safe flow, as tools.

Connect a streamable HTTP client से https://swarme.io/hi/mcp. Begin with tools/list; do not assume a cached list.

swarme_capabilities_खोजswarme_capability_describeswarme_account_balanceswarme_टूल_quoteswarme_टूल_runswarme_टूल_statusswarme_टूल_cancelswarme_टूल_artifactsswarme_अपलोड_session_बनाएँ

Inspect machine_run_status after describe. Quote/run only supported, requires_worker, or प्लान_only; refuse describe_only, missing, and unknown values. Keep approval boundaries around paid runs and फ़ाइल access.

MCP client configurationSelect and copy
{
  "mcpServers": {
    "swarme": {
      "type": "streamable-http",
      "url": "https://YOUR_SWARME_HOST/mcp",
      "हेडर": { "Authorization": "Bearer ${SWARME_API_KEY}" }
    }
  }
}
06 · Governance

Version and deprecate contracts explicitly.

The contract manifest inventories REST, MCP tools, execution and run states, quote/run and फ़ाइल lifecycles, errors, and scopes. The machine-readable changelog classifies changes as additive, behavioral-risk, or breaking. Unknown manifest elements fail compatibility checks conservatively.

चलाएँ php bin/check-contract-compatibility.php --baseline=BASELINE.json --candidate=CANDIDATE.json locally or in CI. Breaking changes fail unless their stable change IDs appear in an explicit local approvals फ़ाइल.

Deprecation convention

When deprecation is activated for an element, publish manifest deprecated मेटाडेटा and use standard Deprecation, Sunset, and लिंक: <...>; rel=deprecation हेडर plus Swarme-Contract-Version. The configured target is at least 90 days' notice when practical. It is a governance target—not an SLA—and urgent सुरक्षा, legal, abuse-prevention, or uncontrollable upstream changes may require less notice. This increment configures and दस्तावेज़ the convention only; it does not deprecate or हटाएँ any endpoint.

07 · SDK-free examples

Use any HTTP client.

These examples use environment variables and placeholders only. They contain no credentials. The source distribution also includes copyable, dependency-free examples/rest-agent.php और examples/mcp-agent.php recipes covering खोज through artifacts or cancellation, with an explicit --approve boundary and optional --file=PATH अपलोड.

Before integration, run php bin/check-agent-contract.php against bundled versioned fixtures. Supplying --base-url=URL is explicit and performs only read-only public discovery checks. These are reusable starter clients—not a generated SDK or a frozen SDK API.

TypeScript · Node 18+Select and copy
const baseUrl = process.env.SWARME_BASE_URL ?? "https://YOUR_SWARME_HOST";
const apiKey = process.env.SWARME_API_KEY;
if (!apiKey) throw new Error("Set SWARME_API_KEY");

const request = async (path: string, init: RequestInit = {}) => {
  const response = await fetch(`${baseUrl}${path}`, {
    ...init,
    हेडर: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", ...init.हेडर },
  });
  if (!response.ok) throw new Error(`${response.status}: ${await response.टेक्स्ट()}`);
  return response.json();
};
const described = await request("/api/capabilities/uuid-generator");
const rawStatus = described.capability?.execution?.machine_run_status;
const machineStatus = rawStatus === "runnable" ? "supported" : rawStatus;
const allowedStatuses = new Set(["supported", "requires_worker", "प्लान_only"]);
if (!allowedStatuses.has(machineStatus)) throw new Error("Capability is describe-only; describe again before execution");
const quote = await request("/api/capabilities/uuid-generator/quote", {
  method: "POST", body: JSON.stringify({ input: {}, client_type: "api" }),
});
const run = await request("/api/capabilities/uuid-generator/run", {
  method: "POST", हेडर: { "Idempotency-Key": crypto.randomUUID() },
  body: JSON.stringify({ input: {}, client_type: "api", quote_id: quote.quote.quote_id }),
});
const status = await request(`/api/capability-runs/${run.run_id}`);
Python · requestsSelect and copy
import os, uuid, requests

base_url = os.getenv("SWARME_BASE_URL", "https://YOUR_SWARME_HOST")
api_key = os.environ["SWARME_API_KEY"]
हेडर = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
described = requests.get(f"{base_url}/api/capabilities/uuid-generator", हेडर=हेडर, timeout=30).json()
raw_status = described.get("capability", {}).get("execution", {}).get("machine_run_status")
machine_status = "supported" if raw_status == "runnable" else raw_status
if machine_status not in {"supported", "requires_worker", "प्लान_only"}:
    raise RuntimeError("Capability is describe-only; describe again before execution")
quote = requests.post(
    f"{base_url}/api/capabilities/uuid-generator/quote",
    हेडर=हेडर, json={"input": {}, "client_type": "api"}, timeout=30,
).json()
run = requests.post(
    f"{base_url}/api/capabilities/uuid-generator/run",
    हेडर={**हेडर, "Idempotency-Key": str(uuid.uuid4())},
    json={"input": {}, "client_type": "api", "quote_id": quote["quote"]["quote_id"]}, timeout=30,
).json()
status = requests.get(f"{base_url}/api/capability-runs/{run['run_id']}", हेडर=हेडर, timeout=30).json()