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.
tasks.get(job_id)
Get current task status:
task = client.tasks.get(job_id="job-123")
print(f"Status: {task.status}")
tasks.wait_for_completion(job_id, timeout=300, poll_interval=3, on_progress=None)
Wait for task completion:
result = client.tasks.wait_for_completion(
job_id="job-123",
timeout=600,
on_progress=lambda t: print(f"Progress: {t.progress}%")
)
Parameters:
job_id (str): Job ID to wait for
timeout (float, optional): Max wait time in seconds (default: 300)
poll_interval (float, optional): Seconds between checks (default: 3)
on_progress (callable, optional): Callback on each check
Async/Await
All methods support async using AsyncClient:
import asyncio
from legnext import AsyncClient
async def main():
async with AsyncClient(api_key="your-api-key") as client:
response = await client.midjourney.diffusion(text="...")
result = await client.tasks.wait_for_completion(response.job_id)
print(result.output.image_urls)
asyncio.run(main())
Batch processing example:
async with AsyncClient(api_key="your-api-key") as client:
# Start multiple jobs
responses = await asyncio.gather(*[
client.midjourney.diffusion(text=f"prompt {i}")
for i in range(5)
])
# Wait for all
results = await asyncio.gather(*[
client.tasks.wait_for_completion(r.job_id)
for r in responses
])
Error Handling
Handle different error types:
from legnext.exceptions import (
ValidationError,
AuthenticationError,
RateLimitError,
LegnextAPIError
)
try:
response = client.midjourney.diffusion(text="...")
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limited - retry later")
except ValidationError as e:
print(f"Invalid parameters: {e.message}")
except LegnextAPIError as e:
print(f"API error: {e.message}")
Exception Types:
| Exception | HTTP | Description |
|---|
ValidationError | 400 | Invalid request parameters |
AuthenticationError | 401 | Invalid API key |
NotFoundError | 404 | Resource not found |
RateLimitError | 429 | Rate limit exceeded |
ServerError | 5xx | Server error |
LegnextAPIError | - | Base exception |
Learn More