Rust Requires Chilkat v11.2.0+
Rust
AI: Simple Stateless Query
See more AI Examples
Demonstrates the simplest stateless query: asking an AI to "Say Hello". This query is standalone and not part of a conversation.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();
// The provider can be "openai", "google", "claude", "deepseek", "xai", or "perplexity".
// Support for additional providers will be added in future versions of Chilkat.
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");
// Add a text input.
let _ = ai.input_add_text("Say Hello.");
// Ask the AI for text output.
if ai.ask("text").is_err() {
println!("{}", ai.last_error_text());
return;
}
// Get the text response.
let sb_response = chilkat::StringBuilder::new();
let _ = ai.get_output_text_sb(&sb_response);
println!("{}", sb_response.get_as_string().unwrap_or_default());
// Sample output:
// Hello! How can I assist you today?
// -------------------------------------------------------------
// The response is in markdown format.
// Also see Markdown to HTML Conversion Examples.
// -------------------------------------------------------------