---
title: Connections
description: Connect the accounts your agents' tools act with, by API key or
  OAuth, from the console, the CLI, the SDK or the API; limit where a connection
  may be used; revoke it.
url: https://hexelstudio.com/docs/titan/connections
---

A **connection** (a connected account) holds the credential a tool uses to act on a service for you: an API key, an OAuth token, or the named credential fields a toolkit needs. Titan stores it encrypted and hands it to the tool only when a governed action runs. The agent never holds the credential.

Each connection belongs to a **toolkit** (for example `GITHUB` or `LINEAR`) and to a workspace (`ws_...`), and optionally an environment. How the credential is obtained comes from the toolkit's **auth config**: its scheme (OAuth 2, API key, named fields), the OAuth app, scopes and URLs.

<Note>
A connection decides what an agent **can reach**; your policy decides what it **may do** there. Connect the account first, then allow, deny or require approval for each capability in [Policies and approvals](https://hexelstudio.com/docs/titan/policies-and-approvals).
</Note>

## Connect an account

<Tabs>
  <Tab title="Console">
    Open **Titan → Connections** in [console.hexelstudio.com](https://console.hexelstudio.com), pick a connector and sign in, or paste its key. The console uses Hexel Studio's Connect pages, so the credential goes straight from your browser to Hexel Studio.
  </Tab>
  <Tab title="CLI">
    Install the [Hexel CLI](https://hexelstudio.com/docs/cli/overview) (0.11.1 or later). The connection goes to the workspace of your [context](https://hexelstudio.com/docs/cli/contexts), or the one you pass with `--workspace`.

    ```bash
    # Connect pages in your browser: pick a connector and sign in there
    hexel connections connect
    hexel connections connect HUBSPOT_REST --for me   # your own account, not the organization's

    # Straight to one toolkit, shared by the workspace
    hexel connections connect GITHUB --oauth
    echo "$LINEAR_KEY" | hexel connections connect LINEAR --api-key
    hexel connections connect ZENDESK --oauth --attribute subdomain=acme
    ```

    `--api-key` never takes the key on the command line: `hexel` asks for it without echo, reads it from standard input or from `--api-key-file`. `--oauth` opens the provider's sign-in page and waits for it to return to `http://127.0.0.1:<port>/callback`, so the toolkit's OAuth app must allow that redirect URI.
  </Tab>
  <Tab title="TypeScript SDK">
    ```ts
    import { connectWithApiKey, startOAuth, completeOAuth } from '@hexelstudio/titan-sdk/flows';

    // API key: sent as credentials.access_token, the value the tool receives
    const account = await connectWithApiKey({
      authConfigId,
      apiKey: process.env.LINEAR_API_KEY,
      account: { toolkit_slug: 'LINEAR', workspace_id: workspaceId },
    });
    ```

    For an OAuth toolkit, call `startOAuth`, send the person to the URL it returns, and call `completeOAuth(code, state)` on your redirect page. See [TypeScript SDK](https://hexelstudio.com/docs/titan/sdk#connect-an-account).
  </Tab>
</Tabs>

## Connect with the API

All connection routes are under `https://api.hexelstudio.com/v1/titan/tools/`. Send an access token (or a service user's API key as `X-API-Key`) and the workspace as `X-Workspace-Id`. Reading needs `tool-gateway:auth:read`; connecting, changing and revoking need `tool-gateway:auth:write`.

<Steps>
  <Step title="Find the toolkit's auth config">
    ```bash
    curl "https://api.hexelstudio.com/v1/titan/tools/auth-configs?workspace_id=$WORKSPACE_ID" \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      -H "X-Workspace-Id: $WORKSPACE_ID"
    ```

    Pick the toolkit's config by `toolkit_slug`: the active one (`is_active`), and the default one (`is_default`) when there are several. An organization-level config has no `workspace_id`.
  </Step>
  <Step title="Store an API key">
    ```bash
    curl -X POST https://api.hexelstudio.com/v1/titan/tools/connected-accounts \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      -H "X-Workspace-Id: $WORKSPACE_ID" \
      -H "Content-Type: application/json" \
      -d '{
        "account": {"toolkit_slug": "LINEAR", "workspace_id": "'"$WORKSPACE_ID"'", "auth_config_id": "'"$AUTH_CONFIG_ID"'"},
        "credentials": {"access_token": "'"$LINEAR_API_KEY"'"}
      }'
    ```

    A toolkit whose auth config declares named credential fields takes them in `credentials.fields` instead.
  </Step>
  <Step title="Or start OAuth">
    ```bash
    curl -X POST https://api.hexelstudio.com/v1/titan/tools/connections/initiate \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      -H "X-Workspace-Id: $WORKSPACE_ID" \
      -H "Content-Type: application/json" \
      -d '{
        "auth_config_id": "'"$AUTH_CONFIG_ID"'",
        "organization_id": "'"$ORG_ID"'",
        "workspace_id": "'"$WORKSPACE_ID"'",
        "redirect_uri": "https://app.example.com/oauth/callback"
      }'
    ```

    Send the person to `authorization_url`. When the provider redirects back with `code` and `state`, complete it with `POST /v1/titan/tools/connections/callback` and the body `{"code": "...", "state": "..."}`. A provider with a per-tenant host (for example Zendesk's subdomain) takes it in `attributes`, such as `{"subdomain": "acme"}`.
  </Step>
</Steps>

The SDK and the CLI call these same routes. Every route, with its fields and errors, is in the [Titan platform API reference](https://hexelstudio.com/docs/api/titan/connections).

## List and revoke

```bash
hexel connections list               # this workspace (--all-workspaces for every one)
hexel connections show <ID>          # one connection and the apps that use it
hexel connections revoke <ID>        # revoke it; --app revokes only one app's use of it
```

With the API, `GET /v1/titan/tools/connected-accounts?workspace_id=...` lists them and `DELETE /v1/titan/tools/connected-accounts/{nano_id}` revokes one. A revoked connection can't be used by any later action. To stop a connection at once while you investigate, kill it with the ID that `hexel connections list` shows (the `nano_id`): `hexel titan kill <ID> --type connection` ([Kill switch](https://hexelstudio.com/docs/titan/kill-switch)). Titan looks up the connection and returns its `connected_account_id` as the `target_id`.

## Limit where a connection may be used

An administrator can scope a connection, so that a governed action uses it only for the destinations and labels you assign:

```bash
curl -X PATCH https://api.hexelstudio.com/v1/titan/tools/connected-accounts/$CONNECTION_ID/scope \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Workspace-Id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"destination_boundaries": ["github.organization:acme"], "tags": ["prod"]}'
```

- `destination_boundaries` are `type:id` values. Every boundary an action's grant requires must be on the connection, so a connection scoped to `github.organization:acme` can't be used for another GitHub organization.
- `tags` are your own labels; every tag a grant requires must be on the connection.

A connection also records the `permissions` its provider granted at connect time (for example the OAuth scope `repo`): an action that needs a permission the connection doesn't have can't use it. Reconnect with the scopes the tool needs.

## Errors

| Status | When |
| --- | --- |
| `400` | A required field is missing, or the body is not valid. |
| `401` | No token, or one the edge rejected. |
| `403` | The caller lacks `tool-gateway:auth:read` or `tool-gateway:auth:write`. |
| `404` | The connection does not exist in your organization (revoke, scope). |

An action that can't find a usable connection fails when it runs, and the [Agent Ledger](https://hexelstudio.com/docs/titan/agent-ledger) records why.
