Skip to main content
Fast, type-safe implementation using Axum with async/await and Tokio runtime. Tested end-to-end with GEPA - achieves 100% accuracy on Banking77.

Quick Start

cd examples/polyglot/rust/
cargo run --release
With authentication:
ENVIRONMENT_API_KEY=your-secret cargo run --release

Dependencies

[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.11", features = ["json"] }
anyhow = "1"
tracing = "0.1"
tracing-subscriber = "0.3"

URL Construction

The most critical part is URL construction with query parameters. The inference_url from the optimizer includes query params for tracing:
// CORRECT: Insert path before query string
let url = if let Some(query_start) = inference_url.find('?') {
    let (base, query) = inference_url.split_at(query_start);
    format!("{}/chat/completions{}", base.trim_end_matches('/'), query)
} else {
    format!("{}/chat/completions", inference_url.trim_end_matches('/'))
};

// Result: http://host/path/chat/completions?cid=xxx

Cross-Compilation

# Linux
cargo build --release --target x86_64-unknown-linux-gnu

# macOS ARM64
cargo build --release --target aarch64-apple-darwin

# Windows
cargo build --release --target x86_64-pc-windows-gnu

When to Choose Rust

  • You want strong type safety and compile-time guarantees
  • You need async/await for concurrent processing
  • You’re comfortable with Rust’s ownership model

Full Example

rust/src/main.rs

Managed Deploy (Cloud)

You can deploy a Rust (or any language) LocalAPI using the Rust SDK and the backend-managed build/run flow. Provide a Dockerfile + context directory and get back a proxy URL.
use synth_ai::{Synth, LocalApiDeploySpec, LocalApiLimits};

#[tokio::main]
async fn main() -> Result<(), synth_ai::Error> {
    let synth = Synth::from_env()?;
    let spec = LocalApiDeploySpec {
        name: "my-localapi".to_string(),
        dockerfile_path: "Dockerfile".to_string(),
        entrypoint: "python /app/server.py".to_string(),
        entrypoint_mode: "command".to_string(),
        port: 8000,
        description: None,
        env_vars: Default::default(),
        limits: LocalApiLimits::default(),
        metadata: Default::default(),
    };

    let result = synth
        .deploy_localapi_from_dir(spec, "./my_task_app", true, 600.0)
        .await?;

    println!("{}", result.task_app_url);
    Ok(())
}