Connecting to Token/API Key Apps
Handle connections where users provide their own credentials (e.g., API Keys)
This guide covers the connection process for external apps that use authentication methods like static API Keys, Bearer Tokens, or other credentials that the end-user must provide (e.g., OpenAI, Stripe, Twilio, many database connections).
Unlike OAuth, this flow doesn’t typically involve redirecting the user’s browser. Instead, your application securely collects the necessary credentials from the user and passes them to Composio during the connection setup.
Prerequisites:
- An Integration for the target app must be configured in Composio, specifying the correct authentication scheme (e.g.,
API_KEY
,BEARER_TOKEN
). - A unique
entity_id
representing the user within your application.
Token/API Key Connection Flow
Step 1: Discover Required Fields
Before prompting your user, determine exactly which credentials they need to provide. Use get_expected_params_for_user
(Python) or apps.getRequiredParamsForAuthScheme
(TypeScript) to query Composio.
This tells your application which fields (e.g., api_key
, account_sid
, token
) to request from the user.
Step 2: Securely Collect Credentials from User
Your application’s UI must now prompt the user to enter the credentials identified in Step 1.
Handle Credentials Securely
Always transmit credentials over HTTPS. Avoid storing them unnecessarily client-side. Mask input fields for keys/tokens. Never log raw credentials.
Step 3: Initiate Connection with User Credentials
Call initiate_connection
(Python) or initiateConnection
(TypeScript) on the user’s Entity
object. Provide the integration_id
(or app_name
) and entity_id
. Crucially, pass the credentials collected from the user inside the connected_account_params
(Python) or connectionParams
(TypeScript) dictionary.
Step 4: Connection Activation (Immediate)
For these types of connections, the connectionStatus
in the response from initiate_connection
should usually be ACTIVE
immediately, as no external user authorization step is needed. The redirectUrl
will typically be null.
You can optionally fetch the connection details using the connectedAccountId
from the response to confirm the ACTIVE
status before proceeding.
Once active, the Connection is ready, and you can use the entity_id
or connectedAccountId
to execute actions for this user and app.