use valyu::ValyuClient;#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let client = ValyuClient::new("your-api-key"); let response = client.ask("What are the latest developments in quantum computing?").await?; if response.success { if let Some(contents) = &response.contents { println!("{}", contents); } } Ok(())}
Use the AnswerRequest builder for anything beyond a plain question, then call client.answer(&request):
use serde_json::json;use valyu::AnswerRequest;// Steer tone and formatlet req = AnswerRequest::new("Explain quantum computing") .with_system_instructions("Explain clearly with practical examples, no jargon.");// Restrict to authoritative sourceslet req = AnswerRequest::new("React performance best practices") .with_search_type("web") .with_included_sources(vec!["react.dev".to_string(), "developer.mozilla.org".to_string()]);// Recent, location-specific answerslet req = AnswerRequest::new("Current renewable energy incentives") .with_country_code("US") .with_date_range("2024-01-01", "2024-12-31");// Structured output - pass a JSON schema, get back a structured objectlet req = AnswerRequest::new("What is the impact of AI on software development?") .with_structured_output(json!({ "type": "object", "properties": { "summary": {"type": "string"}, "key_impacts": {"type": "array", "items": {"type": "string"}} }, "required": ["summary", "key_impacts"] }));let response = client.answer(&req).await?;// With a schema, `contents` comes back as a JSON object instead of a string.if let Some(contents) = &response.contents { if contents.is_object() { println!("{}", serde_json::to_string_pretty(contents)?); }}
For open-ended, multi-step work, reach for DeepResearch instead of Answer.