- Python
- TypeScript
- API
Recommended starting architecture
Keep identity stable
Use a database UUID or immutable primary key foruser_id. Do not use an email address because it can change. Never use a shared value such as default in production, because different customers could inherit the same connection scope.
The same application user can connect several accounts for one toolkit, such as personal and work Gmail. Keep the same user_id and select the connected account when a session needs a specific one.
Reuse sessions for multi-turn work
Every call tocreate() makes a new session. Store session.session_id in Python or session.sessionId in TypeScript with your conversation, then restore it with composio.use(session_id). Reusing the session preserves its tool, authentication, and workbench context.
Create a new session for a different user or a genuinely separate task. Do not create a new session for every message in the same conversation.
Choose the connection experience
Use in-chat authentication when the agent can show a Connect Link and wait for the user. Use manual authentication when your product has its own integrations page or connection flow. Managed auth is the quickest way to start. Create a custom auth config only when you need your own consent-screen branding, custom scopes, dedicated provider quotas, or a custom provider instance.Limit the agent to its job
Restrict the session to the toolkits and tools your feature needs. This makes discovery more relevant and prevents unrelated actions from appearing in the agent’s available surface. Ask for user confirmation before destructive or externally visible actions.Run sessions in your organization’s consumer project
Every Composio organization also has one consumer project: the project behind Composio Connect and the For You clients, where your members’ own connections live. Sessions in it are created with a user API key and an explicit scope. Composio never mints or returns the consumer project’s API key. Resolve the consumer project once to learn its nano IDs, then build the SDK instance with the user API key and that scope. The SDK sendsx-user-api-key, x-org-id, and x-project-id on every request, carries the scope into session clones, and exports it with the session’s MCP config:
- Python
- TypeScript
- API
orgId and projectId (org_id and project_id in Python) must be set together, and the SDK rejects a scope that disagrees with x-org-id or x-project-id entries in defaultHeaders. Without a scope, a user API key addresses the API default (the developer project).
Requires
@composio/core ≥ 0.19.1 (TypeScript) or composio ≥ 0.22.1 (Python).- Python
- TypeScript
- API
org_id and project_nano_id), always together. A UUID in either header is a 400. A user with no connections yet gets an empty toolkits list with the project scope still filled in, so you can create their session before they connect anything. An organization without a consumer project gets null project identifiers from the listing, which never provisions one. Raw HTTP callers create the session with the same three headers on POST /api/v3.1/tool_router/session.
Before you launch
- Verify two different users cannot see or use each other’s connected accounts.
- Test both the first-time connection flow and a returning user with an existing connection.
- Store the Composio API key only on your server. A session created with a user API key exports that organization-wide key in its MCP config, so store that config as a secret too.
- Persist session IDs for multi-turn conversations.
- Test one safe, read-only call against a real connected account.
- Inspect the resulting tool call in Logs.