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. Install
dotnet add package Legnext.SDK
2. Set API Key
export LEGNEXT_API_KEY="your-api-key"
3. Basic Example
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Legnext.SDK.Api;
using Legnext.SDK.Client;
using Legnext.SDK.Extensions;
class Program
{
static async Task Main(string[] args)
{
string apiKey = Environment.GetEnvironmentVariable("LEGNEXT_API_KEY");
// Set up dependency injection
var services = new ServiceCollection();
services.AddApi(config =>
{
config.AddApiHttpClients(client =>
{
client.BaseAddress = new Uri("https://api.legnext.ai");
});
});
var provider = services.BuildServiceProvider();
var imageApi = provider.GetRequiredService<IImageApi>();
try
{
// Generate image
var request = new Dictionary<string, object>
{
{ "text", "a beautiful sunset over mountains" }
};
var response = await imageApi.ApiV1DiffusionPostAsync(
new Option<string>(apiKey),
request
);
if (response.IsOk)
{
var jsonDoc = JsonDocument.Parse(response.RawContent);
if (jsonDoc.RootElement.TryGetProperty("job_id", out var jobId))
{
Console.WriteLine($"Job ID: {jobId.GetString()}");
}
if (jsonDoc.RootElement.TryGetProperty("status", out var status))
{
Console.WriteLine($"Status: {status.GetString()}");
}
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
}
4. Check Task Status
using System.Text.Json;
using Legnext.SDK.Api;
var videoApi = provider.GetRequiredService<IVideoApi>();
try
{
var response = await videoApi.ApiV1JobJobIdGetAsync(
jobId,
new Option<string>(apiKey)
);
if (response.IsOk)
{
var jsonDoc = JsonDocument.Parse(response.RawContent);
var root = jsonDoc.RootElement;
if (root.TryGetProperty("status", out var status))
{
Console.WriteLine($"Status: {status.GetString()}");
}
if (root.TryGetProperty("task_type", out var taskType))
{
Console.WriteLine($"Task Type: {taskType.GetString()}");
}
if (root.TryGetProperty("output", out var output) &&
output.TryGetProperty("image_urls", out var imageUrls))
{
Console.WriteLine("Images:");
foreach (var url in imageUrls.EnumerateArray())
{
Console.WriteLine($" - {url.GetString()}");
}
}
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
Error Handling
try
{
var response = await imageApi.ApiV1DiffusionPostAsync(
new Option<string>(apiKey),
request
);
if (response.IsOk)
{
// Parse and handle successful response
var jsonDoc = JsonDocument.Parse(response.RawContent);
// Process result...
}
else
{
Console.WriteLine($"Request failed with status: {response.StatusCode}");
Console.WriteLine($"Response: {response.RawContent}");
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
Available APIs
IImageApi - Text to image, variations, upscaling, editing
IVideoApi - Video generation, upscaling, and task status
IAccountManagementApi - Account balance and information
Important Notes
- The SDK uses dependency injection with
Microsoft.Extensions.DependencyInjection
- Namespace is
Legnext.SDK.*
- API methods use
Option<T> types for optional parameters
- Responses provide
IsOk property and RawContent for result data
- Base URL is
https://api.legnext.ai (no /api suffix)