Skip to content

Rust

Overview

Floopy is a zero-SDK gateway. The async-openai crate supports custom API base URLs, so you can route all requests through Floopy without any extra dependencies. You get caching, rate limiting, fallbacks, and observability for free.

Installation

Add to your Cargo.toml:

Terminal window
cargo add async-openai tokio

Configuration

use async_openai::{Client, config::OpenAIConfig};
let config = OpenAIConfig::new()
.with_api_base("https://api.floopy.ai/v1")
.with_api_key("fp_your_api_key"); // starts with fp_
let client = Client::with_config(config);

Set your Floopy API key (starts with fp_). You can create one in the dashboard.

Basic Request

use async_openai::types::{
ChatCompletionRequestUserMessageArgs,
CreateChatCompletionRequestArgs,
};
let request = CreateChatCompletionRequestArgs::default()
.model("gpt-4o")
.messages(vec![
ChatCompletionRequestUserMessageArgs::default()
.content("Explain quantum computing in one sentence.")
.build()?
.into(),
])
.build()?;
let response = client.chat().create(request).await?;
println!("{}", response.choices[0].message.content.as_ref().unwrap());

Streaming

use futures::StreamExt;
let request = CreateChatCompletionRequestArgs::default()
.model("gpt-4o")
.messages(vec![
ChatCompletionRequestUserMessageArgs::default()
.content("Write a short poem.")
.build()?
.into(),
])
.stream(true)
.build()?;
let mut stream = client.chat().create_stream(request).await?;
while let Some(result) = stream.next().await {
match result {
Ok(response) => {
for choice in &response.choices {
if let Some(ref content) = choice.delta.content {
print!("{}", content);
}
}
}
Err(e) => eprintln!("Error: {}", e),
}
}

Custom Headers

Pass Floopy-specific headers by configuring a custom reqwest client:

use reqwest::header::{HeaderMap, HeaderValue};
let mut headers = HeaderMap::new();
headers.insert("Floopy-Cache", HeaderValue::from_static("semantic"));
headers.insert("floopy-property-environment", HeaderValue::from_static("production"));
headers.insert("floopy-fallback", HeaderValue::from_static("claude-sonnet-4-20250514"));
let http_client = reqwest::Client::builder()
.default_headers(headers)
.build()?;
let config = OpenAIConfig::new()
.with_api_base("https://api.floopy.ai/v1")
.with_api_key("fp_your_api_key");
let client = Client::with_config(config).with_http_client(http_client);
HeaderDescription
Floopy-CacheCache strategy: semantic or exact
floopy-property-*Attach custom metadata for filtering in the dashboard
floopy-fallbackFallback model if the primary provider fails
floopy-session-idGroup related requests into a session
floopy-user-idAssociate requests with an end user

See the Headers Reference for the full list.