Rust
Rust async-openai with an OpenAI-compatible uncensored API
Use the async-openai crate with Abliterator: OpenAIConfig::with_api_base, typed chat requests, streaming with create_stream, and create_byot to read the cost field.
Build the client with Client::with_config(OpenAIConfig::new().with_api_base("https://abliterator.ai/v1").with_api_key(std::env::var("ABL_API_KEY")?)) and enable the chat-completion feature.
async-openai targets OpenAI's API, but its README has a section on OpenAI-compatible providers: you change the base URL in OpenAIConfig, and the byot feature lets you send and receive your own types. These examples follow the crate's own 0.43 examples; no Rust toolchain was available on the machine used to check this page, so they were compared against the crate source rather than compiled.
Cargo.toml
[package]
name = "abl-rs"
version = "0.1.0"
edition = "2021"
[dependencies]
async-openai = { version = "0.43", features = ["chat-completion", "byot"] }
futures = "0.3"
serde_json = "1"
tokio = { version = "1", features = ["full"] }
export ABL_API_KEY="sk-abl-v1-..."
A typed request
use std::error::Error;
use async_openai::{
config::OpenAIConfig,
types::chat::{
ChatCompletionRequestSystemMessage, ChatCompletionRequestUserMessage,
CreateChatCompletionRequestArgs,
},
Client,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let config = OpenAIConfig::new()
.with_api_base("https://abliterator.ai/v1")
.with_api_key(std::env::var("ABL_API_KEY")?);
let client = Client::with_config(config);
let request = CreateChatCompletionRequestArgs::default()
.model("kimi-k3.1-pro-abliterated")
.max_completion_tokens(800u32)
.messages([
ChatCompletionRequestSystemMessage::from("You are a Rust security reviewer.").into(),
ChatCompletionRequestUserMessage::from(
"When is unsafe justified in FFI code, and how should a reviewer audit it?",
)
.into(),
])
.build()?;
let response = client.chat().create(request).await?;
for choice in &response.choices {
println!("{}", choice.message.content.as_deref().unwrap_or_default());
}
if let Some(usage) = response.usage {
println!("{} prompt / {} completion tokens", usage.prompt_tokens, usage.completion_tokens);
}
Ok(())
}
Streaming
create_stream returns a Stream of chunk results. Abliterator's final chunk carries usage and no choices, so iterating choices handles it without a special case:
use std::error::Error;
use std::io::{stdout, Write};
use async_openai::{
config::OpenAIConfig,
types::chat::{ChatCompletionRequestUserMessageArgs, CreateChatCompletionRequestArgs},
Client,
};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = Client::with_config(
OpenAIConfig::new()
.with_api_base("https://abliterator.ai/v1")
.with_api_key(std::env::var("ABL_API_KEY")?),
);
let request = CreateChatCompletionRequestArgs::default()
.model("deepseek-v4.1-flash-abliterated")
.messages([ChatCompletionRequestUserMessageArgs::default()
.content("Explain how fuzzing found memory-safety bugs in C parsers, and what Rust changes.")
.build()?
.into()])
.build()?;
let mut stream = client.chat().create_stream(request).await?;
let mut out = stdout().lock();
while let Some(result) = stream.next().await {
let chunk = result?;
for choice in &chunk.choices {
if let Some(text) = &choice.delta.content {
write!(out, "{text}")?;
}
}
out.flush()?;
}
writeln!(out)?;
Ok(())
}
Read Abliterator's extra fields with create_byot
The typed structs follow OpenAI's schema, so Abliterator's usage.cost is dropped during deserialization. With the byot feature, create_byot accepts and returns any serde types, here serde_json::Value:
use std::error::Error;
use async_openai::{config::OpenAIConfig, Client};
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = Client::with_config(
OpenAIConfig::new()
.with_api_base("https://abliterator.ai/v1")
.with_api_key(std::env::var("ABL_API_KEY")?),
);
let response: Value = client
.chat()
.create_byot(json!({
"model": "deepseek-v4.1-flash-abliterated",
"stream": false,
"max_tokens": 300,
"messages": [
{"role": "system", "content": "Classify log lines for a SIEM: benign, suspicious or malicious, with one reason."},
{"role": "user", "content": "powershell.exe -nop -w hidden -enc SQBFAFgA..."}
]
}))
.await?;
println!("{}", response["choices"][0]["message"]["content"]);
println!("cost (USD): {}", response["usage"]["cost"]);
Ok(())
}
The crate asks byot callers to set "stream" themselves: false here, true for create_stream_byot, which does the same for streams. Use a struct with #[serde(flatten)] extras if you want types and Abliterator fields together.
Troubleshooting
no method named chat found for struct Client. Thechat-completionfeature is off. Add it inCargo.toml.no method named create_byot. Enable thebyotfeature.ApiErrorwith a 404 status.with_api_basemust behttps://abliterator.ai/v1, including/v1; the crate appends/chat/completions.JSONDeserializeerrors. A typed struct did not match a response field. Switch that call tocreate_byotwithValueand report the mismatch upstream if it is a schema bug.- TLS build errors on musl or minimal images. async-openai uses
reqwestwith rustls by default. Pick another TLS feature only after disabling default features, as the README describes.
Frequently asked questions
Which async-openai features do I need for Abliterator?
chat-completion for client.chat() and its types, plus byot if you want the generic create_byot methods. The Responses, embeddings, images and audio features call endpoints Abliterator does not serve.
How do I read fields that async-openai does not model, like usage.cost?
Use create_byot with serde_json::Value (or your own struct with serde) as the response type. The typed CompletionUsage struct has no cost field, so serde drops it.
Does async-openai read OPENAI_BASE_URL?
Yes. OpenAIConfig::new() falls back to OPENAI_BASE_URL and OPENAI_API_KEY. Calling with_api_base and with_api_key explicitly avoids surprises when those are set for another tool.