Skip to main content
Agent Auth is in beta and under active development. To provide feedback or use this feature, reach out to the LangChain team.

Installation

Quickstart

1. Initialize the client

Self-hosted configuration

For self-hosted LangSmith instances, specify the API URL using the /api-host path on your instance.
Then initialize the client normally:

2. Set up OAuth providers

Before agents can authenticate, you need to configure an OAuth provider using the following process:
  1. Select a unique identifier for your OAuth provider to use in LangChain’s platform (e.g., “github-local-dev”, “google-workspace-prod”).
  2. Go to your OAuth provider’s developer console and create a new OAuth application.
  3. Set the callback URL in your OAuth provider:
For example, if your provider_id is “github-local-dev”, use:
  1. Use client.create_oauth_provider() with the credentials from your OAuth app:

3. Authenticate from an agent

The client authenticate() API is used to get OAuth tokens from pre-configured providers. On the first call, it takes the caller through an OAuth 2.0 auth flow.

In LangGraph context

By default, tokens are scoped to the calling agent using the Assistant ID parameter.
During execution, if authentication is required, the SDK will throw an interrupt. The agent execution pauses and presents the OAuth URL to the user:
After the user completes OAuth authentication and we receive the callback from the provider, they will see the auth success page.
The agent then resumes execution from the point it left off at, and the token can be used for any API calls. We store and refresh OAuth tokens so that future uses of the service by either the user or agent do not require an OAuth flow.

Outside LangGraph context

Provide the auth_url to the user for out-of-band OAuth flows.

Troubleshooting

Self-hosted: 405 Method Not Allowed

If you receive a 405 Method Not Allowed error, ensure LANGSMITH_API_URL points to the /api-host path:

Self-hosted: Malformed OAuth callback URL

Ensure your OAuth provider’s redirect URI matches your LangSmith instance URL: