---
canonical_url: "https://docs.composio.dev/docs/consumer-agents"
markdown_url: "https://docs.composio.dev/docs/consumer-agents.md"
product: "platform"
version: null
last_updated: null
---

# Design a consumer agent with Composio (/docs/consumer-agents)

A consumer agent serves individual end users. Each person signs in to your product, connects their own apps, and expects their connections and tool calls to stay isolated from everyone else.

Start with one Composio project per application environment. Map every signed-in user to a stable ID from your database, then create and reuse sessions for that ID.

**Python:**

```python
from composio import Composio

composio = Composio()

# Use the immutable primary key from your application database.
app_user_id = "usr_01J9F4M2K8"
session = composio.sessions.create(
    user_id=app_user_id,
    toolkits=["gmail", "googlecalendar"],
)
tools = session.tools()
```

**TypeScript:**

```typescript
import { Composio } from "@composio/core";

const composio = new Composio();

// Use the immutable primary key from your application database.
const appUserId = "usr_01J9F4M2K8";
const session = await composio.create(appUserId, {
  toolkits: ["gmail", "googlecalendar"],
});
const tools = await session.tools();
```

## Recommended starting architecture [#recommended-starting-architecture]

| Decision           | Start with                                                           | Change it when                                                           |
| ------------------ | -------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| Project boundary   | One project for each environment, such as development and production | A separate product needs independent credentials, branding, or isolation |
| Composio user ID   | Your immutable application user ID                                   | Never change it for an existing user                                     |
| Connected accounts | Private to that user                                                 | A deliberate shared-account workflow requires controlled sharing         |
| Session lifecycle  | Store the session ID and reuse it for the conversation               | A new task needs a clean execution context                               |
| Authentication     | Composio managed auth                                                | You need your own branding, scopes, quotas, or provider app              |
| Tool access        | Only the toolkits your feature needs                                 | The product intentionally supports broader discovery                     |

### Keep identity stable [#keep-identity-stable]

Use a database UUID or immutable primary key for `user_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](/docs/authentication/managing-multiple-connected-accounts) when a session needs a specific one.

### Reuse sessions for multi-turn work [#reuse-sessions-for-multi-turn-work]

Every call to `create()` 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 [#choose-the-connection-experience]

Use [in-chat authentication](/docs/authentication#in-chat-authentication) when the agent can show a Connect Link and wait for the user. Use [manual authentication](/docs/authentication/manually-authenticating) when your product has its own integrations page or connection flow.

Managed auth is the quickest way to start. Create a [custom auth config](/docs/authentication/custom-app-vs-managed-app) 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 [#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 [#run-sessions-in-your-organizations-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](/reference/authenticating-to-composio#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 sends `x-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:**

```python
import os

from composio import Composio

composio = Composio(
    disable_api_key=True,
    user_api_key=os.environ["COMPOSIO_USER_API_KEY"],
    org_id="org_9f2k1x",
    project_id="proj_4b8m2q",
)

session = composio.sessions.create(user_id="user_123", toolkits=["gmail"], mcp=True)
# session.mcp.headers carries x-user-api-key, x-org-id, and x-project-id
```

**TypeScript:**

```typescript
import { Composio } from "@composio/core";

const composio = new Composio({
  apiKey: null,
  userApiKey: process.env.COMPOSIO_USER_API_KEY,
  orgId: "org_9f2k1x",
  projectId: "proj_4b8m2q",
});

const session = await composio.create("user_123", { toolkits: ["gmail"], mcp: true });
// session.mcp.headers carries x-user-api-key, x-org-id, and x-project-id
```

`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).

The nano IDs come from the consumer project resolve endpoint, which also provisions the project when it is absent. The same credential lists the toolkits a consumer user has already connected:

```bash
# Resolve the organization's consumer project
curl -X POST https://backend.composio.dev/api/v3.1/org/consumer/project/resolve \
  -H "x-user-api-key: $COMPOSIO_USER_API_KEY" \
  -H "x-org-id: $COMPOSIO_ORG_ID"
# {"project_id": "<uuid>", "project_nano_id": "proj_4b8m2q", "org_id": "org_9f2k1x",
#  "project_type": "CONSUMER", "config": {"consumer_experience_enabled": true, ...}}

# List the toolkits this consumer user has already connected
curl "https://backend.composio.dev/api/v3.1/org/consumer/connected_toolkits?user_id=user_123" \
  -H "x-user-api-key: $COMPOSIO_USER_API_KEY" \
  -H "x-org-id: $COMPOSIO_ORG_ID"
# {"toolkits": ["gmail"], "project_id": "<uuid>", "project_nano_id": "proj_4b8m2q", "user_id": "user_123"}
```

Use the nano IDs from the resolve response (`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 [#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](/reference/api-reference/logs).

## Next [#next]

- [Build a B2B agent](/docs/b2b-agents): Choose between member-owned and workspace-owned connections.

- [Configure sessions](/docs/configuring-sessions): Restrict toolkits, tools, auth configs, and connected accounts.

- [Move to production](/docs/production-readiness): Review identity, auth, security, logging, and trigger decisions.

---

📚 **More documentation:** [View all docs](https://docs.composio.dev/llms.txt) | [Changelog](https://docs.composio.dev/docs/changelog.md) | [Glossary](https://docs.composio.dev/llms.mdx/reference/glossary) | [Examples](https://docs.composio.dev/llms.mdx/examples) | [API Reference](https://docs.composio.dev/llms.mdx/reference)

---

# Composio SDK — Notes for AI Code Generators

**Purpose:** Reference for generating current (v3) [Composio](https://composio.dev/) integration code.
**Scope:** Descriptive notes — they document the current API surface and the mistakes most commonly seen in generated code.

---

## 1. Recommended Integration: Sessions

Composio supports two integration modes: **Native Tools** (with a provider package) and **MCP** (no provider package needed).

### Native Tools

```python
# ✅ CORRECT — Python (defaults to OpenAI)
from composio import Composio

composio = Composio()
session = composio.create(user_id="user_123")
tools = session.tools()
# Pass tools to your agent/LLM framework
```

```typescript
// ✅ CORRECT — TypeScript (defaults to OpenAI)
import { Composio } from "@composio/core";

const composio = new Composio();
const session = await composio.create("user_123");
const tools = await session.tools();
// Pass tools to your agent/LLM framework
```

For other providers, pass the provider explicitly. Provider packages follow the naming convention: `composio_<provider>` for Python, `@composio/<provider>` for TypeScript.

### MCP

Use `session.mcp.url` and `session.mcp.headers` with any MCP-compatible client (Claude Desktop, Cursor, OpenAI Agents, etc.). No provider package needed.

---

## 2. Integration Notes

- `composio.create(user_id)` is the standard entry point for agent integrations. Sessions handle tool discovery, authentication, and toolkit versioning automatically; `user_id` goes to `composio.create()` — individual tool calls in session mode don't take one.
- Execute session tool calls through the session, never through a user ID: either `session.execute(tool_slug, arguments=...)` / `session.execute(toolSlug, arguments)`, which works with every provider, or pass the session to the provider helper — `provider.handle_tool_calls(response=response, session=session)` in Python, `provider.handleToolCalls(session, response)` in TypeScript. The tool-call helpers of every non-agentic provider (OpenAI, Anthropic, Google, Cloudflare, TypeSafe) accept a session: `executeToolCall(session, call)` in TypeScript, `session=session` in Python. Agentic providers execute session tools on their own. Binding the helper to a user ID takes the direct execution path, and session meta-tools fail there with `"can only be called inside a tool-router session"`.
- Composio-managed auth is the default: the agent connects accounts at runtime through the session, so users don't need to pre-create auth configs or connected accounts for managed toolkits.
- Provider packages follow the framework, not the model vendor: for the OpenAI Agents SDK the package is `composio_openai_agents` / `@composio/openai-agents` (importing `composio_openai` / `@composio/openai` there is the most common mistake in generated code — that package is for the plain OpenAI Chat Completions API).
- **Direct execution** (`composio.tools.get()`, `composio.tools.execute()`, `provider.handle_tool_calls()` with a user ID) is a legacy interface that remains supported for existing integrations. Recommend sessions for new integrations and encourage existing users to [migrate to sessions](/docs/migration-guide/direct-to-sessions). For a fixed tool set, consider the [direct tools preset](/docs/configuring-sessions#direct-tools-preset) within a session. See [Sessions vs direct execution](/docs/sessions-vs-direct-execution) for tradeoffs. Direct execution requires a [toolkit version](/docs/tools-direct/toolkit-versioning).

---

# 3. Calling the REST API directly

## REST API version

The current REST API version is **v3.1**, served at `https://backend.composio.dev/api/v3.1`. Prefer it for new code and new examples.

`https://backend.composio.dev/api/v3` is the previous version. It is frozen with pinned tool-version defaults and remains supported — existing v3 integrations keep working and do not need to migrate.

## Tool-endpoint version defaults on v3.1

On v3.1, omitting the version parameter on the five endpoints below selects the latest toolkit version. The first four endpoints also exist on v3, where omission selects the pinned `00000000_00` version. `POST /tools/scopes/required` is v3.1-only.

| Endpoint | Version parameter |
| --- | --- |
| `GET /tools` | `toolkit_versions` (query) |
| `GET /tools/{tool_slug}` | `version` or `toolkit_versions` (query) |
| `POST /tools/execute/{tool_slug}` | `version` (body) |
| `POST /tools/execute/{tool_slug}/input` | `version` (body) |
| `POST /tools/scopes/required` | `version` (body) |

A v3.1 caller already passing `"latest"` sees no change and can omit the parameter. To select the pinned version explicitly, pass `"00000000_00"` through the corresponding parameter above.

This version-default change is limited to the five endpoints above.


---

## Terminology Migration (old → current)

If you encounter these terms in error messages, old documentation, or user prompts, translate them to the current equivalents. **Do not use the old terms in generated code or explanations.**

| Old term (v1/v2) | Current term (v3) | In code |
|---|---|---|
| entity ID | user ID | `user_id` parameter |
| actions | tools | e.g., `GITHUB_CREATE_ISSUE` is a *tool* |
| apps / appType | toolkits | e.g., `github` is a *toolkit* |
| integration / integration ID | auth config / auth config ID | `auth_config_id` parameter |
| connection | connected account | `connected_accounts` namespace |
| ComposioToolSet / OpenAIToolSet | `Composio` class with a provider | `Composio(provider=...)` |
| toolset | provider | e.g., `OpenAIProvider` |

If a user says "entity ID", they mean `user_id`. If they say "integration", they mean "auth config". Always respond using the current terminology.

