#artificial-intelligence #sdk #openai

aisdk

An open-source Rust library for building AI-powered applications, inspired by the Vercel AI SDK. It provides a robust, type-safe, and easy-to-use interface for interacting with various Large Language Models (LLMs).

3 unstable releases

Uses new Rust 2024

new 0.2.1 Dec 2, 2025
0.2.0 Dec 2, 2025
0.1.0 Sep 7, 2025

#518 in Asynchronous

MIT license

185KB
4K SLoC

AISDK

Build Status License: MIT Issues PRs Welcome

An open-source Rust library for building AI-powered applications, inspired by the Vercel AI SDK. It provides a type-safe interface for interacting with Large Language Models (LLMs).

Installation

cargo add aisdk

Usage

Enable Providers such as OpenAI, Anthropic, Google and more

Example with OpenAI provider

cargo add aisdk --features openai

Basic Text Generation

use aisdk::{
    core::{LanguageModelRequest},
    providers::openai::OpenAI,
};

async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let openai = OpenAI::new("gpt-5");

    let result = LanguageModelRequest::builder()
        .model(openai)
        .prompt("What is the meaning of life?")
        .build()
        .generate_text() // or stream_text() for streaming
        .await?;

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

Agents / Tools

Defining a Tool

Use the #[tool] macro to expose a Rust function as a callable tool.

use schemars::JsonSchema; // used to convert tool function to json schema

#[tool]
/// Get the weather information given a location
pub fn get_weather(location: String) {
    let weather = match location.as_str() {
        "New York" => 75,
        "Tokyo" => 80,
        _ => 70,
    };
    Ok(weather.to_string())
}

Using Tools in an Agent

Register tools with an agent so the model can call them during its reasoning loop.

use aisdk::{
    core::{LanguageModelRequest},
    utils::step_count_is,
    providers::openai::OpenAI,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let result = LanguageModelRequest::builder()
        .model(OpenAI::new("gpt-4o"))
        .system("You are a helpful assistant with access to tools.")
        .prompt("What is the weather in New York?")
        .with_tool(get_weather())
        .stop_when(step_count_is(3)) // Limit agent loop to 3 steps
        .build()
        .generate_text()
        .await?;

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

Prompts

The AISDK prompt feature provides a powerful, file-based template system for managing AI prompts using the Tera template engine. It allows you to create reusable prompt templates with variable substitution, conditionals, loops, and template inclusion. See Examples for more template examples. Enable with cargo add aisdk --features prompt

Roadmap

  • Agents
  • Tool Execution
  • Prompt Templating
  • Stractured Output (JSON Schema)
  • Language Model Request Support (Text Generation, Streaming)
  • Embedding Model Request Support
  • Image Model Request Support
  • Voice Model Request Support
  • Additional Providers

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

Licensed under the MIT License. See LICENSE for details.

Dependencies

~4–22MB
~239K SLoC