Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
refactor: use typed client methods, remove unnecessary type: ignore comments
The composio-client 1.31.0 already has typed methods for patch, create, and link — no need for raw HTTP calls, untyped dicts, or type: ignore suppressions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Zen Agent <zen@composio.dev>
abir committed
Apr 10, 2026 at 00:06 UTC
b3d28f566f4280edddc563228659c32f1084883c
2 files changed
+32
-49
python/composio/core/models/connected_accounts.py
+26
-41
@@ -11,6 +11,8 @@ from composio import exceptions
11
from composio.client import HttpClient
12
from composio.client.types import (
13
connected_account_create_params,
14
+ connected_account_patch_params,
15
+ connected_account_patch_response,
16
connected_account_retrieve_response,
17
connected_account_update_status_response,
18
)
@@ -360,15 +362,17 @@ class ConnectedAccounts:
362
self,
363
nanoid: str,
364
*,
363
- alias: str,
364
- ) -> t.Dict[str, t.Any]:
365
+ alias: t.Optional[str] = None,
366
+ connection: t.Optional[connected_account_patch_params.Connection] = None,
367
+ ) -> connected_account_patch_response.ConnectedAccountPatchResponse:
368
"""
366
- Update a connected account's alias.
369
+ Update a connected account's alias and/or credentials.
370
368
- :param nanoid: The unique identifier of the connected account.
369
- :param alias: Human-readable alias for the account. Must be unique per userId
370
- and toolkit within the project. Pass an empty string to clear.
371
- :return: Dict with ``success``, and optionally ``id`` and ``status``.
371
+ :param nanoid: The connected account ID (ca_xxx).
372
+ :param alias: Human-readable alias. Pass an empty string to clear.
373
+ Must be unique per entity and toolkit within the project.
374
+ :param connection: Credential update with authScheme and val fields.
375
+ :return: Response with ``id``, ``status``, and ``success``.
376
377
Example:
378
# Set an alias
@@ -377,16 +381,10 @@ class ConnectedAccounts:
381
# Clear an alias
382
composio.connected_accounts.update('ca_abc123', alias='')
383
"""
380
- if not nanoid:
381
- raise ValueError(
382
- f"Expected a non-empty value for `nanoid` but received {nanoid!r}"
383
- )
384
- # The composio_client doesn't yet have a typed method for this endpoint,
385
- # so we call the raw client patch method directly.
386
- return self._client.patch( # type: ignore[no-any-return]
387
- f"/api/v3/connected_accounts/{nanoid}",
388
- body={"alias": alias},
389
- cast_to=dict, # type: ignore[arg-type]
384
+ return self._client.connected_accounts.patch(
385
+ nanoid,
386
+ alias=alias,
387
+ connection=connection,
388
)
389
390
def initiate(
@@ -437,16 +435,13 @@ class ConnectedAccounts:
435
if config is not None:
436
connection["state"] = config
437
440
- create_kwargs: dict[str, t.Any] = {
441
- "auth_config": {"id": auth_config_id},
442
- "connection": t.cast(
438
+ response = self._client.connected_accounts.create(
439
+ auth_config={"id": auth_config_id},
440
+ connection=t.cast(
441
connected_account_create_params.Connection, connection
442
),
445
- }
446
- if alias is not None:
447
- create_kwargs["alias"] = alias
448
-
449
- response = self._client.connected_accounts.create(**create_kwargs)
443
+ alias=alias,
444
+ )
445
return ConnectionRequest(
446
id=response.id,
447
status=response.connection_data.val.status,
@@ -494,22 +489,12 @@ class ConnectedAccounts:
489
# Wait for the connection to be established
490
connected_account = composio.connected_accounts.wait_for_connection(connection_request.id)
491
"""
497
- # Prepare the request payload
498
- payload: dict[str, t.Any] = {
499
- "auth_config_id": auth_config_id,
500
- "user_id": user_id,
501
- }
502
-
503
- # Add callback_url only if provided
504
- if callback_url is not None:
505
- payload["callback_url"] = callback_url
506
-
507
- # Add alias only if provided
508
- if alias is not None:
509
- payload["alias"] = alias
510
-
511
- # Call the link creation endpoint
512
- response = self._client.link.create(**payload)
492
+ response = self._client.link.create(
493
+ auth_config_id=auth_config_id,
494
+ user_id=user_id,
495
+ callback_url=callback_url,
496
+ alias=alias,
497
+ )
498
499
return ConnectionRequest(
500
id=response.connected_account_id,
python/composio/core/models/tool_router_session.py
+6
-8
@@ -396,14 +396,12 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
396
:param alias: Human-readable alias for the connection. Must be unique
397
per userId and toolkit within the project.
398
"""
399
- link_params: dict = {
400
- "session_id": self.session_id,
401
- "toolkit": toolkit,
402
- "callback_url": callback_url if callback_url else omit,
403
- }
404
- if alias is not None:
405
- link_params["alias"] = alias
406
- response = self._client.tool_router.session.link(**link_params) # type: ignore[arg-type]
399
+ response = self._client.tool_router.session.link(
400
+ session_id=self.session_id,
401
+ toolkit=toolkit,
402
+ callback_url=callback_url if callback_url else omit,
403
+ alias=alias if alias is not None else omit,
404
+ )
405
return ConnectionRequest(
406
id=response.connected_account_id,
407
redirect_url=response.redirect_url,