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.
1. Add Dependency
Add to your Cargo.toml:
[dependencies]
legnext-rust-sdk = "1.0.0"
tokio = { version = "1", features = ["full"] }
2. Set API Key
export LEGNEXT_API_KEY="your-api-key"
3. Basic Example
use legnext_rust_sdk::apis::configuration::Configuration;
use legnext_rust_sdk::apis::image_api;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Configure API client
let mut config = Configuration::new();
config.base_path = "https://api.legnext.ai".to_string();
let api_key = env::var("LEGNEXT_API_KEY")?;
// Generate image
let mut request = std::collections::HashMap::new();
request.insert("text".to_string(), serde_json::json!("a beautiful sunset over mountains"));
match image_api::api_v1_diffusion_post(&config, Some(&api_key), Some(request)).await {
Ok(response) => {
println!("Response: {:?}", response);
}
Err(e) => {
eprintln!("Error: {:?}", e);
}
}
Ok(())
}
4. Check Task Status
use legnext_rust_sdk::apis::video_api;
let job_id = "your-job-id-here";
match video_api::api_v1_job_job_id_get(&config, &job_id, Some(&api_key)).await {
Ok(task_response) => {
if let Some(status) = task_response.status {
println!("Status: {}", status);
}
if let Some(output) = task_response.output {
if let Some(image_urls) = output.image_urls {
println!("Images: {:?}", image_urls);
}
}
}
Err(e) => {
eprintln!("Error: {:?}", e);
}
}
Error Handling
match image_api::api_v1_diffusion_post(&config, Some(&api_key), Some(request)).await {
Ok(response) => {
// Handle success
println!("Success: {:?}", response);
}
Err(e) => {
eprintln!("Error: {:?}", e);
}
}
Async/Await
All API calls are async and require an async runtime like Tokio:
[dependencies]
tokio = { version = "1", features = ["full"] }
Available APIs
image_api - Text to image, variations, upscaling, editing
video_api - Video generation, upscaling, and task status
account_management_api - Account balance and information