Interactive clients use OAuth 2.1 with PKCE. Headless CI and service environments can use the operator's sk_live_* key when they cannot complete a browser flow, but the key carries operator-wide access.
npx @getstackrun/cli auth loginOpens a browser, asks you to approve the device, and stores a refresh token at ~/.stack/credentials.json with mode 0600. On Linux and macOS the CLI sets the file to mode 0600; on Windows it inherits the access controls on %USERPROFILE%\.stack.
Subsequent runs read the refresh token, exchange it for a one-hour access token, and rotate the refresh on use. npx @getstackrun/cli auth status shows the current sign-in state, while npx @getstackrun/cli auth logout revokes the refresh and clears the file.
Add STACK as a remote MCP server with the URL below. The client starts the OAuth flow. Approve the requested scopes in your browser.
https://mcp.getstack.run/mcpUse the client-specific integration guide when you need its exact command or settings path.
On the first call, the MCP server returns 401 Unauthorized with a WWW-Authenticate: Bearer resource_metadata=... header pointing at /.well-known/oauth-protected-resource. The MCP client picks that up, starts the OAuth flow, and stores the resulting tokens in its own credential store.
For interactive development:
import { Stack } from '@getstackrun/sdk';
const stack = new Stack(); // reads ~/.stack/credentials.json
const agents = await stack.agents.list();For an enrolled agent runtime:
const stack = new Stack({ agent_id: 'agt_xxx' });
// First run: generates an Ed25519 keypair locally, runs proof-of-possession
// enrollment via /v1/agents/<id>/enroll. Private key is persisted to
// ~/.stack/agents/<agent_id>.json (mode 0600).
// Subsequent runs sign every API call with a fresh 60-second JWT.See Agent Keys for enrollment, signing, replay protection, and rotation.
Set STACK_API_KEY from the CI provider's secret store. This is the operator API key, not a workload-scoped credential, so any process that can read it receives operator-level access.
STACK_API_KEY=sk_live_... node my-agent.jsAn API key in your .env file or your CI secrets store is a credential that a reader can copy. OAuth stores a rotating refresh token in the user's credential store and issues one-hour access tokens. Refresh-token replay revokes the token family and records a security event.
Use OAuth for interactive clients. Use the operator API key only when a headless workload cannot complete that flow, and keep it out of agent prompts, source code and logs.