open_ai_rust 0.2.15

Open AI SDK for Rust. To my knowledge, the only fully comprehensive and up-to-date Open AI crate built in and for Rust. Provides both low-level control with high level ergonomics for doing cool things (the whole reason we use Rust in the first place). Is maintained and has been used and tested in products used in production.
Documentation
use reqwest::Client;
use serde_json::Value;

use crate::{API_KEY, OPENAI_MSG_ENDPOINT, helpers::{get_key, get_url}, logoi::{input::payload::ChatPayLoad, output::AiMsgResponse}};

pub mod embed;
pub mod audio;

pub async fn open_ai_msg(
    payload: ChatPayLoad
) -> Result<AiMsgResponse, String> {
    let client = Client::new();
    let url = get_url("/v1/chat/completions")?;
    let response = match client.post(url)
        .header("Content-Type", "application/json")
        .header("Authorization", format!("Bearer {}", get_key()?))
        .json(&payload)
        .send()
        .await {
            Ok(data) => data,
            Err(e) => return Err(format!("Error sending request to Open Ai: {}", e))
        };

        if response.status().is_success() {
            let json: Value = response.json().await.map_err(|e| format!("Error reading response JSON: {}", e))?;
            let response_data: AiMsgResponse = serde_json::from_value(json).map_err(|e| format!("Error parsing OpenAI response: {}", e))?;
            Ok(response_data)
        } else {
        let status = response.status();
        return Err(format!("Open Ai Error! Status: {status}       Err Msgs: {}", match response.text().await {
            Ok(data) => data,
            Err(e) => format!("Error parsing Open Ai response: {}", e)
        }))
    }
}