# Create a link session for a toolkit in a tool router session

**Documentation:** /reference/api-reference/tool-router/postToolRouterSessionBySessionIdLink

Initiates an authentication link session for a specific toolkit within a tool router session. Returns a link token and redirect URL that users can use to complete the OAuth flow.

---

## POST `/api/v3/tool_router/session/{session_id}/link`

**Endpoint:** `https://backend.composio.dev/api/v3/tool_router/session/{session_id}/link`

**Summary:** Create a link session for a toolkit in a tool router session

Initiates an authentication link session for a specific toolkit within a tool router session. Returns a link token and redirect URL that users can use to complete the OAuth flow.

### Authentication

**ApiKeyAuth** - API Key in `header` header `x-api-key` OR **UserApiKeyAuth** - API Key in `header` header `x-user-api-key`

### Path Parameters

- `session_id` (string (toolRouterSessionId)) *(required)*: The unique identifier of the tool router session

### Request Body

**Schema:**

- `toolkit` (string) *(required)*: The unique slug identifier of the toolkit to connect
- `callback_url` (string (uri)): URL where users will be redirected after completing auth

**Example:**

```json
{
  "toolkit": "string",
  "callback_url": "https://example.com"
}
```

### Responses

#### 201 - Successfully created link session. Returns link token, redirect URL, and connected account ID.

**Response Schema:**

- `link_token` (string) *(required)*: Token used to complete the authentication flow
- `redirect_url` (string (uri)) *(required)*: The URL where users should be redirected to complete OAuth
- `connected_account_id` (string (connectedAccountId)) *(required)*: The unique identifier for the connected account

**Example Response:**

```json
{
  "link_token": "string",
  "redirect_url": "https://example.com",
  "connected_account_id": "string"
}
```

#### 400 - Bad request. This may occur if the toolkit slug is invalid, request parameters are malformed, or a connected account is already defined for this toolkit in the session configuration.

**Response Schema:**

- `error` (object) *(required)*
  - `message` (string) *(required)*
  - `code` (number) *(required)*
  - `slug` (string) *(required)*
  - `status` (number) *(required)*
  - `request_id` (string)
  - `suggested_fix` (string)
  - `errors` (array<string>)

#### 401 - Unauthorized. Authentication is required or the provided credentials are invalid.

**Response Schema:**

- `error` (object) *(required)*
  - `message` (string) *(required)*
  - `code` (number) *(required)*
  - `slug` (string) *(required)*
  - `status` (number) *(required)*
  - `request_id` (string)
  - `suggested_fix` (string)
  - `errors` (array<string>)

#### 403 - Forbidden. The session does not belong to the authenticated user.

**Response Schema:**

- `error` (object) *(required)*
  - `message` (string) *(required)*
  - `code` (number) *(required)*
  - `slug` (string) *(required)*
  - `status` (number) *(required)*
  - `request_id` (string)
  - `suggested_fix` (string)
  - `errors` (array<string>)

#### 404 - Not found. The session does not exist, toolkit not found, or no auth config exists for the toolkit.

**Response Schema:**

- `error` (object) *(required)*
  - `message` (string) *(required)*
  - `code` (number) *(required)*
  - `slug` (string) *(required)*
  - `status` (number) *(required)*
  - `request_id` (string)
  - `suggested_fix` (string)
  - `errors` (array<string>)

#### 500 - Internal server error. An unexpected error occurred while creating the link session.

**Response Schema:**

- `error` (object) *(required)*
  - `message` (string) *(required)*
  - `code` (number) *(required)*
  - `slug` (string) *(required)*
  - `status` (number) *(required)*
  - `request_id` (string)
  - `suggested_fix` (string)
  - `errors` (array<string>)

### Example cURL Request

```bash
curl -X POST "https://backend.composio.dev/api/v3/tool_router/session/string/link" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "toolkit": "string",
    "callback_url": "https://example.com"
  }'
```