Overview
The Rust SDK provides several constructor methods:Edgee::from_env()- Reads from environment variables (idiomatic Rust)Edgee::with_api_key()- Creates client with just an API key (convenience)Edgee::new()- Creates client with fullEdgeeConfig(type-safe)
Method 1: Environment Variables (Recommended for Production)
The simplest and most secure approach is to use environment variables. The SDK will automatically readEDGEE_API_KEY and optionally EDGEE_BASE_URL.
Method 2: API Key Only (Quick Start)
For quick testing or simple scripts, usewith_api_key():
https://api.edgee.ai). To use a custom base URL, use Method 3.
Method 3: Configuration Object (Type-Safe)
For full control and type safety, useEdgeeConfig with the builder pattern:
api_key is required and must be provided either via constructor argument or EDGEE_API_KEY environment variable. If neither is provided, an Error::MissingApiKey will be returned.
Error Handling
The SDK uses Rust’sResult<T, E> type for explicit error handling:
Using ? Operator
Custom Error Handling
Complete Examples
Example 1: Production Setup
Example 2: Multi-Environment Setup
Troubleshooting
”MissingApiKey” Error
Problem: The SDK can’t find your API key. Solutions:-
Set the environment variable:
-
Use
with_api_key(): -
Use
EdgeeConfig:
Custom Base URL Not Working
Problem: Your custom base URL isn’t being used. Check:- Verify the base URL in your configuration
- Check if environment variable
EDGEE_BASE_URLis overriding it - Ensure you’re using the correct configuration method