Expand description
The official Rust SDK for the Nolgia API: generate images, video, audio and 3D, run the NOLGIA Agent, and manage your library.
#[nolgia::tokio::main(crate = "nolgia::tokio")]
async fn main() -> nolgia::Result<()> {
let nolgia = nolgia::Client::from_env()?; // NOLGIA_API_KEY
let done = nolgia.subscribe(nolgia::image("gpt-image-2", "a red fox in the snow")).await?;
nolgia.download(done.url().unwrap(), "fox.png").await?;
Ok(())
}§Layout
Clientis the entry point. Build it withClient::new(an API key),Client::from_env(NOLGIA_API_KEY,NOLGIA_BASE_URL) orClient::builder(base URL, timeouts,RetryPolicy, idempotency).- Every API operation is a method on it, generated from the OpenAPI spec
(
api::Client):nolgia.list_models().send(). Request and response types live intypes. Append.typed()to get aResultwith a typedError. - Hand-written helpers cover the workflows:
image,videoandaudiobuild a request,Client::submit/Client::subscribe/Client::wait_jobfor generation,Client::quotefor prices,Client::upload_fileandClient::downloadfor files,Client::paginate_assetsfor lists,Client::job_eventsandClient::session_eventsfor live streams, andClient::run_agentfor the agent. blocking::Client(featureblocking) does the same without async.
§Errors
Error::Api is a refusal: its ApiError carries the HTTP status, the
machine-readable ErrorCode, the detail to show and the request_id
for support, with is_out_of_credits,
is_plan_required and
is_rate_limited for the common branches.
Error::Job is a generation that failed or was canceled, with its code
and whether the credits were refunded.
§Retries and idempotency
Requests the server refused for now (429) or failed to answer (5xx,
a dropped connection) are retried with exponential backoff, honouring
Retry-After, when repeating them cannot do the work twice. Generation
submits are safe to repeat: the API refuses an identical submit within
five minutes with 409 naming the existing job, and Client::submit
resolves its own retry onto that job. Set an Idempotency-Key
(SubmitOptions, Client::with_idempotency_key) to declare a
deliberate new generation of an identical request.
§Runtime
The SDK is async on tokio, re-exported as nolgia::tokio with
serde_json and json!, so cargo add nolgia is the whole install.
#[tokio::main] needs use nolgia::tokio; in scope, or write
#[nolgia::tokio::main(crate = "nolgia::tokio")].
Re-exports§
Modules§
- api
- The generated client: one method per API operation, request builders in
api::builder, schemas inapi::types. Generated bymake sdk-rustfrom the public OpenAPI spec; do not edit. - blocking
blocking - A synchronous client, for programs without an async runtime (feature
blocking).
Macros§
- json
- Construct a
serde_json::Valuefrom a JSON literal.
Structs§
- Agent
RunResult - The outcome of
Client::run_agent. - ApiError
- A refusal from the API: a non-2xx response, usually an RFC 7807 problem.
- Client
- A Nolgia API client.
- Client
Builder - Configures a
Client. - Generation
- A generation request ready to send: the endpoint and its JSON body.
- Generation
Result - A finished, successful generation.
- JobError
- A job that reached
failedorcanceled. - JobEvent
- One frame of a job’s status stream.
- JobHandle
- A submitted job. Cheap to clone.
- Media
- One file a finished job produced.
- Page
- One page from a cursor-paginated list.
- Retry
Policy - How the SDK retries a request the server refused for now (
429) or failed to answer (500,502,503,504, or a dropped connection). - RunAgent
Options - Options for
Client::run_agent. - Session
Event - One frame of an agent session’s event stream.
- SseEvent
- One raw server-sent event.
- Submit
Options - Options for
Client::submit_with. - Upload
Options - Options for
Client::upload_fileandClient::upload_bytes. - Uuid
- A Universally Unique Identifier (UUID).
- Wait
Options - Options for
Client::wait_job.
Enums§
- Agent
RunStatus - How an agent run ended.
- Error
- Every way an SDK call can fail.
- Error
Code - The machine-readable
codethe API puts on a refusal (error.code) or a failed job (failure.code). - Value
- Represents any valid JSON value.
Constants§
- API_
KEY_ ENV - The environment variable
Client::from_envreads the API key from. - BASE_
URL_ ENV - The environment variable
Client::from_envreads the base URL from. - DEFAULT_
BASE_ URL - The production API.
- STAGING_
BASE_ URL - The staging API. Staging keys are minted on stg.nolgia.ai and do not work against production.
- TOKEN_
ENV - Also accepted for the API key, as the CLI and the other SDKs’ examples use it.
Traits§
- Into
Generation - Anything
Client::submitaccepts. Implemented for the typed generation requests, their builders, andGeneration. - Stream
- A stream of values produced asynchronously.
- Stream
Ext - An extension trait for
Streams that provides a variety of convenient combinator functions. - Typed
- Turns a generated call’s result into
nolgia::Result<T>: the response body, or a typedErrorwhoseApiErrorcarries the problem’s status,code,detailandrequest_id.
Functions§
- audio
- Audio:
POST /generate/audiowithmodelandprompt(the text to speak for a voice model, the description for music and sound). Pick a voice with.set("voice", "...");GET /voicesandGET /modelslist them. - content_
type_ for - The MIME type the upload endpoint expects for a file name, from its
extension.
Nonefor a type the API does not accept. - image
- An image generation:
POST /generate/imagewithmodelandprompt. Add any other field ofGenerateImageRequestwithGeneration::set. - paginate
- Every item of a cursor-paginated list, fetching pages as the stream is read.
- video
- A video generation:
POST /generate/videowithmodelandprompt. Addduration_seconds,aspect_ratio, reference assets and the rest withGeneration::set.
Type Aliases§
- Question
Handler - Answers the agent’s closing question;
Noneends the run withAgentRunStatus::AwaitingInput. - Result
Result<T, nolgia::Error>.- Status
Callback - Called with each new state of a job while waiting.