openai-realtime-proxy

Crates.ioopenai-realtime-proxy
lib.rsopenai-realtime-proxy
version0.1.0
sourcesrc
created_at2024-10-01 22:01:12.37616
updated_at2024-10-01 22:01:12.37616
descriptionSafely deploy OpenAI's Realtime APIs in less than 5 minutes!
homepage
repositoryhttps://github.com/m1guelpf/openai-realtime-proxy
max_upload_size
id1393450
size46,310
Miguel Piedrafita (m1guelpf)

documentation

README

openai-realtime-proxy

Safely deploy OpenAI's Realtime APIs in less than 5 minutes!

crates.io download count badge docs.rs

The OpenAI Realtime API provides a seamless voice-to-voice conversation experience. To reduce latency, it establishes a WebSocket connection between the client and the backend. However, production apps likely need a proxy sitting in the middle to handle authentication, rate limiting, and avoid leaking sensitive data.

This library takes care of the proxying part, allowing you to focus on the rest of your application.

use axum::{extract::WebSocketUpgrade, response::IntoResponse, routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new().route("/ws", get(ws_handler));

    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

async fn ws_handler(ws: WebSocketUpgrade) -> impl IntoResponse {
    // check for authentication/access/etc. here

    let proxy = realtime_proxy::Proxy::new(
        std::env::var("OPENAI_API_KEY").expect("OPENAI_API_TOKEN env var not set.")
    );

    ws.on_upgrade(|socket| proxy.handle(socket))
}

Refer to the documentation on docs.rs for detailed usage instructions.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 1

cargo fmt