floopy-sdk (Rust)
Official Floopy AI Gateway SDK for Rust. Drop-in wrapper around the
async-openaicrate with Floopy's cache, audit, experiments, routing, and security on top.
Why
floopy-sdk wraps the official async-openai crate and points it at the
Floopy gateway, so:
- Zero migration cost for chat and embeddings — same types, same
methods, via
client.openai(). - Upstream updates to
async-openaireach you oncargo updatewithout forks or parity drift. - Floopy-only features (audit, experiments, constraints, decision
export, feedback, routing dry-run, sessions) get first-class typed,
async methods instead of hand-rolled
reqwestcalls.
Install
The crate is published as floopy-sdk and imported as floopy. Requires
Rust >= 1.82. It is fully async (Tokio).
Quick start
use Floopy;
use ;
async
client.openai() returns a lazily-built async_openai::Client pre-pointed
at the gateway; chat/embeddings/models behave exactly like upstream. The
wrapped crate is re-exported as floopy::async_openai, so you don't declare
it separately unless you want to.
Migrating from async-openai
- use async_openai::{Client, config::OpenAIConfig};
- let client = Client::with_config(
- OpenAIConfig::new().with_api_key(std::env::var("OPENAI_API_KEY")?),
- );
+ use floopy::Floopy;
+ let fl = Floopy::new(std::env::var("FLOOPY_API_KEY")?)?;
+ let client = fl.openai();
let response = client.chat().create(request).await?;
Floopy options (cache, prompt versioning, security firewall)
use ;
#
These map to Floopy-* headers forwarded to every request (both
OpenAI-compat calls and Floopy-only ones). Per-call overrides go through a
trailing RequestOptions argument on every resource method.
| Option | Header | Purpose |
|---|---|---|
cache.enabled |
Floopy-Cache-Enabled |
Toggle exact + semantic cache |
cache.bucket_max_size |
Floopy-Cache-Bucket-Max-Size |
Max entries per semantic bucket |
prompt_id |
Floopy-Prompt-Id |
Stored prompt to resolve |
prompt_version |
Floopy-Prompt-Version |
Pinned version for prompt_id |
llm_security_enabled |
floopy-llm-security-enabled |
LLM firewall pre-check |
Floopy-only resources
Each resource maps to a public /v1/* gateway endpoint and is typed
end-to-end. Errors are [floopy::Error] variants (see below). Pagination
and export are futures::Streams.
# use Floopy;
# use *;
# use StreamExt;
# async
Batch + Files
OpenAI-shaped Batch + Files passthrough. A batch carries no model up
front, so select the upstream with RequestOptions::new().provider(...)
(the floopy-provider header) — optional when the key has one provider.
# use floopy::Floopy;
# use floopy::types::{BatchCreateParams, FileUploadParams};
# use floopy::RequestOptions;
# async fn run(client: Floopy) -> Result<(), Box<dyn std::error::Error>> {
let file = client.files().upload(
FileUploadParams {
file: std::fs::read("requests.jsonl")?,
filename: Some("requests.jsonl".into()),
purpose: "batch".into(),
},
RequestOptions::new().provider("openai"),
).await?;
let batch = client.batches().create(
BatchCreateParams {
input_file_id: file.id,
endpoint: "/v1/chat/completions".into(),
completion_window: "24h".into(),
metadata: None,
},
RequestOptions::new().provider("openai"),
).await?;
let done = client.batches().retrieve(&batch.id, RequestOptions::new().provider("openai")).await?;
if done.status.as_deref() == Some("completed") {
if let Some(out) = done.output_file_id {
let bytes = client.files().content(&out, RequestOptions::new().provider("openai")).await?;
let _ = bytes;
}
}
# Ok(()) }
files().list/retrieve/delete and batches().list/cancel are also
available.
Error handling
Every Floopy-only call returns Result<T, floopy::Error>:
# use ;
# use DecisionListParams;
# async
Error::status(), Error::request_id(), Error::feature() and
Error::retry_after_seconds() are available on every variant. Errors from
chat/embeddings are emitted by async-openai
(async_openai::error::OpenAIError), not this crate.
Security
- The API key is only ever sent in the
Authorizationheader and is never rendered byDebug; the SDK never logs request or response bodies. - TLS certificate verification is on by default (rustls + webpki-roots).
- Releases are immutable, signed crates.io publishes via Trusted Publishing (OIDC) — no long-lived registry token in this repo.
Self-hosting / custom base URL
# use Floopy;
#
Links
- Full SDK guide: https://floopy.ai/docs/guides/sdks/floopy-sdk-rust (Português)
- API docs: https://docs.rs/floopy-sdk
- API reference: https://floopy.ai/docs/guides/api-reference
- Changelog:
CHANGELOG.md
License
Apache-2.0 © Floopy