SDKv0.3.0

Rust SDK

Integrate Meridian inference into your Rust applications using the async-openai crate with a custom API base URL. Drop-in compatible with any OpenAI-shaped client.

Quickstart

Add to your Cargo.toml:

[dependencies]
async-openai = "0.23"
tokio = { version = "1", features = ["full"] }

Usage

Configure the client with api_base pointing to Meridian and your API key:

use async_openai::{
    Client, config::OpenAIConfig,
    types::CreateChatCompletionRequestArgs,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = OpenAIConfig::new()
        .with_api_base("https://api.getnimbus.net/v1")
        .with_api_key("mk-xxxxxxxxxxxxxxxxxxxxxxxx");

    let client = Client::with_config(config);

    let request = CreateChatCompletionRequestArgs::default()
        .model("meridian-1")
        .messages(vec![
            ("system", "You are a helpful assistant.").into(),
            ("user", "Explain Rust traits in one sentence.").into(),
        ])
        .max_tokens(128u32)
        .build()?;

    let response = client.chat().create(request).await?;

    println!("{}", response.choices[0]
        .message.content
        .unwrap_or_default());

    Ok(())
}

Streaming

use async_openai::types::CreateChatCompletionRequestArgs;
use futures::StreamExt;

let request = CreateChatCompletionRequestArgs::default()
    .model("meridian-1")
    .messages(vec![("user", "Write a haiku about Rust.").into()])
    .build()?;

let mut stream = client.chat().create_stream(request).await?;

while let Some(result) = stream.next().await {
    match result {
        Ok(response) => {
            if let Some(content) = &response.choices[0].delta.content {
                print!("{content}");
            }
        }
        Err(e) => eprintln!("Stream error: {e}"),
    }
}