Documentation Index
Fetch the complete documentation index at: https://docs.legnext.ai/llms.txt
Use this file to discover all available pages before exploring further.
Get Your API Key
- Visit Legnext Dashboard
- Log in to your account
- Navigate to API Keys section
- Create a new API key
- Copy and save it securely
Using Your API Key
Method 1: Direct Initialization
use legnext_rust_sdk::apis::configuration::Configuration;
use legnext_rust_sdk::apis::image_api;
#[tokio::main]
async fn main() {
let mut config = Configuration::new();
config.base_path = "https://api.legnext.ai".to_string();
let api_key = "your-api-key-here";
// Use api_key in function calls
}
Method 2: Environment Variable (Recommended)
Set the environment variable:
# macOS/Linux
export LEGNEXT_API_KEY="your-api-key-here"
# Windows CMD
set LEGNEXT_API_KEY=your-api-key-here
# Windows PowerShell
$env:LEGNEXT_API_KEY="your-api-key-here"
Then in your code:
use std::env;
use legnext_rust_sdk::apis::configuration::Configuration;
#[tokio::main]
async fn main() {
let mut config = Configuration::new();
config.base_path = "https://api.legnext.ai".to_string();
let api_key = env::var("LEGNEXT_API_KEY")
.expect("LEGNEXT_API_KEY environment variable not set");
// Use api_key in function calls
}
Method 3: Using dotenv Crate
Add to Cargo.toml:
[dependencies]
dotenv = "0.15"
legnext-rust-sdk = "1.0"
tokio = { version = "1", features = ["full"] }
Create .env file:
LEGNEXT_API_KEY=your-api-key-here
LEGNEXT_BASE_URL=https://api.legnext.ai
In your code:
use dotenv::dotenv;
use std::env;
use legnext_rust_sdk::apis::configuration::Configuration;
#[tokio::main]
async fn main() {
dotenv().ok();
let mut config = Configuration::new();
config.base_path = env::var("LEGNEXT_BASE_URL")
.unwrap_or_else(|_| "https://api.legnext.ai".to_string());
let api_key = env::var("LEGNEXT_API_KEY")
.expect("LEGNEXT_API_KEY not found in environment");
// Use api_key in function calls
}
Security Best Practices
⚠️ Never hardcode API keys in your code
✅ Always use environment variables or .env files
✅ Add .env to .gitignore
✅ Use expect() or proper error handling for missing keys
✅ Rotate keys regularly and revoke compromised ones
Next Steps