Programmatic API
Create a least-privilege API key, authenticate a server-to-server integration, and work safely with the v1 host, session, audit and team endpoints.
Before you start
- Use an organization workspace with the API entitlement and a role permitted to manage API keys.
- Decide the smallest set of resources and scopes your server-side integration actually needs.
- Prepare an approved secret manager and an HTTPS-capable runtime; do not expose a live key in client-side code.
Let’s walk through it.
- 01
Create a purpose-specific key
Open My Page → API Keys, choose Create API Key, give it a name that identifies its integration and environment, select only the required scopes, and choose an expiry. Copy the secret immediately; it is shown only once.
- 02
Store the secret outside your code
Put the sm_live_ key in the deployment platform's secret manager or another approved secret store. Never put it in a browser, repository, ticket, shell history or application configuration committed to source control.
- 03
Verify identity first
Call GET /api/v1/me with Authorization: Bearer followed by the key. Confirm the returned organization, key name and granted scopes before the integration reads or writes resources.
- 04
Use the matching scoped endpoint
Use GET /hosts and GET /hosts/:hostId for visible host metadata, GET /sessions for active sessions, GET /audits for connection-audit records, and GET /team for member and resolved-role inventory. Use POST /hosts only when your client can create the required encrypted address envelopes.
- 05
Rotate deliberately
Create a replacement key, deploy it, verify it with /me, observe the integration, then revoke the old key. Revocation and expiry deny later requests immediately.
What success looks like
Your integration authenticates with a least-privilege key, verifies its organization and scopes through /api/v1/me, and handles documented success and error responses without exposing secrets.
Good to know.
Base URL and authentication
The public programmatic surface is /api/v1 on the same ShellMate origin used by your organization. Send either Authorization: Bearer sm_live_… or X-API-Key: sm_live_… on every request, not both. The API is for server-to-server use; it is separate from browser, desktop and internal v3 endpoints.
Scopes and current access
hosts:read reads hosts and needs hosts.view; hosts:write creates encrypted-envelope hosts and needs hosts.create; sessions:read reads active sessions and needs sessions.manage; audits:read reads connection audits and needs logs.view; team:read reads member inventory and needs team.manage. A scope never bypasses the key creator's current role, organization entitlement or host visibility.
Requests, responses and pagination
Collection reads accept limit and offset. Limit defaults to 50, is at least 1 and is capped at 200; offset defaults to 0. Collection responses contain data and pagination; the hosts response also includes total. Successful host detail responses contain data. /me returns key identity, granted scopes and organization identity. Error responses contain an error and usually a stable code, such as API_KEY_REQUIRED, INVALID_API_KEY, INSUFFICIENT_SCOPE, ROLE_PERMISSION_DENIED, HOST_NOT_FOUND or V2_CIPHERTEXT_REQUIRED.
Encrypted host creation
POST /hosts requires a client-generated UUID plus hostEnc and portEnc encrypted envelopes. Plaintext host, ip and port input is rejected, and the endpoint forces shared pending enrollment. It is not a server-side encryption service. Generate the envelopes with the compatible ShellMate client crypto contract; do not try to transform or log them as addresses.
Safe failure handling
Do not blindly retry a 400, 403, 404 or 409 response. Fix the request or access condition first. For a 500, use bounded exponential backoff and preserve the endpoint, UTC time, HTTP status and safe error code for support. The API has no webhook or idempotency-key contract, so POST /hosts retries must avoid duplicate creation.
Full reference
The complete request and response examples, endpoint field descriptions, error matrix and operational guidance are maintained in the Programmatic API reference bundled with the ShellMate source distribution at docs/api/PROGRAMMATIC_API.md. The API Keys page links to this guide for the customer-facing workflow.
A few common questions.
Why does a valid-looking key return 401?
Check that the full secret is present in one supported header, that it has not expired or been revoked, and that the key creator remains active in the same organization. Do not paste the secret into a support request.
Why does a request return INSUFFICIENT_SCOPE or ROLE_PERMISSION_DENIED?
The API requires both the selected key scope and the current role permission of the person who created it. Grant only the needed scope and have an administrator review the creator's organization role.
Can I create a host with an IP address or port in JSON?
No. The v1 API rejects plaintext address and port fields. Only use POST /hosts when your integration can produce the required encrypted hostEnc and portEnc envelopes through the supported client crypto contract.