Skip to main content

SDK Configuration

Configure the AgentSDK with various options to customize behavior, timeouts, callbacks, and more.

SDKConfig Interface

Configuration Options

agentId (required)

agentId
string
required
Your unique agent identifier. This is the client ID used in OAuth flows.

agentSecret (optional)

agentSecret
string
Agent secret for confidential clients. Only required for initial registration and some server-side operations. Not needed for OAuth 2.1 with PKCE flows.
Keep your agent secret secure! Never expose it in client-side code or public repositories.

serverUrl (optional)

serverUrl
string
The base URL of the Auth-Agent server. Defaults to the environment variable AUTH_SERVER_URL or the public Auth-Agent API.

timeout (optional)

timeout
number
default:"10000"
Request timeout in milliseconds. All API requests will abort after this duration.

customFetch (optional)

customFetch
typeof fetch
Custom fetch implementation. Useful for testing, adding custom interceptors, or using a different HTTP client.
Example with custom headers:

onTokensReceived (optional)

onTokensReceived
(tokens: TokenResponse) => void | Promise<void>
Callback invoked when new tokens are received (after OAuth code exchange). Use this to store tokens in your preferred storage system.

onTokensRefreshed (optional)

onTokensRefreshed
(tokens: TokenResponse) => void | Promise<void>
Callback invoked when tokens are refreshed. Use this to update stored tokens.

onTokensRevoked (optional)

onTokensRevoked
() => void | Promise<void>
Callback invoked when tokens are revoked. Use this to clear stored tokens.

Complete Example

Here’s a complete configuration example with all options:

Environment Variables

You can use environment variables for sensitive configuration:
.env

Best Practices

Always implement the onTokensReceived, onTokensRefreshed, and onTokensRevoked callbacks to properly manage token lifecycle. Use encrypted storage for sensitive tokens.
Set timeouts based on your network conditions and server response times. Default is 10 seconds, but you may need longer for slower networks.
Never commit agent secrets to version control. Use environment variables or secure secret management systems.
Implement proper error handling for all SDK methods. Use try-catch blocks and handle specific error codes.

Next Steps

AgentSDK Methods

Explore all available SDK methods

Token Manager

Learn about token management