#diffusion #api #image #create #request #client #token

diffusion_to

Rust crate for interacting with the diffusion.to API

2 unstable releases

0.2.0 Oct 2, 2023
0.1.0 Sep 29, 2023

#5 in #diffusion

47 downloads per month
Used in diffusion_to_cli

MIT license

16KB
316 lines

diffusion_to

Rust crate for interacting with the diffusion.to API.

Using the crate

First, add the crate to the project.

cargo add diffusion_to

Instantiate a client, create an image request, and send it off. Wait for the image to be created and download it.

let client = DiffusionClient::new(args.api_key)?;

let request = ImageRequest::new(args.prompt)
    .update_steps(args.steps.try_into()?)
    .update_model(args.model.try_into()?)
let token = client.request_image(request).await?;

// wait for up to five minutes
let image = client
    .check_and_wait(token, Some(Duration::from_secs(300)))
    .await?;

println!("{}", image.raw)

lib.rs:

diffusion_to

diffusion_to is a library for interacting with the API for diffusion.to. This API makes it easy to create AI-generated images and download them in a base64 format to be used however is needed. All options available in the UI are available through the library, using enums where possible to prevent invalid requests from being made.

Example

Basic usage:

let client = DiffusionClient::new(args.api_key)?;

let request = ImageRequest::new(args.prompt)
    .update_steps(args.steps.try_into()?)
    .update_model(args.model.try_into()?)
let token = client.request_image(request).await?;

// wait for up to five minutes
let image = client
    .check_and_wait(token, Some(Duration::from_secs(300)))
    .await?;

println!("{}", iamge.raw)

Dependencies

~4–17MB
~248K SLoC