Overview
The Mention API client supports multiple authentication and configuration methods to fit different use cases. This guide covers all available options for initializing and configuring your client.Quick Start
The simplest way to get started is with a direct access token:- Sync
- Async
Configuration Methods
Environment Variables
The recommended approach for production applications is to use environment variables with theMentionConfig.from_env() method.
Setting Up Environment Variables
Create a.env file in your project root:
Only
MENTION_ACCESS_TOKEN is required. All other variables have sensible defaults.Using Configuration with Client
- Sync
- Async
Custom Environment File
You can specify a custom.env file location:
Custom Environment Variable Prefix
By default, the client looks for variables prefixed withMENTION_. You can customize this:
Direct Configuration
For programmatic configuration, create aMentionConfig instance directly:
Configuration Options
TheMentionConfig dataclass supports the following options:
| Parameter | Type | Default | Description |
|---|---|---|---|
access_token | str | Required | OAuth2 access token for authentication |
account_id | str | None | None | Default account ID for operations |
base_url | str | https://api.mention.net/api | Base URL for the Mention API |
timeout | float | 30.0 | Request timeout in seconds |
max_retries | int | 3 | Maximum retry attempts for failed requests |
retry_delay | float | 1.0 | Base delay between retries (uses exponential backoff) |
Advanced Configuration
Context Manager Pattern
Both sync and async clients support context managers for automatic resource cleanup:- Sync
- Async
Per-Account Configuration
If you work with multiple accounts, you can create account-specific configurations:Custom Client Initialization
For fine-grained control, initialize the client directly with custom parameters:Best Practices
Never Hardcode Credentials
Never Hardcode Credentials
Always use environment variables or secure secret management systems. Never commit access tokens to version control.
Use Context Managers
Use Context Managers
Always use context managers to ensure proper cleanup of HTTP connections:
Configure Timeouts Appropriately
Configure Timeouts Appropriately
Set timeouts based on your use case:
- Interactive applications: 10-30 seconds
- Background processing: 60+ seconds
- Streaming operations: 120+ seconds
Handle Multiple Accounts Efficiently
Handle Multiple Accounts Efficiently
Create configurations once and reuse them:
Obtaining an Access Token
To use the Mention API, you need an OAuth2 access token. Here’s how to obtain one:- Log in to your Mention account
- Navigate to Settings → API
- Generate a new access token
- Store it securely in your environment variables
Next Steps
Sync vs Async
Learn when to use synchronous or asynchronous clients
Error Handling
Handle exceptions and implement retry logic