cred-openai-agents
OpenAI Agents SDK integration for Cred. OAuth2 credential delegation for AI agents.
Install
pip install cred-openai-agents
Quick Start
import os
from cred_openai_agents import cred_delegate_tool, cred_use_tool
from agents import Agent
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())
tool = cred_delegate_tool(
agent_token=os.environ["CRED_AGENT_TOKEN"],
base_url=os.environ["CRED_BASE_URL"],
user_id="user_123",
app_client_id="my_app_client_id",
token_format="handle",
agent_identity=identity,
)
agent = Agent(
name="assistant",
tools=[tool, cred_use_tool(
agent_token=os.environ["CRED_AGENT_TOKEN"],
base_url=os.environ["CRED_BASE_URL"],
agent_identity=identity,
)],
)
Tool Schema
The cred_delegate tool matches the Cred MCP tool spec:
| Parameter | Type | Description |
|---|---|---|
service |
string |
Service slug (e.g. google, github) |
scopes |
string[] |
OAuth scopes to request |
user_id and app_client_id are pre-configured at factory time, not agent-controlled.
By default, cred_delegate_tool returns a legacy access token for backwards compatibility. Set token_format="handle" to return a brokered delegation id, then use cred_use_tool to make allowed service API calls without exposing provider access tokens.
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). In a process that serves more than one user, pass user_id= to the use tool as well: a use tool configured with a user_id refuses delegations issued for any other user. Without it, the user is not checked.
Handling Consent
When the user hasn't connected the service, the tool raises ConsentRequiredError.
The error's consent_url attribute contains the URL to redirect the user.
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-openai-agents 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cred_openai_agents-2.0.1.tar.gz | 13.0 kB | Without provenance | Details for cred_openai_agents-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cred_openai_agents-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for cred_openai_agents-2.0.1-py3-none-any.whl |
Total release size: 23.5 kB
Release files / cred_openai_agents-2.0.1.tar.gz
| Download URL | cred_openai_agents-2.0.1.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6dd2d8f7812467b2e16d17959ec3f531034a46f84bf6a3b872874ab57a760a2
|
|
BLAKE2b-256 checksum How to use checksums |
9a59ce07123316e1ce0a6a937dcf40c9f0de7dc75348a17110b468ef2d4621a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / cred_openai_agents-2.0.1-py3-none-any.whl
| Download URL | cred_openai_agents-2.0.1-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6c6d5df3bf876e14c4b0edeb70fcbebd4a9896e6ca17d76f4e7698aed46448d
|
|
BLAKE2b-256 checksum How to use checksums |
6c58f9108c7bec78ccd175614007fc9b283dd2336d5bbdfa38bebf2b2ee24c47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for cred-openai-agents 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.