Rust Requires Chilkat v11.4.0+
Rust
Simple AI Image Generation
See more AI Examples
Create an image by providing a text description.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let ai = chilkat::Ai::new();
ai.set_provider("openai");
// Use your provider's API key.
ai.set_api_key("MY_API_KEY");
// Choose a model.
ai.set_model("gpt-5.6-terra");
let ask_params = chilkat::JsonObject::new();
let _ = ask_params.update_string("image.output_format", "jpeg");
let _ = ask_params.update_string("image.size", "1024x1024");
let _ = ask_params.update_string("image.quality", "low");
let _ = ai.set_ask_params(&ask_params);
let _ = ai.input_add_text("Generate a small, cute illustration of a gray tabby cat hugging a happy otter wearing an orange scarf");
// Ask the AI for image output.
if ai.ask("image").is_err() {
println!("{}", ai.last_error_text());
return;
}
// Get the image response data.
let bd_image_data = chilkat::BinData::new();
if ai.get_output_bd(&bd_image_data).is_err() {
println!("{}", ai.last_error_text());
return;
}
let _ = bd_image_data.write_file("c:/aaworkarea/out.jpg");
println!("Success.");