audacity-sdk (Rust)
Rust SDK for the Audacity Investments AI gateway. Exposes an Amazon Bedrock Converse-shaped API so teams migrating off Bedrock can swap the client construction + API key and keep the rest of their code.
Installation
Add to Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["rt-multi-thread", "macros"] }
Quickstart
Converse (non-streaming)
use ;
async
ConverseStream (streaming)
use ;
async
Images (vision models)
Bedrock-style image content blocks are supported in user messages. Pass raw bytes (base64-encoded for you) or a URL (Audacity extension):
use ;
let image_bytes = read?;
let response = client.converse
.model_id
.messages
.send
.await?;
// Or reference a hosted image directly (not available in Bedrock):
// source: ImageSource::Url("https://example.com/photo.jpg".into())
ImageFormat is one of Png, Jpeg, Gif, Webp. Use a vision-capable model.
Migrating from aws-sdk-bedrockruntime
The SDK is designed to be a drop-in. Here is a side-by-side diff:
-use aws_sdk_bedrockruntime::Client;
-use aws_sdk_bedrockruntime::types::{ContentBlock, ConversationRole, Message};
+use audacity_sdk::{Client, ContentBlock, ConversationRole, Message};
-let config = aws_config::load_from_env().await;
-let client = Client::new(&config);
+let client = audacity_sdk::Client::from_env()?; // reads AUDACITY_API_KEY
let response = client.converse()
- .model_id("anthropic.claude-3-5-sonnet-20241022-v2:0")
+ .model_id("gpt-5.4-mini")
.messages(
Message::builder()
.role(ConversationRole::User)
- .content(ContentBlock::Text("Hello".into()))
+ .content(ContentBlock::Text("Hello".into()))
.build()?
)
.send()
.await?;
Error handling
use ;
match client.converse.model_id.messages.send.await
Error variants
| Variant | Retryable | Trigger |
|---|---|---|
Validation |
no | 400 / invalid request |
AccessDenied |
no | 401/403 / bad key |
ServiceQuotaExceeded |
no | 402 / budget exceeded |
ResourceNotFound |
no | 404 / unknown model |
ModelTimeout |
yes | 408 / TIMEOUT_ERROR |
Throttling |
yes | 429 / rate limited |
ModelError |
no | model-side error |
ModelStreamError |
no | stream-specific error |
ServiceUnavailable |
yes | 502/503/504 |
InternalServer |
yes | 500 |
MissingApiKey |
— | no key in env/config |
Sdk |
yes (network) | network / decode failure |
Every server error carries ErrorDetails { message, status_code, error_code, request_id, retry_after_seconds, raw_body }.
Configuration
| Source | API key | Base URL |
|---|---|---|
| Explicit | Config::builder().api_key("…") |
.base_url("…") |
| Environment | AUDACITY_API_KEY |
AUDACITY_BASE_URL |
| Default | — | https://portal.audacityinvestments.com |
Other options:
use Duration;
let config = builder
.api_key
.base_url
.timeout
.max_retries // 3 total attempts
.build?;
let client = new;
License
Copyright Audacity Investments. All rights reserved.
See LICENSE.