SDK Integration Common Guide
This page defines the shared integration model used by Node, Python, and Go SDK guides.
Auth model
- Machine auth (runtime connect + runtime writes): use
SIMPLEFLOW_API_TOKEN, or useMACHINE_CLIENT_ID+MACHINE_CLIENT_SECRETand exchange via/v1/oauth/token. - User auth (runtime invoke/chat history): use user bearer token.
- Chat entrypoint (
/api/v1/chat): accepts API key (agk_*) or user bearer.agent_idis required.
User session and authorization (remote agents)
Access tokens are opaque to permission logic: org roles (member, admin, super_admin) are not embedded in self-hosted JWT claims. Resolve the canonical user and roles with GET /v1/me using the same bearer token the browser or client sends.
SDK helpers (Python / Node):
fetch_current_user/fetchCurrentUser— callsGET /v1/me; returnsuser_id,organization_id,roles,email,full_name.create_auth_session/createAuthSession— callsPOST /v1/auth/sessionswithemailandpassword; returns the issued access token payload.refresh_auth_session/refreshAuthSession— callsPOST /v1/auth/sessions/refreshusing the CSRF token + refresh cookie session.validate_access_token/validateAccessToken— validates token by callingGET /v1/me.
Use email/password only for initial session creation. All other SDK operations should use the issued bearer token (auth_token / authToken).
can_read_chat_user_scope/canReadChatUserScope— pure helper aligned with control-plane chat read rules:membermay only use chat APIs foruser_idequal to their ownuser_idfrom/v1/me;admin/super_adminmay read other users’ chat data; an empty chatuser_id(org-wide listing) is allowed only foradmin/super_admin.fetch_agent/fetchAgent—GET /api/v1/agents/{agent_id}; 200 means the caller has read access to that agent; 403 means no read access (agent RBAC is not represented in the JWT).authorize_runtime_chat_read/authorizeChatRead— runs/v1/me, enforces chat scope for a target chatuser_id, then fetches the agent; use beforelistChatSessions/listChatMessageswhen building a remote backend.
Do not use JWT sub as user_id for chat APIs on self-hosted auth: use user_id from /v1/me (or the login response) so it matches the control-plane user row.
Shared env variables
Base:
SIMPLEFLOW_BASE_URL
Machine auth:
SIMPLEFLOW_API_TOKEN- or
MACHINE_CLIENT_ID+MACHINE_CLIENT_SECRET
Runtime identity:
SIMPLEFLOW_AGENT_IDSIMPLEFLOW_AGENT_VERSIONSIMPLEFLOW_RUNTIME_IDSIMPLEFLOW_ORGANIZATION_IDRUNTIME_ENDPOINT_URL
User-scoped APIs:
SIMPLEFLOW_USER_BEARER
Workflow bridge:
WORKFLOW_PATH
Shared integration sequence
- Create SDK client with
SIMPLEFLOW_BASE_URLand machine auth. - Register runtime (
/v1/runtime/connector/v1/runtime/registrationsdepending on deployment). - Execute workflow.
- Emit canonical telemetry via
writeEventFromWorkflowResult(...). - Optionally emit span telemetry with
withTelemetry(...).emitSpan(...). - Use chat history APIs with user bearer token when needed.
Language-specific guides
- Node: Node SDK Integration
- Python: Python SDK Integration
- Go: Go SDK Integration