Skip to main content

cred-langchain

LangChain integration for Cred. OAuth2 credential delegation for AI agents.

Install

pip install cred-langchain

Quick Start

import os
from cred_langchain import CredToolkit
from cred import ConsentRequiredError
from cred import AgentIdentity

# The agent's own did:key identity, created once with cred.generate_agent_identity()
# and persisted with identity.export(); load_agent_identity() stands for your own
# secret store lookup returning that dict.
identity = AgentIdentity.from_export(load_agent_identity())

toolkit = CredToolkit(
    agent_token=os.environ["CRED_AGENT_TOKEN"],
    base_url=os.environ["CRED_BASE_URL"],
    user_id="user_123",
    token_format="handle",
    agent_identity=identity,
)
tools = toolkit.get_tools()
# tools = [CredDelegateTool, CredStatusTool, CredRevokeTool, CredUseTool]

# Use with any LangChain agent
from langchain.agents import AgentExecutor
agent = AgentExecutor(agent=..., tools=tools)

Tools

Tool Name Description
CredDelegateTool cred_delegate Get OAuth access for a service
CredUseTool cred_use Broker an API call through Cred with a delegation id
CredStatusTool cred_status List user's connected services
CredRevokeTool cred_revoke Revoke a service connection

CredToolkit(..., token_format="handle") returns brokered delegation ids from cred_delegate and includes cred_use so provider access tokens stay on the Cred server. The default token_format="raw" remains available for backwards compatibility.

agent_identity is required with token_format="handle". The Cred server issues a Delegation Token (a DPoP-bound JWT) to the agent's own key and accepts it only with a DPoP proof signed by that key. The key stays in your process; it is never sent to the model or the server, and it is not a tool argument. The model only sees delegation_id: the token itself is kept in an in-process map (delegation_id to token and expiry), filled by the delegate tool and read by the use tool, so it never appears in tool output. The use tool raises a clear error if no agent_identity is configured or the delegation_id is unknown or expired (call the delegate tool again).

When a user hasn't connected a service yet, CredDelegateTool raises ConsentRequiredError. Catch it and redirect the user to e.consent_url to complete the OAuth flow.

Brokered Server Mode

Point CRED_BASE_URL at your self-hosted @credninja/server deployment and set token_format="handle" when you want the agent to receive delegation ids instead of provider access tokens.

Metadata

Release files for cred-langchain 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cred-langchain 2.0.1
File Size Uploaded Provenance Actions
cred_langchain-2.0.1.tar.gz 13.2 kB Without provenance Details for cred_langchain-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cred-langchain 2.0.1
File Interpreter ABI Platform Actions
cred_langchain-2.0.1-py3-none-any.whl Python 3 none any Details for cred_langchain-2.0.1-py3-none-any.whl

Total release size: 24.6 kB

Release files / cred_langchain-2.0.1.tar.gz

Download URL cred_langchain-2.0.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
10b217901073537b594e51dfe130417c932c48735379d86b973dd31d7c978cb0
BLAKE2b-256 checksum
How to use checksums
6b5f987f05351a07594df28932ecc1edf6771494e4ec6a30389799d4c51b1167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / cred_langchain-2.0.1-py3-none-any.whl

Download URL cred_langchain-2.0.1-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fb3b0222588f906804f5a0d745a0d33b62e878d61a56f233f7c2d22a9b10ea8
BLAKE2b-256 checksum
How to use checksums
3c51e00b0c8be8800bd3e467a1018e427f0f5531a9a0bc03d8742c834da81377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for cred-langchain 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page