# Basic Usage (/docs/basic-usage)
The AI SDK standardizes integrating artificial intelligence (AI) models across [supported providers](/docs/#model-providers). This enables developers to focus on building great AI applications, not waste time on technical details.
For example, here’s how you can generate text with various models using the AI SDK
### Enable the [Provider](/docs/#model-providers) of your choice
You can enable the provider you want by using the feature flag of the provider. e.g. for [OpenAI](/docs/providers/openai)
```bash
cargo add aisdk --features openai # anthropic, google or any other provider
```
### Generating Text
To generate text, you can use the `LanguageModelRequest` builder and call the `generate_text()` method. This method returns a `GenerateTextResponse` which contains the generated text and other information such as token usage statistics, stop reason, and tool call results
you can find more info about generating text [here](/docs/concepts/generating-text#generate_text).
### Streaming Text
To stream text, you can use the `LanguageModelRequest` builder and call the `stream_text()` method. This method returns a `StreamTextResponse` which contains the generated text and other information such as token usage statistics, stop reason, and tool call results.
You can find more info about streaming text [here](/docs/concepts/generating-text#stream_text).
## Next Steps
* Take a deeper look at [`LanguageModelRequest`](/docs/concepts/generating-text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Introduction (/docs)
## Core Features
} title="Strongly Typed">
No more “model doesn’t support tool calling” errors in prod. aisdk guarantees the model fits the task at compile time.
} title="Provider Agnostic">
Designed to be provider agnostic, allowing you to easily integrate with any AI provider.
} title="Agents">
Build AI agents that can interact with users and perform tasks.
} title="Seamless Integrations">
Seamlessly integrates with Axum, Actix and more. Compatible with Vercel's ai-sdk ui for React, Svelte, Vue and more.
## Model Providers
AISDK supports a wide range of AI providers, including:
*
Amazon Bedrock
*
Anthropic
*
DeepSeek
*
Google
*
Groq
*
OpenRouter
*
OpenAI
*
Together AI
*
Vercel
*
xAI
*
zAI
* And 65+ Other providers. See the provider docs in the navigation for the complete list.
# Installation (/docs/installation)
## Installation
To add the AISDK, you can use the following command:
```bash
cargo add aisdk
```
This will add aisdk to your project's dependencies.
## Feature Flags
`aisdk` includes several features that extend its functionality
* **[Providers](/docs#model-providers)** interact with different AI model providers.
```bash
cargo add aisdk --features # e.g. openai
```
* **[Prompt](/docs/concepts/prompt)** use the built-in prompt templating system.
```bash
cargo add aisdk --features prompt
```
You can find more information about the available features in the API documentations.
# Agents (/docs/concepts/agents)
Agents are **Large Language Models (LLMs)** that use **tools** in a **loop** to accomplish complex tasks. Unlike standard generation, an agent can observe the results of its actions and decide on the next step autonomously.
In AISDK, these components work together:
* **LLMs**: Act as the "brain," processing input and deciding which actions to take.
* **Tools**: Extend the model's capabilities (e.g., searching the web, querying a database).
* **Loop**: orchestrates execution through:
* **Context management** - Maintaining conversation history and deciding what the model sees at each step
* **Stopping conditions** - Determining when the loop (task) is complete
## The Agentic Loop
When you provide tools to a [LanguageModelRequest](/docs/concepts/generating-text), AISDK automatically manages the **Agentic Loop**.
Every interaction between the model and the environment (including tool calls and intermediate reasoning) is recorded as a **Step**. A single complex request might result in multiple steps, each containing full context.
1. **Reasoning**: The model decides to call one or more tools. This triggers a new **Step**.
2. **Action**: AISDK executes the tools and captures their results.
3. **Observation**: The results are fed back into the conversation history.
4. **Re-evaluation**: The model decides the next step based on the new context.
## Example: The Weather Agent
Here is a example agent that uses multiple tools to answer questions.
```rust
use aisdk::core::{LanguageModelRequest, Tool, utils::step_count_is};
use aisdk::providers::OpenAI;
use aisdk::macros::tool;
#[tool]
/// Get the current weather in a specific location
fn get_weather(location: String) -> Tool {
// In a real app, this would call a weather API
Ok(format!("The weather in {} is 72°F and sunny.", location))
}
#[tool]
/// Convert Fahrenheit to Celsius
fn fahrenheit_to_celsius(f: f32) -> Tool {
let c = (f - 32.0) * 5.0 / 9.0;
Ok(format!("{:.1}°C", c))
}
#[tokio::main]
async fn main() -> Result<(), Box> {
let weather_agent = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.system("You are a helpful weather assistant.")
.prompt("What is the weather in San Francisco in Celsius?")
.with_tool(get_weather())
.with_tool(fahrenheit_to_celsius())
.stop_when(step_count_is(10))
.build()
.generate_text()
.await?;
println!("Final Answer: {:?}", weather_agent.text());
Ok(())
}
```
## Accessing Step Metadata
You can access the history of these turns from the response. Each **Step** provides:
* `step_id`: The chronological identifier of the turn.
* `messages()`: All messages recorded during this specific step.
* `usage()`: Token usage statistics for this turn.
* `tool_calls()`: Any tools requested by the model.
* `tool_results()`: Any results received from tools.
```rust
for step in weather_agent.steps() {
println!("--- Turn {} ---", step.step_id);
println!("Messages in this turn: {} Usage: {:?}", step.messages().len(), step.usage());
}
```
## Loop Control (`stop_when`)
Because agents operate in a loop, it is critical to prevent infinite execution or excessive token usage. AISDK provides the `.stop_when()` method to define explicit exit conditions.
The `stop_when` method accepts a closure with the following signature: `Fn(&LanguageModelOptions) -> bool`. This closure receives the current state of the request (including all interaction history and options) and returns `true` if the loop should terminate.
```rust
/// Example: Stop when total token usage exceeds 1000:
.stop_when(|options| options.usage().total_tokens > 1000)
/// Example: Stop if the last assistant message contains "DONE":
.stop_when(|options| {
options.text().map_or(false, |t| t.contains("DONE"))
})
/// Example: Stop after 5 tool calls:
.stop_when(|options| {
options.tool_calls().map_or(false, |calls| calls.len() > 5)
})
```
#### Using `step_count_is` Helper:
The most common way to control an agent loop is by limiting the number of turns (steps). AISDK provides a `step_count_is(n)` utility for this purpose.
```rust
use aisdk::core::utils::step_count_is;
// Stop after 3 steps
.stop_when(step_count_is(3))
```
## Lifecycle Hooks
Hooks allow you to intercept the agent at different stages of its thinking process. This is powerful for logging, custom moderation, or dynamically adjusting the agent's context.
### `on_step_start`
Runs **before** the model generates a response for a specific step. It receives a mutable reference to the current options, allowing you to modify the request context on the fly.
**Signature**: `Fn(&mut LanguageModelOptions)`
```rust
/// Example: Dynamically update the system prompt based on turn count:
.on_step_start(|options| {
let turn = options.steps().len();
if turn > 3 {
options.system = Some("You are now in 'Critical Mode'. Be brief.".into());
}
})
/// Example: Increase temperature as the conversation progresses:
.on_step_start(|options| {
let turn = options.steps().len();
options.temperature = Some(turn as u32 * 10); // Increases randomness
})
```
### `on_step_finish`
Runs **after** a model response is received but **before** tools are executed (or after the final response). It is ideal for observing the model's intent or performing safety checks.
**Signature**: `Fn(&mut LanguageModelOptions)`
```rust
/// Example: Log the model's intent or reasoning:
.on_step_finish(|options| {
if let Some(step) = options.last_step() {
println!("Turn {} finished. Reasoning: {:?}", step.step_id, step.usage());
}
})
/// Example: Monitor for specific tool usage:
.on_step_finish(|options| {
if let Some(calls) = options.tool_calls() {
if calls.iter().any(|c| c.function.name == "delete_database") {
println!("WARNING: Agent requested a dangerous operation!");
}
}
})
```
## Workflow Patterns
While the automatic loop is powerful, many production systems require more structure. You can combine core AISDK primitives to implement advanced orchestration patterns.
### Routing
Use a fast/cheap model to classify a query, then route it to a specialized agent or workflow.
```rust
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(JsonSchema, Deserialize, Debug)]
enum QueryType {
Technical,
Billing,
General,
}
// 1. Classify the query using Structured Output
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_4o_mini())
.prompt(user_query)
.schema::()
.build()
.generate_text()
.await?;
let query_type: QueryType = response.into_schema().unwrap();
// 2. Route to specialized logic
match query_type {
QueryType::Technical => handle_technical(user_query).await?,
QueryType::Billing => handle_billing(user_query).await?,
QueryType::General => handle_general(user_query).await?,
};
```
### Sequential Chains
Chains execute steps in a predefined order where the output of one request becomes the input for the next.
```rust
// Step 1: Generate summary
let summary = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt(format!("Summarize this article: {}", article))
.build()
.generate_text()
.await?;
// Step 2: Translate the summary
let translation = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt(format!("Translate this to French: {:?}", summary.text()))
.build()
.generate_text()
.await?;
```
### Parallel Processing
Execute independent tasks concurrently using `tokio::try_join!` to reduce latency. This is ideal for patterns like multi-expert reviews, where specialized models audit the same input for different concerns.
```rust
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(JsonSchema, Deserialize, Debug)]
struct ReviewSummary {
vulnerabilities_found: bool,
performance_score: u32,
action_items: Vec,
}
// 1. Run specialized reviews in parallel (Returning Text)
let (security_res, performance_res) = tokio::try_join!(
LanguageModelRequest::builder()
.model(OpenAI::gpt_4o())
.system("You are a security expert.")
.prompt(format!("Review this code: {}", code))
.build()
.generate_text(),
LanguageModelRequest::builder()
.model(OpenAI::gpt_4o())
.system("You are a performance expert.")
.prompt(format!("Review this code: {}", code))
.build()
.generate_text()
)?;
// 2. Aggregate results into a Structured Report
let report = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.system("You are a technical lead summarizing multiple code reviews.")
.prompt(format!(
"Synthesize these reviews into a structured report: \nSecurity: {:?} \nPerformance: {:?}",
security_res.text(), performance_res.text()
))
.schema::()
.build()
.generate_text()
.await?;
let summary: ReviewSummary = report.into_schema().unwrap();
println!("Final Structured Report: {:?}", summary);
```
## Next Steps
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* See how [Capabilities](/docs/concepts/generating-text#capability-system) protect your agent logic.
# Embedding (/docs/concepts/embedding)
The `EmbeddingModelRequest` is used to embed text into vector representations using supported providers.
## Model Providers
Check with the docs for the model provider of your choice to see if it supports embedding. For this example, we'll use OpenAI as our provider and the text-embedding-ada-002 model.
```bash
cargo add aisdk --features openai # anthropic, google or any other provider that supports embedding.
```
At its core is the `embed()` method, which takes a `>` of text and returns a `Vec>` in which each index of the input vector corresponds to the output embeddings.
```rust
let openai = OpenAI::text_embedding_ada_002();
let inputs = vec![
"Hello, world!".to_string(),
"This is a test".to_string(),
"Multiple embeddings".to_string(),
];
let request = EmbeddingModelRequest::builder()
.model(openai)
.input(inputs)
.build();
.embed()
.await
.expect("Embedding request failed");
```
Result will return a `Vec>` with the same length as the input vector. The output structure will be:
```rust
[
[0.0012, 0.0034, 0.0056, 0.078, ...], // Example embedding for "Hello, world!"
[0.01, 0.02, 0.03, 0.04, 0.05, ...], // Example embedding for "This is a test"
[0.06, 0.07, 0.08, 0.09, 0.11, ...], // Example embedding for "Multiple embeddings"
]
```
# Dimensions
The dimensions of the ouput embeddings can be configured with the `.dimensions(u32)` method. The default and the allowed maximum/minimum values depend on the provider so check the provider docs. in an event an unsupported value is used that causes the provider to throw an error, the sdk will propagate the error back to the user.
```rust
let openai = OpenAI::text_embedding_3_small();
let request = EmbeddingModelRequest::builder()
.model(openai)
.input(vec!["Hello, world!".to_string()])
.dimensions(100) // Enforces a dimension of 100
.build();
.embed()
.await
.expect("Embedding request failed");
```
# Generating Text (/docs/concepts/generating-text)
`LanguageModelRequest` is the main AISDK interface for building and executing LLM requests. It gives you a type-safe builder, compile-time capability checks, and one consistent API across providers.
## Quick Start
Pick a provider feature first (OpenAI used here):
```bash
cargo add aisdk --features openai
```
Then build and run a request:
```rust
use aisdk::{core::LanguageModelRequest, providers::OpenAI};
#[tokio::main]
async fn main() -> Result<(), Box> {
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.system("You are a concise assistant.")
.prompt("Explain ownership in Rust in one paragraph.")
.temperature(30)
.build()
.generate_text()
.await?;
println!("{}", response.text());
Ok(())
}
```
## The Capability System
AISDK uses Rust traits to enforce model capabilities at compile time. If a model does not support a feature, the request does not compile.
This applies to:
* Tool calling
* Structured output
* Reasoning features
* Multimodal input/output
```rust
// ✅ WORKS: GPT-5 supports tool calls
let request = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.with_tool(my_tool) // Valid!
.build();
// ❌ FAILS TO COMPILE: Because O1 Mini doesn't support tool calls
let request = LanguageModelRequest::builder()
.model(OpenAI::o1_mini())
.with_tool(my_tool) // ERROR: The trait `ToolCallSupport` is not implemented..
.build();
```
## Type-State Builder Flow
`LanguageModelRequest::builder()` follows a strict build sequence. Each stage only exposes valid methods for that stage.
1. Choose a model: `.model(M)`
2. Optional system instruction: `.system(...)`
3. Choose one input style: `.prompt(...)` or `.messages(...)`
4. Optional options and orchestration features
5. Finalize with `.build()`
### Request Inputs
Use one of these:
* `prompt(impl Into)` for a single user prompt
* `messages(Messages)` for multi-turn history
`prompt(...)` and `messages(...)` are mutually exclusive by design.
```rust
// Single-turn
let request = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt("What is the capital of France?")
.build();
// Multi-turn
let request = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.messages(messages)
.build();
```
### Model Options
Common tuning methods:
* `temperature(u32)`: randomness (0-100)
* `top_p(u32)`: nucleus sampling (0-100)
* `top_k(u32)`: limit token candidates
* `seed(u32)`: deterministic sampling seed
* `max_retries(u32)`: retry count on failures
* `frequency_penalty(f32)`: repetition penalty
* `stop_sequences(Vec)`: early stop tokens
* `reasoning_effort(ReasoningEffort)`: reasoning level (supported models only)
For `u32` percentage-style options, AISDK scales values to each provider's native format.
### Orchestration Features
Use these to move from plain generation to agent workflows:
* `with_tool(Tool)`: register tools (see [Tools](/docs/concepts/tools))
* `schema()`: enforce structured output (see [Structured Output](/docs/concepts/structured-output))
* `on_step_start(...)`, `on_step_finish(...)`, `stop_when(...)`: lifecycle hooks and loop control (see [Agents](/docs/concepts/agents#lifecycle-hooks))
## Execution
Build first, then execute.
### `generate_text()`
Non-streaming execution. Returns when generation is complete.
```rust
let response = request.generate_text().await?;
println!("{}", response.text());
```
### `stream_text()`
Streaming execution. Emits incremental chunks as tokens arrive.
`LanguageModelStreamChunkType` can include:
* `Start`
* `Text(String)`
* `Reasoning(String)`
* `End(AssistantMessage)`
```rust
let response = request.stream_text().await?;
let mut stream = response.stream;
while let Some(chunk) = stream.next().await {
if let LanguageModelStreamChunkType::Text(text) = chunk {
print!("{}", text);
}
}
```
## Response Types Reference
Both `GenerateTextResponse` and `StreamTextResponse` expose helpers for final output and execution metadata.
> \[!NOTE]
> On `StreamTextResponse`, metadata accessors are async and should be called after stream consumption.
| Method | Description |
| :--------------- | :----------------------------------------------------- |
| `text()` | Text from the final assistant message |
| `content()` | Final assistant content (excluding reasoning) |
| `usage()` | Aggregated token usage across all steps |
| `messages()` | Full conversation message history |
| `stop_reason()` | Why generation ended (`Finish`, `Hook`, `Error`, etc.) |
| `steps()` | All recorded steps in chronological order |
| `last_step()` | Most recent step |
| `step(id)` | Step lookup by ID |
| `tool_calls()` | All tool calls issued during execution |
| `tool_results()` | All tool results collected during execution |
### Non-Streaming Example
```rust
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt("What is 2+2?")
.build()
.generate_text()
.await?;
println!("Text: {:?}", response.text());
println!("Usage: {:?}", response.usage());
println!("Stop Reason: {:?}", response.stop_reason());
println!("Final Content: {:?}", response.content());
```
### Streaming Example
```rust
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt("Write a short story.")
.build()
.stream_text()
.await?;
let mut stream = response.stream;
while let Some(chunk) = stream.next().await {
if let LanguageModelStreamChunkType::Text(text) = chunk {
print!("{}", text);
}
}
// Access final metadata after stream consumption
let final_usage = response.usage().await;
let steps = response.steps().await;
let reason = response.stop_reason().await;
```
## Next Steps
* Learn how to create [Custom Tools](/docs/concepts/tools)
* Use [Structured Output](/docs/concepts/structured-output) for reliable typed data
* Build multi-step workflows with [Agents](/docs/concepts/agents)
# Prompts (/docs/concepts/prompts)
//TODO:
# Structured Output (/docs/concepts/structured-output)
Structured Output allows you to force a model to output valid JSON that matches a specific schema. This is essential for building reliable applications where the model's response is consumed directly by application logic.
Structured output is capability-guarded at compile time when you pick models via typed model methods (for example `OpenAI::gpt_5()`). See [Capability Safety](/docs/concepts/generating-text#the-capability-system) in the Generating Text docs.
## Getting Started
AISDK relies on the `serde` and `schemars` crates to convert rust structs into JSON and vice versa. Add them to your Cargo.toml to enable structured output.
```bash
cargo add serde schemars
```
### Defining a Schema
Define your target data structures using simple patterns, such as `#[derive(JsonSchema, Deserialize)]`.:
```rust
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(JsonSchema, Deserialize, Debug)]
struct UserInfo {
name: String,
age: u32,
email: Option,
}
```
## Example: Information Extraction
Here is how to extract structured data from a block of text.
```rust
use aisdk::core::LanguageModelRequest;
use aisdk::providers::OpenAI;
#[tokio::main]
async fn main() -> Result<(), Box> {
let input = "My name is Alice, I am 28 years old and you can reach me at alice@example.com";
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt(format!("Extract information from: {}", input))
.schema::() // Tell the model what structure you expect
.build()
.generate_text()
.await?;
// Deserialize the response into your struct
let user: UserInfo = response.into_schema()?;
println!("Name: {}", user.name);
println!("Age: {}", user.age);
println!("Email: {}", user.email.unwrap_or_default());
Ok(())
}
```
## Advanced Schemas
You can use complex Rust types to define sophisticated schemas.
### Enums for Classification
Enums are perfect for categorizing input into a fixed set of options.
```rust
#[derive(JsonSchema, Deserialize, Debug)]
enum Sentiment {
Positive,
Negative,
Neutral,
}
#[derive(JsonSchema, Deserialize, Debug)]
struct SentimentAnalysis {
sentiment: Sentiment,
confidence: f32, // 0.0 to 1.0
}
```
### Nested Objects and Lists
You can nest structs and use `Vec` to represent complex heirarchies.
```rust
#[derive(JsonSchema, Deserialize, Debug)]
struct Recipe {
name: String,
ingredients: Vec,
prep_time_minutes: u32,
}
#[derive(JsonSchema, Deserialize, Debug)]
struct Ingredient {
item: String,
amount: String,
}
```
***
## Next Steps
* Explore creating [Custom Tools](/docs/concepts/tools).
* Learn how [Agents](/docs/concepts/agents) use Structured Output for routing.
* See the full [Language Model Request](/docs/concepts/generating-text) documentation.
# Tools (/docs/concepts/tools)
While large language models (LLMs) have incredible generation capabilities,
they struggle with discrete tasks (e.g. mathematics) and interacting with the outside world (e.g. getting the weather).
A 'Tool' is a general term for a function or logic that can be executed by an AI model. They can be user defined or pre-defined by the provider. Tools are provided to the AI model's context as per the developer's needs.The AI model can then use the provided tools to perform specific queries to aid in text generation or actions to be taken externally.
Tool usage is capability-guarded at compile time when you pick models via typed model methods (for example `OpenAI::gpt_5()`). See [Capability Safety](/docs/concepts/generating-text#the-capability-system) in the Generating Text docs.
## Defining Tools with `#[tool]`
The recommended way to define tools is using the `#[tool]` macro. This attribute transforms a standard Rust function into a `Tool` object that the model can understand.
```rust
use aisdk::core::Tool;
use aisdk::macros::tool;
#[tool]
/// Get the current weather in a specific location
pub fn get_weather(location: String) -> Tool {
// In a real app, this would call a weather API
let weather = format!("The weather in {} is 75°F and sunny.", location);
Ok(weather)
}
```
### Function-to-Tool Extraction
AISDK automatically extracts metadata from your function:
* **Name**: Unique, descriptive name of the tool. Her it is automatically inferred as `get_weather` from the function name.
* **Description**: Briefly describes the tool's purpose and usage. Rust-style docs with examples can be used for few-shot prompting.
* **Arguments**: Function parameters are automatically converted into a JSON Schema using `schemars`.
* **Body**: The tool’s logic executed when called by the AI. Must return `Tool` or `Result`. Errors can be returned as `Err(String)` to help the AI understand failures.
### Registering Tools
To make a tool available to a model, pass it to the `.with_tool()` method in the [`LanguageModelRequest`](/docs/concepts/generating-text) builder.
> When using the `#[tool]` macro, the macro wraps your logic in a function that returns a `Tool`. You must **call** the function (e.g., `get_weather()`) when passing it to the builder.
This appends the tool to the list of tools that the AI model will use.
```rust
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_5())
.prompt("What's the weather in Tokyo?")
.with_tool(get_weather()) // Register the tool
.build()
.generate_text()
.await?;
```
### `tool` Macro Customization
You can override the default inferred name and description using macro attributes.
```rust
#[tool(name = "check-weather", desc = "Retrieves weather data for a city")]
fn get_weather(location: String) -> Tool {
Ok(format!("Sunny in {}", location))
}
```
## Manual Tool Definition (Advanced)
You can define your own tools in aisdk by instantiating the `Tool` and related structs and passing
it to one of the AI model text generation builders.
### Defining the Tool
````rust
use super::{Tool, ToolExecute};
use serde_json::Value;
// define tool function body, should return Result
#[allow(unused_variables)]
let func = ToolExecute::new(Box::new(|inp: Value| {
// Ai SDK will pass in a json object with the following structure
// ```json
// {
// "location": "New York"
// }
// ```
let location = inp.get("location").unwrap();
Ok(format!("Cloudy"))
}));
// define tool input structure
#[derive(schemars::JsonSchema, Debug)]
#[allow(dead_code)]
struct ToolInput {
location: String,
}
// change tool arguments to json schema
// Which will be similar to the following
// ```json
// "properties": {
// "location": {
// "type": "string"
// }
// }
let schema = schemars::schema_for!(ToolInput);
// bring it all together
let get_weather_tool = Tool::builder()
.name("get-weather")
.description("Get the weather information given a location")
.input_schema(schema.clone())
.execute(func)
.build()
.unwrap();
````
### Registering Manually-Defined Tools
To register manually-defined tools with the AI model, you need to add them to [`LanguageModelRequest`](/docs/concepts/generating-text) builder using the `with_tool` method.
This appends the tool to the list of tools that the AI model will use.
```rust
// call the model with `Tool` struct
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_tool) // you don't need to call it if using structs.
.build()
.generate_text()
.await;
```
## Next Steps
* Use tools in a loop with [Agents](/docs/concepts/agents).
* Learn how to extract [Structured Output](/docs/concepts/structured-output).
* Explore the full [Language Model Request](/docs/concepts/generating-text) API.
# Axum (/docs/integrations/axum)
The Axum integration provides seamless support for building AI-powered web applications with `aisdk` and Axum web framework. It handles server-sent events (SSE) streaming, enabling real-time delivery of AI-generated content to frontend clients.
## Installation
Add the `axum` feature to enable Axum-specific integrations:
```bash
cargo add aisdk --features axum
```
Additional dependencies for the Axum web server:
```bash
cargo add axum tower-http --features tower-http/cors
```
## Vercel AI SDK UI
AISDK.rs Axum integration includes built-in support for [Vercel's AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview). The integration automatically converts [`StreamTextResponse`](/docs/ai-sdk-ui/overview) to Axum SSE responses in Vercel-compatible format, allowing you to use frontend hooks like `useChat` and `useCompletion` with minimal setup.
### How It Works
1. **Request**: Frontend sends `VercelUIRequest` using Vercel's AI SDK UI hooks such as `useChat` via SSE
2. **Processing**: AISDK.rs processes the request with [`LanguageModelRequest`](/docs/concepts/generating-text) Streaming API
3. **Conversion**: Response is automatically converted to Vercel UI stream chunks
4. **Response**: Axum streams the chunks back to the frontend
### Quick Example
```rust
use aisdk::{
core::LanguageModelRequest,
integrations::{
axum::AxumSseResponse,
vercel_aisdk_ui::VercelUIRequest,
},
providers::OpenAI,
};
// Example handler function
async fn chat_handler(
axum::Json(request): axum::Json,
) -> AxumSseResponse {
// Convert the Message sent by the frontend to AISDK.rs Messages
let messages = request.into();
// Generate streaming response
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_4o())
.messages(messages)
.build()
.stream_text()
.await
.unwrap();
// Convert to Axum SSE response (Vercel UI compatible)
response.into()
}
#[tokio::main]
async fn main() {
let app = axum::Router::new()
.route("/api/chat", axum::routing::post(chat_handler))
.layer(tower_http::cors::CorsLayer::permissive());
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
println!("Listening on http://{}", addr);
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
}
```
> **Note**: `AxumSseResponse` is a type alias for `axum::response::Sse>>`. You can replace `AxumSseResponse` with the full type definition if you prefer.
### Frontend Example (React)
This example uses React, but you can use any Vercel AI SDK UI supported frontend framework such as React, Vue.js, Svelte, Angular, or SolidJS. See the [complete list of supported frameworks](https://ai-sdk.dev/docs/ai-sdk-ui/overview#ui-framework-support).
```tsx
'use client';
import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport } from 'ai';
import { useState } from 'react';
export default function Page() {
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({
api: 'http://localhost:8080/api/chat',
}),
});
const [input, setInput] = useState('');
return (
<>
{messages.map(message => (
))}
>
);
}
```
### Builder Configuration
For more control over streaming behavior, use the builder API to configure which chunk types to send:
```rust
use aisdk::core::LanguageModelRequest;
use aisdk::integrations::vercel_aisdk_ui::VercelUIRequest;
use aisdk::integrations::axum::AxumSseResponse;
use aisdk::providers::OpenAI;
async fn chat_handler(
Json(request): Json,
) -> AxumSseResponse {
let messages = request.into();
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_4o())
.messages(messages)
.build()
.stream_text()
.await?;
// Configure stream with builder
response
.to_axum_vercel_ui_stream()
.send_reasoning() // Enable reasoning chunks
.send_start() // Include start signals
.send_finish() // Include finish signals
.build()
}
```
#### Builder Options
| Method | Description |
| ----------------------- | ---------------------------------------- |
| `send_reasoning()` | Include reasoning chunks in the stream |
| `send_start()` | Send start signal chunks |
| `send_finish()` | Send finish signal chunks |
| `with_id_generator(fn)` | Set custom message ID generator function |
| `build()` | Build the final `AxumSseResponse` |
## Next Steps
* Read the [Vercel AI SDK UI docs](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for frontend details
* Take a deeper look at [`LanguageModelRequest`](/docs/concepts/generating-text)
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Vercel AI-SDK UI (/docs/integrations)
The Vercel AI SDK UI integration allows you to build **Rust backends** that work seamlessly with [Vercel's AI SDK UI frontend hooks](https://ai-sdk.dev/docs/ai-sdk-ui/overview). It converts AISDK.rs streams into the Vercel-compatible SSE format, enabling you to use `useChat`, `useCompletion`, and other frontend hooks with a Rust backend.
## How It Works
```
Frontend (useChat) → SSE → Rust Backend (AISDK.rs)
↓
VercelUIStream chunks
```
## Quick Start
AISDK.rs provides framework support for Rust backends with seamless integration. In this example, we'll use **Axum** for the Rust backend and **React** for the frontend. However, you can use [other supported Rust backends](#backend-framework-supports) with AISDK.rs. Similarly, Vercel's AI SDK UI supports many frontend frameworks, so you can choose the one that works best for your project. See the [list of supported frontend frameworks](https://ai-sdk.dev/docs/ai-sdk-ui/overview#ui-framework-support).
### Install Dependencies
Since we're using Axum, you need to enable the `axum` feature in AISDK. For the AI provider, we're using OpenAI, but you can use [any available provider](/docs#model-providers).
```bash
cargo add aisdk --features openai axum
```
### Backend Example (Axum)
```rust
use aisdk::{
core::LanguageModelRequest,
integrations::{
axum::AxumSseResponse,
vercel_aisdk_ui::VercelUIRequest,
},
providers::OpenAI,
};
// Example Axum handler function
async fn chat_handler(
axum::Json(request): axum::Json,
) -> AxumSseResponse {
// Convert the Message sent by the frontend to AISDK.rs Messages
let messages = request.into();
// Generate streaming response
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_4o())
.messages(messages)
.build()
.stream_text()
.await?;
// Convert to Axum SSE response (Vercel UI compatible)
response.into()
}
```
For more information, see the [Axum integration docs](/docs/integrations/axum#vercel-ai-sdk-ui).
### Frontend Example (React)
This example uses React, but you can use any Vercel AI SDK UI supported frontend framework such as React, Vue.js, Svelte, Angular, or SolidJS. See the [complete list of supported frameworks](https://ai-sdk.dev/docs/ai-sdk-ui/overview#ui-framework-support).
```tsx
'use client';
import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport } from 'ai';
import { useState } from 'react';
export default function Page() {
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({
api: 'http://localhost:8080/api/chat',
}),
});
const [input, setInput] = useState('');
return (
<>
{messages.map(message => (
))}
>
);
}
```
## Backend Framework Supports
AISDK.rs provides seamless integration for receiving requests from Vercel's AI SDK UI frontend hooks, processing them with the [`LanguageModelRequest`](/docs/concepts/generating-text) API, and streaming responses back in the Vercel-compatible format. This integration handles all of the low-level details of SSE streaming and message format conversion.
Currently supported frameworks:
* [Axum](/docs/integrations/axum#vercel-ai-sdk-ui)
More frameworks will be added in the future.
### Manual Conversion
If you need full control over the request handling and streaming process, or if your framework isn't yet supported by AISDK.rs, you can use the manual conversion approach. This gives you complete flexibility to integrate with any web framework.
Use the `into_vercel_ui_stream()` method to convert a `StreamTextResponse` into Vercel UI stream chunk types. You can configure which chunk types to send (reasoning, start, finish) using `VercelUIStreamOptions`.
```rust
use aisdk::core::{LanguageModelRequest, Messages};
use aisdk::integrations::vercel_aisdk_ui::{VercelUIRequest, VercelUIStreamOptions};
use aisdk::providers::OpenAI;
use futures::Stream;
// Handler function signature varies by your framework
async fn chat_handler(request: impl Into) -> impl Stream> {
// Extract VercelUIRequest from the framework-specific request
let ui_message: VercelUIRequest = request.into();
// Convert VercelUIRequest to AISDK Messages
let messages: Messages = ui_message.into();
// Generate streaming response
let response = LanguageModelRequest::builder()
.model(OpenAI::gpt_3_5_turbo())
.messages(messages)
.build()
.stream_text()
.await?;
// Configure which chunk types to send
let options = VercelUIStreamOptions {
send_reasoning: true,
send_start: true,
send_finish: true,
generate_message_id: None,
};
// Convert LanguageModelStream to VercelUIStream
let vercel_stream = response.into_vercel_ui_stream(options);
// Return the stream using your framework's specific response type
// This is framework-specific - see Axum integration for a complete example
vercel_stream
}
```
## Next Steps
* Read the [Vercel AI SDK UI docs](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for frontend details
* Take a deeper look at [`LanguageModelRequest`](/docs/concepts/generating-text)
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Ai302 (/docs/providers/302ai)
AISDK provides first-class support for Ai302 with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Ai302 provider feature:
```bash
cargo add aisdk --features 302ai
```
This installs AISDK with the Ai302 provider enabled. Once you have enabled the Ai302 provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Ai302::model_name()`, where **model\_name** is the Ai302 model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Ai302;
let 302ai = Ai302::minimax_m1();
```
This initializes the provider with:
* Model: `"MiniMax-M1"`
* API key from environment (if set with `302AI_API_KEY`)
* Ai302's default base URL ([https://api.302.ai/v1](https://api.302.ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Ai302,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let 302ai = Ai302::minimax_m1();
let response = LanguageModelRequest::builder()
.model(302ai)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Ai302::builder()`
### API Key
```rust
let 302ai = Ai302::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `302AI_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let 302ai = Ai302::::builder()
.base_url("https://api.302.ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let 302ai = Ai302::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let 302ai = Ai302::::builder()
.provider_name("Ai302")
.build()?;
```
### Full Custom Configuration Example
```rust
let 302ai = Ai302::::builder()
.api_key("your-api-key")
.base_url("https://api.302.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Ai302")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Ai302;
// Specify model as a string at runtime
let 302ai = Ai302::model_name("MiniMax-M1");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Ai302,
};
let 302ai = Ai302::::builder()
.model_name("MiniMax-M1")
.api_key("your-api-key")
.base_url("https://api.302.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Ai302")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Ai302::minimax_m1()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Abacus (/docs/providers/abacus)
AISDK provides first-class support for Abacus with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Abacus provider feature:
```bash
cargo add aisdk --features abacus
```
This installs AISDK with the Abacus provider enabled. Once you have enabled the Abacus provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Abacus::model_name()`, where **model\_name** is the Abacus model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Abacus;
let abacus = Abacus::qwen_qwq_32b();
```
This initializes the provider with:
* Model: `"Qwen/QwQ-32B"`
* API key from environment (if set with `ABACUS_API_KEY`)
* Abacus's default base URL ([https://routellm.abacus.ai/v1](https://routellm.abacus.ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Abacus,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let abacus = Abacus::qwen_qwq_32b();
let response = LanguageModelRequest::builder()
.model(abacus)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Abacus::builder()`
### API Key
```rust
let abacus = Abacus::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `ABACUS_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let abacus = Abacus::::builder()
.base_url("https://routellm.abacus.ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let abacus = Abacus::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let abacus = Abacus::::builder()
.provider_name("Abacus")
.build()?;
```
### Full Custom Configuration Example
```rust
let abacus = Abacus::::builder()
.api_key("your-api-key")
.base_url("https://routellm.abacus.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Abacus")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Abacus;
// Specify model as a string at runtime
let abacus = Abacus::model_name("Qwen/QwQ-32B");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Abacus,
};
let abacus = Abacus::::builder()
.model_name("Qwen/QwQ-32B")
.api_key("your-api-key")
.base_url("https://routellm.abacus.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Abacus")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Abacus::qwen_qwq_32b()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Aihubmix (/docs/providers/aihubmix)
AISDK provides first-class support for Aihubmix with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Aihubmix provider feature:
```bash
cargo add aisdk --features aihubmix
```
This installs AISDK with the Aihubmix provider enabled. Once you have enabled the Aihubmix provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Aihubmix::model_name()`, where **model\_name** is the Aihubmix model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Aihubmix;
let aihubmix = Aihubmix::kimi_k2_0905();
```
This initializes the provider with:
* Model: `"Kimi-K2-0905"`
* API key from environment (if set with `AIHUBMIX_API_KEY`)
* Aihubmix's default base URL ([https://aihubmix.com/v1](https://aihubmix.com/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Aihubmix,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let aihubmix = Aihubmix::kimi_k2_0905();
let response = LanguageModelRequest::builder()
.model(aihubmix)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Aihubmix::builder()`
### API Key
```rust
let aihubmix = Aihubmix::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `AIHUBMIX_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let aihubmix = Aihubmix::::builder()
.base_url("https://aihubmix.com/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let aihubmix = Aihubmix::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let aihubmix = Aihubmix::::builder()
.provider_name("Aihubmix")
.build()?;
```
### Full Custom Configuration Example
```rust
let aihubmix = Aihubmix::::builder()
.api_key("your-api-key")
.base_url("https://aihubmix.com/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Aihubmix")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Aihubmix;
// Specify model as a string at runtime
let aihubmix = Aihubmix::model_name("Kimi-K2-0905");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Aihubmix,
};
let aihubmix = Aihubmix::::builder()
.model_name("Kimi-K2-0905")
.api_key("your-api-key")
.base_url("https://aihubmix.com/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Aihubmix")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Aihubmix::kimi_k2_0905()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# AlibabaCn (/docs/providers/alibaba-cn)
AISDK provides first-class support for AlibabaCn with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the AlibabaCn provider feature:
```bash
cargo add aisdk --features alibaba-cn
```
This installs AISDK with the AlibabaCn provider enabled. Once you have enabled the AlibabaCn provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `AlibabaCn::model_name()`, where **model\_name** is the AlibabaCn model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::AlibabaCn;
let alibaba-cn = AlibabaCn::deepseek_r1();
```
This initializes the provider with:
* Model: `"deepseek-r1"`
* API key from environment (if set with `DASHSCOPE_API_KEY`)
* AlibabaCn's default base URL ([https://dashscope.aliyuncs.com/compatible-mode/v1](https://dashscope.aliyuncs.com/compatible-mode/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::AlibabaCn,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let alibaba-cn = AlibabaCn::deepseek_r1();
let response = LanguageModelRequest::builder()
.model(alibaba-cn)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `AlibabaCn::builder()`
### API Key
```rust
let alibaba-cn = AlibabaCn::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `DASHSCOPE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let alibaba-cn = AlibabaCn::::builder()
.base_url("https://dashscope.aliyuncs.com/compatible-mode/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let alibaba-cn = AlibabaCn::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let alibaba-cn = AlibabaCn::::builder()
.provider_name("AlibabaCn")
.build()?;
```
### Full Custom Configuration Example
```rust
let alibaba-cn = AlibabaCn::::builder()
.api_key("your-api-key")
.base_url("https://dashscope.aliyuncs.com/compatible-mode/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("AlibabaCn")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::AlibabaCn;
// Specify model as a string at runtime
let alibaba-cn = AlibabaCn::model_name("deepseek-r1");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::AlibabaCn,
};
let alibaba-cn = AlibabaCn::::builder()
.model_name("deepseek-r1")
.api_key("your-api-key")
.base_url("https://dashscope.aliyuncs.com/compatible-mode/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("AlibabaCn")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `AlibabaCn::deepseek_r1()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Alibaba (/docs/providers/alibaba)
AISDK provides first-class support for Alibaba with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Alibaba provider feature:
```bash
cargo add aisdk --features alibaba
```
This installs AISDK with the Alibaba provider enabled. Once you have enabled the Alibaba provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Alibaba::model_name()`, where **model\_name** is the Alibaba model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Alibaba;
let alibaba = Alibaba::qvq_max();
```
This initializes the provider with:
* Model: `"qvq-max"`
* API key from environment (if set with `DASHSCOPE_API_KEY`)
* Alibaba's default base URL ([https://dashscope-intl.aliyuncs.com/compatible-mode/v1](https://dashscope-intl.aliyuncs.com/compatible-mode/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Alibaba,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let alibaba = Alibaba::qvq_max();
let response = LanguageModelRequest::builder()
.model(alibaba)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Alibaba::builder()`
### API Key
```rust
let alibaba = Alibaba::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `DASHSCOPE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let alibaba = Alibaba::::builder()
.base_url("https://dashscope-intl.aliyuncs.com/compatible-mode/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let alibaba = Alibaba::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let alibaba = Alibaba::::builder()
.provider_name("Alibaba")
.build()?;
```
### Full Custom Configuration Example
```rust
let alibaba = Alibaba::::builder()
.api_key("your-api-key")
.base_url("https://dashscope-intl.aliyuncs.com/compatible-mode/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Alibaba")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Alibaba;
// Specify model as a string at runtime
let alibaba = Alibaba::model_name("qvq-max");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Alibaba,
};
let alibaba = Alibaba::::builder()
.model_name("qvq-max")
.api_key("your-api-key")
.base_url("https://dashscope-intl.aliyuncs.com/compatible-mode/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Alibaba")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Alibaba::qvq_max()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# AmazonBedrock (/docs/providers/amazon-bedrock)
AISDK provides first-class support for AmazonBedrock with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the AmazonBedrock provider feature:
```bash
cargo add aisdk --features amazon-bedrock
```
This installs AISDK with the AmazonBedrock provider enabled. Once you have enabled the AmazonBedrock provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `AmazonBedrock::model_name()`, where **model\_name** is the AmazonBedrock model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::AmazonBedrock;
let amazon-bedrock = AmazonBedrock::ai21_jamba_1_5_large_v1_0();
```
This initializes the provider with:
* Model: `"ai21.jamba-1-5-large-v1:0"`
* API key from environment (if set with `BEDROCK_API_KEY`)
* AmazonBedrock's default base URL ([https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1/](https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::AmazonBedrock,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let amazon-bedrock = AmazonBedrock::ai21_jamba_1_5_large_v1_0();
let response = LanguageModelRequest::builder()
.model(amazon-bedrock)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `AmazonBedrock::builder()`
### API Key
```rust
let amazon-bedrock = AmazonBedrock::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `BEDROCK_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let amazon-bedrock = AmazonBedrock::::builder()
.base_url("https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let amazon-bedrock = AmazonBedrock::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let amazon-bedrock = AmazonBedrock::::builder()
.provider_name("AmazonBedrock")
.build()?;
```
### Full Custom Configuration Example
```rust
let amazon-bedrock = AmazonBedrock::::builder()
.api_key("your-api-key")
.base_url("https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("AmazonBedrock")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::AmazonBedrock;
// Specify model as a string at runtime
let amazon-bedrock = AmazonBedrock::model_name("ai21.jamba-1-5-large-v1:0");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::AmazonBedrock,
};
let amazon-bedrock = AmazonBedrock::::builder()
.model_name("ai21.jamba-1-5-large-v1:0")
.api_key("your-api-key")
.base_url("https://bedrock-runtime.us-east-1.amazonaws.com/openai/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("AmazonBedrock")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `AmazonBedrock::ai21_jamba_1_5_large_v1_0()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Anthropic (/docs/providers/anthropic)
AISDK provides first-class support for Anthropic with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Anthropic provider feature:
```bash
cargo add aisdk --features anthropic
```
This installs AISDK with the Anthropic provider enabled. Once you have enabled the Anthropic provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Anthropic::model_name()`, where **model\_name** is the Anthropic model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Anthropic;
let anthropic = Anthropic::claude_3_5_haiku_20241022();
```
This initializes the provider with:
* Model: `"claude-3-5-haiku-20241022"`
* API key from environment (if set with `ANTHROPIC_API_KEY`)
* Anthropic's default base URL ([https://api.anthropic.com/v1/](https://api.anthropic.com/v1/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Anthropic,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let anthropic = Anthropic::claude_3_5_haiku_20241022();
let response = LanguageModelRequest::builder()
.model(anthropic)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Anthropic::builder()`
### API Key
```rust
let anthropic = Anthropic::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `ANTHROPIC_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let anthropic = Anthropic::::builder()
.base_url("https://api.anthropic.com/v1/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let anthropic = Anthropic::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let anthropic = Anthropic::::builder()
.provider_name("Anthropic")
.build()?;
```
### Full Custom Configuration Example
```rust
let anthropic = Anthropic::::builder()
.api_key("your-api-key")
.base_url("https://api.anthropic.com/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Anthropic")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Anthropic;
// Specify model as a string at runtime
let anthropic = Anthropic::model_name("claude-3-5-haiku-20241022");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Anthropic,
};
let anthropic = Anthropic::::builder()
.model_name("claude-3-5-haiku-20241022")
.api_key("your-api-key")
.base_url("https://api.anthropic.com/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Anthropic")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Anthropic::claude_3_5_haiku_20241022()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Bailing (/docs/providers/bailing)
AISDK provides first-class support for Bailing with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Bailing provider feature:
```bash
cargo add aisdk --features bailing
```
This installs AISDK with the Bailing provider enabled. Once you have enabled the Bailing provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Bailing::model_name()`, where **model\_name** is the Bailing model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Bailing;
let bailing = Bailing::ling_1t();
```
This initializes the provider with:
* Model: `"Ling-1T"`
* API key from environment (if set with `BAILING_API_TOKEN`)
* Bailing's default base URL ([https://api.tbox.cn/api/llm/v1/chat/completions](https://api.tbox.cn/api/llm/v1/chat/completions))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Bailing,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let bailing = Bailing::ling_1t();
let response = LanguageModelRequest::builder()
.model(bailing)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Bailing::builder()`
### API Key
```rust
let bailing = Bailing::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `BAILING_API_TOKEN` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let bailing = Bailing::::builder()
.base_url("https://api.tbox.cn/api/llm/v1/chat/completions")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let bailing = Bailing::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let bailing = Bailing::::builder()
.provider_name("Bailing")
.build()?;
```
### Full Custom Configuration Example
```rust
let bailing = Bailing::::builder()
.api_key("your-api-key")
.base_url("https://api.tbox.cn/api/llm/v1/chat/completions")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Bailing")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Bailing;
// Specify model as a string at runtime
let bailing = Bailing::model_name("Ling-1T");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Bailing,
};
let bailing = Bailing::::builder()
.model_name("Ling-1T")
.api_key("your-api-key")
.base_url("https://api.tbox.cn/api/llm/v1/chat/completions")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Bailing")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Bailing::ling_1t()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Baseten (/docs/providers/baseten)
AISDK provides first-class support for Baseten with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Baseten provider feature:
```bash
cargo add aisdk --features baseten
```
This installs AISDK with the Baseten provider enabled. Once you have enabled the Baseten provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Baseten::model_name()`, where **model\_name** is the Baseten model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Baseten;
let baseten = Baseten::qwen_qwen3_coder_480b_a35b_instruct();
```
This initializes the provider with:
* Model: `"Qwen/Qwen3-Coder-480B-A35B-Instruct"`
* API key from environment (if set with `BASETEN_API_KEY`)
* Baseten's default base URL ([https://inference.baseten.co/v1](https://inference.baseten.co/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Baseten,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let baseten = Baseten::qwen_qwen3_coder_480b_a35b_instruct();
let response = LanguageModelRequest::builder()
.model(baseten)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Baseten::builder()`
### API Key
```rust
let baseten = Baseten::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `BASETEN_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let baseten = Baseten::::builder()
.base_url("https://inference.baseten.co/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let baseten = Baseten::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let baseten = Baseten::::builder()
.provider_name("Baseten")
.build()?;
```
### Full Custom Configuration Example
```rust
let baseten = Baseten::::builder()
.api_key("your-api-key")
.base_url("https://inference.baseten.co/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Baseten")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Baseten;
// Specify model as a string at runtime
let baseten = Baseten::model_name("Qwen/Qwen3-Coder-480B-A35B-Instruct");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Baseten,
};
let baseten = Baseten::::builder()
.model_name("Qwen/Qwen3-Coder-480B-A35B-Instruct")
.api_key("your-api-key")
.base_url("https://inference.baseten.co/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Baseten")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Baseten::qwen_qwen3_coder_480b_a35b_instruct()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Berget (/docs/providers/berget)
AISDK provides first-class support for Berget with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Berget provider feature:
```bash
cargo add aisdk --features berget
```
This installs AISDK with the Berget provider enabled. Once you have enabled the Berget provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Berget::model_name()`, where **model\_name** is the Berget model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Berget;
let berget = Berget::baai_bge_reranker_v2_m3();
```
This initializes the provider with:
* Model: `"BAAI/bge-reranker-v2-m3"`
* API key from environment (if set with `BERGET_API_KEY`)
* Berget's default base URL ([https://api.berget.ai/v1](https://api.berget.ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Berget,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let berget = Berget::baai_bge_reranker_v2_m3();
let response = LanguageModelRequest::builder()
.model(berget)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Berget::builder()`
### API Key
```rust
let berget = Berget::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `BERGET_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let berget = Berget::::builder()
.base_url("https://api.berget.ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let berget = Berget::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let berget = Berget::::builder()
.provider_name("Berget")
.build()?;
```
### Full Custom Configuration Example
```rust
let berget = Berget::::builder()
.api_key("your-api-key")
.base_url("https://api.berget.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Berget")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Berget;
// Specify model as a string at runtime
let berget = Berget::model_name("BAAI/bge-reranker-v2-m3");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Berget,
};
let berget = Berget::::builder()
.model_name("BAAI/bge-reranker-v2-m3")
.api_key("your-api-key")
.base_url("https://api.berget.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Berget")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Berget::baai_bge_reranker_v2_m3()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Chutes (/docs/providers/chutes)
AISDK provides first-class support for Chutes with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Chutes provider feature:
```bash
cargo add aisdk --features chutes
```
This installs AISDK with the Chutes provider enabled. Once you have enabled the Chutes provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Chutes::model_name()`, where **model\_name** is the Chutes model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Chutes;
let chutes = Chutes::minimaxai_minimax_m2_1_tee();
```
This initializes the provider with:
* Model: `"MiniMaxAI/MiniMax-M2.1-TEE"`
* API key from environment (if set with `CHUTES_API_KEY`)
* Chutes's default base URL ([https://llm.chutes.ai/v1](https://llm.chutes.ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Chutes,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let chutes = Chutes::minimaxai_minimax_m2_1_tee();
let response = LanguageModelRequest::builder()
.model(chutes)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Chutes::builder()`
### API Key
```rust
let chutes = Chutes::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `CHUTES_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let chutes = Chutes::::builder()
.base_url("https://llm.chutes.ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let chutes = Chutes::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let chutes = Chutes::::builder()
.provider_name("Chutes")
.build()?;
```
### Full Custom Configuration Example
```rust
let chutes = Chutes::::builder()
.api_key("your-api-key")
.base_url("https://llm.chutes.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Chutes")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Chutes;
// Specify model as a string at runtime
let chutes = Chutes::model_name("MiniMaxAI/MiniMax-M2.1-TEE");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Chutes,
};
let chutes = Chutes::::builder()
.model_name("MiniMaxAI/MiniMax-M2.1-TEE")
.api_key("your-api-key")
.base_url("https://llm.chutes.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Chutes")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Chutes::minimaxai_minimax_m2_1_tee()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# CloudflareAiGateway (/docs/providers/cloudflare-ai-gateway)
AISDK provides first-class support for CloudflareAiGateway with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the CloudflareAiGateway provider feature:
```bash
cargo add aisdk --features cloudflare-ai-gateway
```
This installs AISDK with the CloudflareAiGateway provider enabled. Once you have enabled the CloudflareAiGateway provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `CloudflareAiGateway::model_name()`, where **model\_name** is the CloudflareAiGateway model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::CloudflareAiGateway;
let cloudflare-ai-gateway = CloudflareAiGateway::anthropic_claude_3_5_haiku();
```
This initializes the provider with:
* Model: `"anthropic/claude-3-5-haiku"`
* API key from environment (if set with `CLOUDFLARE_API_TOKEN`)
* CloudflareAiGateway's default base URL ([https://gateway.ai.cloudflare.com/v1/$\{CLOUDFLARE\_ACCOUNT\_ID}/$\{CLOUDFLARE\_GATEWAY\_ID}/compat/](https://gateway.ai.cloudflare.com/v1/$\{CLOUDFLARE_ACCOUNT_ID}/$\{CLOUDFLARE_GATEWAY_ID}/compat/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::CloudflareAiGateway,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let cloudflare-ai-gateway = CloudflareAiGateway::anthropic_claude_3_5_haiku();
let response = LanguageModelRequest::builder()
.model(cloudflare-ai-gateway)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `CloudflareAiGateway::builder()`
### API Key
```rust
let cloudflare-ai-gateway = CloudflareAiGateway::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `CLOUDFLARE_API_TOKEN` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let cloudflare-ai-gateway = CloudflareAiGateway::::builder()
.base_url("https://gateway.ai.cloudflare.com/v1/${CLOUDFLARE_ACCOUNT_ID}/${CLOUDFLARE_GATEWAY_ID}/compat/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let cloudflare-ai-gateway = CloudflareAiGateway::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let cloudflare-ai-gateway = CloudflareAiGateway::::builder()
.provider_name("CloudflareAiGateway")
.build()?;
```
### Full Custom Configuration Example
```rust
let cloudflare-ai-gateway = CloudflareAiGateway::::builder()
.api_key("your-api-key")
.base_url("https://gateway.ai.cloudflare.com/v1/${CLOUDFLARE_ACCOUNT_ID}/${CLOUDFLARE_GATEWAY_ID}/compat/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("CloudflareAiGateway")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::CloudflareAiGateway;
// Specify model as a string at runtime
let cloudflare-ai-gateway = CloudflareAiGateway::model_name("anthropic/claude-3-5-haiku");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::CloudflareAiGateway,
};
let cloudflare-ai-gateway = CloudflareAiGateway::::builder()
.model_name("anthropic/claude-3-5-haiku")
.api_key("your-api-key")
.base_url("https://gateway.ai.cloudflare.com/v1/${CLOUDFLARE_ACCOUNT_ID}/${CLOUDFLARE_GATEWAY_ID}/compat/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("CloudflareAiGateway")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `CloudflareAiGateway::anthropic_claude_3_5_haiku()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# CloudflareWorkersAi (/docs/providers/cloudflare-workers-ai)
AISDK provides first-class support for CloudflareWorkersAi with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the CloudflareWorkersAi provider feature:
```bash
cargo add aisdk --features cloudflare-workers-ai
```
This installs AISDK with the CloudflareWorkersAi provider enabled. Once you have enabled the CloudflareWorkersAi provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `CloudflareWorkersAi::model_name()`, where **model\_name** is the CloudflareWorkersAi model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::CloudflareWorkersAi;
let cloudflare-workers-ai = CloudflareWorkersAi::ai4bharat_indictrans2_en_indic_1b();
```
This initializes the provider with:
* Model: `"@cf/ai4bharat/indictrans2-en-indic-1B"`
* API key from environment (if set with `CLOUDFLARE_ACCOUNT_ID`)
* CloudflareWorkersAi's default base URL ([https://api.cloudflare.com/client/v4/accounts/$\{CLOUDFLARE\_ACCOUNT\_ID}/ai/v1](https://api.cloudflare.com/client/v4/accounts/$\{CLOUDFLARE_ACCOUNT_ID}/ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::CloudflareWorkersAi,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let cloudflare-workers-ai = CloudflareWorkersAi::ai4bharat_indictrans2_en_indic_1b();
let response = LanguageModelRequest::builder()
.model(cloudflare-workers-ai)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `CloudflareWorkersAi::builder()`
### API Key
```rust
let cloudflare-workers-ai = CloudflareWorkersAi::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `CLOUDFLARE_ACCOUNT_ID` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let cloudflare-workers-ai = CloudflareWorkersAi::::builder()
.base_url("https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let cloudflare-workers-ai = CloudflareWorkersAi::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let cloudflare-workers-ai = CloudflareWorkersAi::::builder()
.provider_name("CloudflareWorkersAi")
.build()?;
```
### Full Custom Configuration Example
```rust
let cloudflare-workers-ai = CloudflareWorkersAi::::builder()
.api_key("your-api-key")
.base_url("https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("CloudflareWorkersAi")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::CloudflareWorkersAi;
// Specify model as a string at runtime
let cloudflare-workers-ai = CloudflareWorkersAi::model_name("@cf/ai4bharat/indictrans2-en-indic-1B");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::CloudflareWorkersAi,
};
let cloudflare-workers-ai = CloudflareWorkersAi::::builder()
.model_name("@cf/ai4bharat/indictrans2-en-indic-1B")
.api_key("your-api-key")
.base_url("https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("CloudflareWorkersAi")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `CloudflareWorkersAi::ai4bharat_indictrans2_en_indic_1b()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Cortecs (/docs/providers/cortecs)
AISDK provides first-class support for Cortecs with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Cortecs provider feature:
```bash
cargo add aisdk --features cortecs
```
This installs AISDK with the Cortecs provider enabled. Once you have enabled the Cortecs provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Cortecs::model_name()`, where **model\_name** is the Cortecs model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Cortecs;
let cortecs = Cortecs::claude_4_5_sonnet();
```
This initializes the provider with:
* Model: `"claude-4-5-sonnet"`
* API key from environment (if set with `CORTECS_API_KEY`)
* Cortecs's default base URL ([https://api.cortecs.ai/v1](https://api.cortecs.ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Cortecs,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let cortecs = Cortecs::claude_4_5_sonnet();
let response = LanguageModelRequest::builder()
.model(cortecs)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Cortecs::builder()`
### API Key
```rust
let cortecs = Cortecs::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `CORTECS_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let cortecs = Cortecs::::builder()
.base_url("https://api.cortecs.ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let cortecs = Cortecs::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let cortecs = Cortecs::::builder()
.provider_name("Cortecs")
.build()?;
```
### Full Custom Configuration Example
```rust
let cortecs = Cortecs::::builder()
.api_key("your-api-key")
.base_url("https://api.cortecs.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Cortecs")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Cortecs;
// Specify model as a string at runtime
let cortecs = Cortecs::model_name("claude-4-5-sonnet");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Cortecs,
};
let cortecs = Cortecs::::builder()
.model_name("claude-4-5-sonnet")
.api_key("your-api-key")
.base_url("https://api.cortecs.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Cortecs")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Cortecs::claude_4_5_sonnet()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Deepseek (/docs/providers/deepseek)
AISDK provides first-class support for Deepseek with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Deepseek provider feature:
```bash
cargo add aisdk --features deepseek
```
This installs AISDK with the Deepseek provider enabled. Once you have enabled the Deepseek provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Deepseek::model_name()`, where **model\_name** is the Deepseek model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Deepseek;
let deepseek = Deepseek::deepseek_chat();
```
This initializes the provider with:
* Model: `"deepseek-chat"`
* API key from environment (if set with `DEEPSEEK_API_KEY`)
* Deepseek's default base URL ([https://api.deepseek.com](https://api.deepseek.com))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Deepseek,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let deepseek = Deepseek::deepseek_chat();
let response = LanguageModelRequest::builder()
.model(deepseek)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Deepseek::builder()`
### API Key
```rust
let deepseek = Deepseek::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `DEEPSEEK_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let deepseek = Deepseek::::builder()
.base_url("https://api.deepseek.com")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let deepseek = Deepseek::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let deepseek = Deepseek::::builder()
.provider_name("Deepseek")
.build()?;
```
### Full Custom Configuration Example
```rust
let deepseek = Deepseek::::builder()
.api_key("your-api-key")
.base_url("https://api.deepseek.com")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Deepseek")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Deepseek;
// Specify model as a string at runtime
let deepseek = Deepseek::model_name("deepseek-chat");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Deepseek,
};
let deepseek = Deepseek::::builder()
.model_name("deepseek-chat")
.api_key("your-api-key")
.base_url("https://api.deepseek.com")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Deepseek")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Deepseek::deepseek_chat()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Fastrouter (/docs/providers/fastrouter)
AISDK provides first-class support for Fastrouter with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Fastrouter provider feature:
```bash
cargo add aisdk --features fastrouter
```
This installs AISDK with the Fastrouter provider enabled. Once you have enabled the Fastrouter provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Fastrouter::model_name()`, where **model\_name** is the Fastrouter model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Fastrouter;
let fastrouter = Fastrouter::anthropic_claude_opus_4_1();
```
This initializes the provider with:
* Model: `"anthropic/claude-opus-4.1"`
* API key from environment (if set with `FASTROUTER_API_KEY`)
* Fastrouter's default base URL ([https://go.fastrouter.ai/api/v1](https://go.fastrouter.ai/api/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Fastrouter,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let fastrouter = Fastrouter::anthropic_claude_opus_4_1();
let response = LanguageModelRequest::builder()
.model(fastrouter)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Fastrouter::builder()`
### API Key
```rust
let fastrouter = Fastrouter::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `FASTROUTER_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let fastrouter = Fastrouter::::builder()
.base_url("https://go.fastrouter.ai/api/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let fastrouter = Fastrouter::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let fastrouter = Fastrouter::::builder()
.provider_name("Fastrouter")
.build()?;
```
### Full Custom Configuration Example
```rust
let fastrouter = Fastrouter::::builder()
.api_key("your-api-key")
.base_url("https://go.fastrouter.ai/api/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Fastrouter")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Fastrouter;
// Specify model as a string at runtime
let fastrouter = Fastrouter::model_name("anthropic/claude-opus-4.1");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Fastrouter,
};
let fastrouter = Fastrouter::::builder()
.model_name("anthropic/claude-opus-4.1")
.api_key("your-api-key")
.base_url("https://go.fastrouter.ai/api/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Fastrouter")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Fastrouter::anthropic_claude_opus_4_1()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# FireworksAi (/docs/providers/fireworks-ai)
AISDK provides first-class support for FireworksAi with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the FireworksAi provider feature:
```bash
cargo add aisdk --features fireworks-ai
```
This installs AISDK with the FireworksAi provider enabled. Once you have enabled the FireworksAi provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `FireworksAi::model_name()`, where **model\_name** is the FireworksAi model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::FireworksAi;
let fireworks-ai = FireworksAi::models_deepseek_r1_0528();
```
This initializes the provider with:
* Model: `"accounts/fireworks/models/deepseek-r1-0528"`
* API key from environment (if set with `FIREWORKS_API_KEY`)
* FireworksAi's default base URL ([https://api.fireworks.ai/inference/v1/](https://api.fireworks.ai/inference/v1/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::FireworksAi,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let fireworks-ai = FireworksAi::models_deepseek_r1_0528();
let response = LanguageModelRequest::builder()
.model(fireworks-ai)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `FireworksAi::builder()`
### API Key
```rust
let fireworks-ai = FireworksAi::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `FIREWORKS_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let fireworks-ai = FireworksAi::::builder()
.base_url("https://api.fireworks.ai/inference/v1/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let fireworks-ai = FireworksAi::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let fireworks-ai = FireworksAi::::builder()
.provider_name("FireworksAi")
.build()?;
```
### Full Custom Configuration Example
```rust
let fireworks-ai = FireworksAi::::builder()
.api_key("your-api-key")
.base_url("https://api.fireworks.ai/inference/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("FireworksAi")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::FireworksAi;
// Specify model as a string at runtime
let fireworks-ai = FireworksAi::model_name("accounts/fireworks/models/deepseek-r1-0528");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::FireworksAi,
};
let fireworks-ai = FireworksAi::::builder()
.model_name("accounts/fireworks/models/deepseek-r1-0528")
.api_key("your-api-key")
.base_url("https://api.fireworks.ai/inference/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("FireworksAi")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `FireworksAi::models_deepseek_r1_0528()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Firmware (/docs/providers/firmware)
AISDK provides first-class support for Firmware with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Firmware provider feature:
```bash
cargo add aisdk --features firmware
```
This installs AISDK with the Firmware provider enabled. Once you have enabled the Firmware provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Firmware::model_name()`, where **model\_name** is the Firmware model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Firmware;
let firmware = Firmware::claude_haiku_4_5();
```
This initializes the provider with:
* Model: `"claude-haiku-4-5"`
* API key from environment (if set with `FIRMWARE_API_KEY`)
* Firmware's default base URL ([https://app.firmware.ai/api/v1](https://app.firmware.ai/api/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Firmware,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let firmware = Firmware::claude_haiku_4_5();
let response = LanguageModelRequest::builder()
.model(firmware)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Firmware::builder()`
### API Key
```rust
let firmware = Firmware::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `FIRMWARE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let firmware = Firmware::::builder()
.base_url("https://app.firmware.ai/api/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let firmware = Firmware::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let firmware = Firmware::::builder()
.provider_name("Firmware")
.build()?;
```
### Full Custom Configuration Example
```rust
let firmware = Firmware::::builder()
.api_key("your-api-key")
.base_url("https://app.firmware.ai/api/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Firmware")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Firmware;
// Specify model as a string at runtime
let firmware = Firmware::model_name("claude-haiku-4-5");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Firmware,
};
let firmware = Firmware::::builder()
.model_name("claude-haiku-4-5")
.api_key("your-api-key")
.base_url("https://app.firmware.ai/api/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Firmware")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Firmware::claude_haiku_4_5()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Friendli (/docs/providers/friendli)
AISDK provides first-class support for Friendli with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Friendli provider feature:
```bash
cargo add aisdk --features friendli
```
This installs AISDK with the Friendli provider enabled. Once you have enabled the Friendli provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Friendli::model_name()`, where **model\_name** is the Friendli model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Friendli;
let friendli = Friendli::lgai_exaone_exaone_4_0_1_32b();
```
This initializes the provider with:
* Model: `"LGAI-EXAONE/EXAONE-4.0.1-32B"`
* API key from environment (if set with `FRIENDLI_TOKEN`)
* Friendli's default base URL ([https://api.friendli.ai/serverless/v1](https://api.friendli.ai/serverless/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Friendli,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let friendli = Friendli::lgai_exaone_exaone_4_0_1_32b();
let response = LanguageModelRequest::builder()
.model(friendli)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Friendli::builder()`
### API Key
```rust
let friendli = Friendli::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `FRIENDLI_TOKEN` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let friendli = Friendli::::builder()
.base_url("https://api.friendli.ai/serverless/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let friendli = Friendli::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let friendli = Friendli::::builder()
.provider_name("Friendli")
.build()?;
```
### Full Custom Configuration Example
```rust
let friendli = Friendli::::builder()
.api_key("your-api-key")
.base_url("https://api.friendli.ai/serverless/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Friendli")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Friendli;
// Specify model as a string at runtime
let friendli = Friendli::model_name("LGAI-EXAONE/EXAONE-4.0.1-32B");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Friendli,
};
let friendli = Friendli::::builder()
.model_name("LGAI-EXAONE/EXAONE-4.0.1-32B")
.api_key("your-api-key")
.base_url("https://api.friendli.ai/serverless/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Friendli")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Friendli::lgai_exaone_exaone_4_0_1_32b()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# GithubCopilot (/docs/providers/github-copilot)
AISDK provides first-class support for GithubCopilot with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the GithubCopilot provider feature:
```bash
cargo add aisdk --features github-copilot
```
This installs AISDK with the GithubCopilot provider enabled. Once you have enabled the GithubCopilot provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `GithubCopilot::model_name()`, where **model\_name** is the GithubCopilot model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::GithubCopilot;
let github-copilot = GithubCopilot::claude_haiku_4_5();
```
This initializes the provider with:
* Model: `"claude-haiku-4.5"`
* API key from environment (if set with `GITHUB_TOKEN`)
* GithubCopilot's default base URL ([https://api.githubcopilot.com](https://api.githubcopilot.com))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::GithubCopilot,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let github-copilot = GithubCopilot::claude_haiku_4_5();
let response = LanguageModelRequest::builder()
.model(github-copilot)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `GithubCopilot::builder()`
### API Key
```rust
let github-copilot = GithubCopilot::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `GITHUB_TOKEN` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let github-copilot = GithubCopilot::::builder()
.base_url("https://api.githubcopilot.com")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let github-copilot = GithubCopilot::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let github-copilot = GithubCopilot::::builder()
.provider_name("GithubCopilot")
.build()?;
```
### Full Custom Configuration Example
```rust
let github-copilot = GithubCopilot::::builder()
.api_key("your-api-key")
.base_url("https://api.githubcopilot.com")
.path("https://full-url.example/v1/chat/completions")
.provider_name("GithubCopilot")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::GithubCopilot;
// Specify model as a string at runtime
let github-copilot = GithubCopilot::model_name("claude-haiku-4.5");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::GithubCopilot,
};
let github-copilot = GithubCopilot::::builder()
.model_name("claude-haiku-4.5")
.api_key("your-api-key")
.base_url("https://api.githubcopilot.com")
.path("https://full-url.example/v1/chat/completions")
.provider_name("GithubCopilot")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `GithubCopilot::claude_haiku_4_5()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# GithubModels (/docs/providers/github-models)
AISDK provides first-class support for GithubModels with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the GithubModels provider feature:
```bash
cargo add aisdk --features github-models
```
This installs AISDK with the GithubModels provider enabled. Once you have enabled the GithubModels provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `GithubModels::model_name()`, where **model\_name** is the GithubModels model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::GithubModels;
let github-models = GithubModels::ai21_labs_ai21_jamba_1_5_large();
```
This initializes the provider with:
* Model: `"ai21-labs/ai21-jamba-1.5-large"`
* API key from environment (if set with `GITHUB_TOKEN`)
* GithubModels's default base URL ([https://models.github.ai/inference](https://models.github.ai/inference))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::GithubModels,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let github-models = GithubModels::ai21_labs_ai21_jamba_1_5_large();
let response = LanguageModelRequest::builder()
.model(github-models)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `GithubModels::builder()`
### API Key
```rust
let github-models = GithubModels::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `GITHUB_TOKEN` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let github-models = GithubModels::::builder()
.base_url("https://models.github.ai/inference")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let github-models = GithubModels::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let github-models = GithubModels::::builder()
.provider_name("GithubModels")
.build()?;
```
### Full Custom Configuration Example
```rust
let github-models = GithubModels::::builder()
.api_key("your-api-key")
.base_url("https://models.github.ai/inference")
.path("https://full-url.example/v1/chat/completions")
.provider_name("GithubModels")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::GithubModels;
// Specify model as a string at runtime
let github-models = GithubModels::model_name("ai21-labs/ai21-jamba-1.5-large");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::GithubModels,
};
let github-models = GithubModels::::builder()
.model_name("ai21-labs/ai21-jamba-1.5-large")
.api_key("your-api-key")
.base_url("https://models.github.ai/inference")
.path("https://full-url.example/v1/chat/completions")
.provider_name("GithubModels")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `GithubModels::ai21_labs_ai21_jamba_1_5_large()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Google (/docs/providers/google)
AISDK provides first-class support for Google with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Google provider feature:
```bash
cargo add aisdk --features google
```
This installs AISDK with the Google provider enabled. Once you have enabled the Google provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Google::model_name()`, where **model\_name** is the Google model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Google;
let google = Google::gemini_1_5_flash();
```
This initializes the provider with:
* Model: `"gemini-1.5-flash"`
* API key from environment (if set with `GOOGLE_API_KEY`)
* Google's default base URL ([https://generativelanguage.googleapis.com](https://generativelanguage.googleapis.com))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Google,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let google = Google::gemini_1_5_flash();
let response = LanguageModelRequest::builder()
.model(google)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Google::builder()`
### API Key
```rust
let google = Google::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `GOOGLE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let google = Google::::builder()
.base_url("https://generativelanguage.googleapis.com")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let google = Google::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let google = Google::::builder()
.provider_name("Google")
.build()?;
```
### Full Custom Configuration Example
```rust
let google = Google::::builder()
.api_key("your-api-key")
.base_url("https://generativelanguage.googleapis.com")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Google")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Google;
// Specify model as a string at runtime
let google = Google::model_name("gemini-1.5-flash");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Google,
};
let google = Google::::builder()
.model_name("gemini-1.5-flash")
.api_key("your-api-key")
.base_url("https://generativelanguage.googleapis.com")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Google")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Google::gemini_1_5_flash()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Groq (/docs/providers/groq)
AISDK provides first-class support for Groq with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Groq provider feature:
```bash
cargo add aisdk --features groq
```
This installs AISDK with the Groq provider enabled. Once you have enabled the Groq provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Groq::model_name()`, where **model\_name** is the Groq model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Groq;
let groq = Groq::llama_3_1_8b_instant();
```
This initializes the provider with:
* Model: `"llama-3.1-8b-instant"`
* API key from environment (if set with `GROQ_API_KEY`)
* Groq's default base URL ([https://api.groq.com/openai/v1/](https://api.groq.com/openai/v1/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Groq,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let groq = Groq::llama_3_1_8b_instant();
let response = LanguageModelRequest::builder()
.model(groq)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Groq::builder()`
### API Key
```rust
let groq = Groq::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `GROQ_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let groq = Groq::::builder()
.base_url("https://api.groq.com/openai/v1/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let groq = Groq::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let groq = Groq::::builder()
.provider_name("Groq")
.build()?;
```
### Full Custom Configuration Example
```rust
let groq = Groq::::builder()
.api_key("your-api-key")
.base_url("https://api.groq.com/openai/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Groq")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Groq;
// Specify model as a string at runtime
let groq = Groq::model_name("llama-3.1-8b-instant");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Groq,
};
let groq = Groq::::builder()
.model_name("llama-3.1-8b-instant")
.api_key("your-api-key")
.base_url("https://api.groq.com/openai/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Groq")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Groq::llama_3_1_8b_instant()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Helicone (/docs/providers/helicone)
AISDK provides first-class support for Helicone with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Helicone provider feature:
```bash
cargo add aisdk --features helicone
```
This installs AISDK with the Helicone provider enabled. Once you have enabled the Helicone provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Helicone::model_name()`, where **model\_name** is the Helicone model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Helicone;
let helicone = Helicone::chatgpt_4o_latest();
```
This initializes the provider with:
* Model: `"chatgpt-4o-latest"`
* API key from environment (if set with `HELICONE_API_KEY`)
* Helicone's default base URL ([https://ai-gateway.helicone.ai/v1](https://ai-gateway.helicone.ai/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Helicone,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let helicone = Helicone::chatgpt_4o_latest();
let response = LanguageModelRequest::builder()
.model(helicone)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Helicone::builder()`
### API Key
```rust
let helicone = Helicone::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `HELICONE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let helicone = Helicone::::builder()
.base_url("https://ai-gateway.helicone.ai/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let helicone = Helicone::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let helicone = Helicone::::builder()
.provider_name("Helicone")
.build()?;
```
### Full Custom Configuration Example
```rust
let helicone = Helicone::::builder()
.api_key("your-api-key")
.base_url("https://ai-gateway.helicone.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Helicone")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Helicone;
// Specify model as a string at runtime
let helicone = Helicone::model_name("chatgpt-4o-latest");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Helicone,
};
let helicone = Helicone::::builder()
.model_name("chatgpt-4o-latest")
.api_key("your-api-key")
.base_url("https://ai-gateway.helicone.ai/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Helicone")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Helicone::chatgpt_4o_latest()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Huggingface (/docs/providers/huggingface)
AISDK provides first-class support for Huggingface with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Huggingface provider feature:
```bash
cargo add aisdk --features huggingface
```
This installs AISDK with the Huggingface provider enabled. Once you have enabled the Huggingface provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Huggingface::model_name()`, where **model\_name** is the Huggingface model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Huggingface;
let huggingface = Huggingface::minimaxai_minimax_m2_1();
```
This initializes the provider with:
* Model: `"MiniMaxAI/MiniMax-M2.1"`
* API key from environment (if set with `HF_TOKEN`)
* Huggingface's default base URL ([https://router.huggingface.co/v1](https://router.huggingface.co/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Huggingface,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let huggingface = Huggingface::minimaxai_minimax_m2_1();
let response = LanguageModelRequest::builder()
.model(huggingface)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Huggingface::builder()`
### API Key
```rust
let huggingface = Huggingface::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `HF_TOKEN` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let huggingface = Huggingface::::builder()
.base_url("https://router.huggingface.co/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let huggingface = Huggingface::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let huggingface = Huggingface::::builder()
.provider_name("Huggingface")
.build()?;
```
### Full Custom Configuration Example
```rust
let huggingface = Huggingface::::builder()
.api_key("your-api-key")
.base_url("https://router.huggingface.co/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Huggingface")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Huggingface;
// Specify model as a string at runtime
let huggingface = Huggingface::model_name("MiniMaxAI/MiniMax-M2.1");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Huggingface,
};
let huggingface = Huggingface::::builder()
.model_name("MiniMaxAI/MiniMax-M2.1")
.api_key("your-api-key")
.base_url("https://router.huggingface.co/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Huggingface")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Huggingface::minimaxai_minimax_m2_1()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Iflowcn (/docs/providers/iflowcn)
AISDK provides first-class support for Iflowcn with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Iflowcn provider feature:
```bash
cargo add aisdk --features iflowcn
```
This installs AISDK with the Iflowcn provider enabled. Once you have enabled the Iflowcn provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Iflowcn::model_name()`, where **model\_name** is the Iflowcn model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Iflowcn;
let iflowcn = Iflowcn::deepseek_r1();
```
This initializes the provider with:
* Model: `"deepseek-r1"`
* API key from environment (if set with `IFLOW_API_KEY`)
* Iflowcn's default base URL ([https://apis.iflow.cn/v1](https://apis.iflow.cn/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Iflowcn,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let iflowcn = Iflowcn::deepseek_r1();
let response = LanguageModelRequest::builder()
.model(iflowcn)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Iflowcn::builder()`
### API Key
```rust
let iflowcn = Iflowcn::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `IFLOW_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let iflowcn = Iflowcn::::builder()
.base_url("https://apis.iflow.cn/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let iflowcn = Iflowcn::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let iflowcn = Iflowcn::::builder()
.provider_name("Iflowcn")
.build()?;
```
### Full Custom Configuration Example
```rust
let iflowcn = Iflowcn::::builder()
.api_key("your-api-key")
.base_url("https://apis.iflow.cn/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Iflowcn")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Iflowcn;
// Specify model as a string at runtime
let iflowcn = Iflowcn::model_name("deepseek-r1");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Iflowcn,
};
let iflowcn = Iflowcn::::builder()
.model_name("deepseek-r1")
.api_key("your-api-key")
.base_url("https://apis.iflow.cn/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Iflowcn")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Iflowcn::deepseek_r1()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Inception (/docs/providers/inception)
AISDK provides first-class support for Inception with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Inception provider feature:
```bash
cargo add aisdk --features inception
```
This installs AISDK with the Inception provider enabled. Once you have enabled the Inception provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Inception::model_name()`, where **model\_name** is the Inception model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Inception;
let inception = Inception::mercury();
```
This initializes the provider with:
* Model: `"mercury"`
* API key from environment (if set with `INCEPTION_API_KEY`)
* Inception's default base URL ([https://api.inceptionlabs.ai/v1/](https://api.inceptionlabs.ai/v1/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Inception,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let inception = Inception::mercury();
let response = LanguageModelRequest::builder()
.model(inception)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Inception::builder()`
### API Key
```rust
let inception = Inception::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `INCEPTION_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let inception = Inception::::builder()
.base_url("https://api.inceptionlabs.ai/v1/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let inception = Inception::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let inception = Inception::::builder()
.provider_name("Inception")
.build()?;
```
### Full Custom Configuration Example
```rust
let inception = Inception::::builder()
.api_key("your-api-key")
.base_url("https://api.inceptionlabs.ai/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Inception")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Inception;
// Specify model as a string at runtime
let inception = Inception::model_name("mercury");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Inception,
};
let inception = Inception::::builder()
.model_name("mercury")
.api_key("your-api-key")
.base_url("https://api.inceptionlabs.ai/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Inception")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Inception::mercury()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Inference (/docs/providers/inference)
AISDK provides first-class support for Inference with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Inference provider feature:
```bash
cargo add aisdk --features inference
```
This installs AISDK with the Inference provider enabled. Once you have enabled the Inference provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Inference::model_name()`, where **model\_name** is the Inference model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Inference;
let inference = Inference::google_gemma_3();
```
This initializes the provider with:
* Model: `"google/gemma-3"`
* API key from environment (if set with `INFERENCE_API_KEY`)
* Inference's default base URL ([https://inference.net/v1](https://inference.net/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Inference,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let inference = Inference::google_gemma_3();
let response = LanguageModelRequest::builder()
.model(inference)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Inference::builder()`
### API Key
```rust
let inference = Inference::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `INFERENCE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let inference = Inference::::builder()
.base_url("https://inference.net/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let inference = Inference::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let inference = Inference::::builder()
.provider_name("Inference")
.build()?;
```
### Full Custom Configuration Example
```rust
let inference = Inference::::builder()
.api_key("your-api-key")
.base_url("https://inference.net/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Inference")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Inference;
// Specify model as a string at runtime
let inference = Inference::model_name("google/gemma-3");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Inference,
};
let inference = Inference::::builder()
.model_name("google/gemma-3")
.api_key("your-api-key")
.base_url("https://inference.net/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Inference")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Inference::google_gemma_3()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# IoNet (/docs/providers/io-net)
AISDK provides first-class support for IoNet with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the IoNet provider feature:
```bash
cargo add aisdk --features io-net
```
This installs AISDK with the IoNet provider enabled. Once you have enabled the IoNet provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `IoNet::model_name()`, where **model\_name** is the IoNet model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::IoNet;
let io-net = IoNet::intel_qwen3_coder_480b_a35b_instruct_int4_mixed_ar();
```
This initializes the provider with:
* Model: `"Intel/Qwen3-Coder-480B-A35B-Instruct-int4-mixed-ar"`
* API key from environment (if set with `IOINTELLIGENCE_API_KEY`)
* IoNet's default base URL ([https://api.intelligence.io.solutions/api/v1](https://api.intelligence.io.solutions/api/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::IoNet,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let io-net = IoNet::intel_qwen3_coder_480b_a35b_instruct_int4_mixed_ar();
let response = LanguageModelRequest::builder()
.model(io-net)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `IoNet::builder()`
### API Key
```rust
let io-net = IoNet::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `IOINTELLIGENCE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let io-net = IoNet::::builder()
.base_url("https://api.intelligence.io.solutions/api/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let io-net = IoNet::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let io-net = IoNet::::builder()
.provider_name("IoNet")
.build()?;
```
### Full Custom Configuration Example
```rust
let io-net = IoNet::::builder()
.api_key("your-api-key")
.base_url("https://api.intelligence.io.solutions/api/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("IoNet")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::IoNet;
// Specify model as a string at runtime
let io-net = IoNet::model_name("Intel/Qwen3-Coder-480B-A35B-Instruct-int4-mixed-ar");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::IoNet,
};
let io-net = IoNet::::builder()
.model_name("Intel/Qwen3-Coder-480B-A35B-Instruct-int4-mixed-ar")
.api_key("your-api-key")
.base_url("https://api.intelligence.io.solutions/api/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("IoNet")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `IoNet::intel_qwen3_coder_480b_a35b_instruct_int4_mixed_ar()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Jiekou (/docs/providers/jiekou)
AISDK provides first-class support for Jiekou with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Jiekou provider feature:
```bash
cargo add aisdk --features jiekou
```
This installs AISDK with the Jiekou provider enabled. Once you have enabled the Jiekou provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Jiekou::model_name()`, where **model\_name** is the Jiekou model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Jiekou;
let jiekou = Jiekou::baidu_ernie_4_5_300b_a47b_paddle();
```
This initializes the provider with:
* Model: `"baidu/ernie-4.5-300b-a47b-paddle"`
* API key from environment (if set with `JIEKOU_API_KEY`)
* Jiekou's default base URL ([https://api.jiekou.ai/openai](https://api.jiekou.ai/openai))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Jiekou,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let jiekou = Jiekou::baidu_ernie_4_5_300b_a47b_paddle();
let response = LanguageModelRequest::builder()
.model(jiekou)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Jiekou::builder()`
### API Key
```rust
let jiekou = Jiekou::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `JIEKOU_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let jiekou = Jiekou::::builder()
.base_url("https://api.jiekou.ai/openai")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let jiekou = Jiekou::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let jiekou = Jiekou::::builder()
.provider_name("Jiekou")
.build()?;
```
### Full Custom Configuration Example
```rust
let jiekou = Jiekou::::builder()
.api_key("your-api-key")
.base_url("https://api.jiekou.ai/openai")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Jiekou")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Jiekou;
// Specify model as a string at runtime
let jiekou = Jiekou::model_name("baidu/ernie-4.5-300b-a47b-paddle");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Jiekou,
};
let jiekou = Jiekou::::builder()
.model_name("baidu/ernie-4.5-300b-a47b-paddle")
.api_key("your-api-key")
.base_url("https://api.jiekou.ai/openai")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Jiekou")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Jiekou::baidu_ernie_4_5_300b_a47b_paddle()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# KuaeCloudCodingPlan (/docs/providers/kuae-cloud-coding-plan)
AISDK provides first-class support for KuaeCloudCodingPlan with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the KuaeCloudCodingPlan provider feature:
```bash
cargo add aisdk --features kuae-cloud-coding-plan
```
This installs AISDK with the KuaeCloudCodingPlan provider enabled. Once you have enabled the KuaeCloudCodingPlan provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `KuaeCloudCodingPlan::model_name()`, where **model\_name** is the KuaeCloudCodingPlan model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::KuaeCloudCodingPlan;
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::glm_4_7();
```
This initializes the provider with:
* Model: `"GLM-4.7"`
* API key from environment (if set with `KUAE_API_KEY`)
* KuaeCloudCodingPlan's default base URL ([https://coding-plan-endpoint.kuaecloud.net/v1](https://coding-plan-endpoint.kuaecloud.net/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::KuaeCloudCodingPlan,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::glm_4_7();
let response = LanguageModelRequest::builder()
.model(kuae-cloud-coding-plan)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `KuaeCloudCodingPlan::builder()`
### API Key
```rust
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `KUAE_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::::builder()
.base_url("https://coding-plan-endpoint.kuaecloud.net/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::::builder()
.provider_name("KuaeCloudCodingPlan")
.build()?;
```
### Full Custom Configuration Example
```rust
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::::builder()
.api_key("your-api-key")
.base_url("https://coding-plan-endpoint.kuaecloud.net/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("KuaeCloudCodingPlan")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::KuaeCloudCodingPlan;
// Specify model as a string at runtime
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::model_name("GLM-4.7");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::KuaeCloudCodingPlan,
};
let kuae-cloud-coding-plan = KuaeCloudCodingPlan::::builder()
.model_name("GLM-4.7")
.api_key("your-api-key")
.base_url("https://coding-plan-endpoint.kuaecloud.net/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("KuaeCloudCodingPlan")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `KuaeCloudCodingPlan::glm_4_7()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Llama (/docs/providers/llama)
AISDK provides first-class support for Llama with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Llama provider feature:
```bash
cargo add aisdk --features llama
```
This installs AISDK with the Llama provider enabled. Once you have enabled the Llama provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Llama::model_name()`, where **model\_name** is the Llama model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Llama;
let llama = Llama::cerebras_llama_4_maverick_17b_128e_instruct();
```
This initializes the provider with:
* Model: `"cerebras-llama-4-maverick-17b-128e-instruct"`
* API key from environment (if set with `LLAMA_API_KEY`)
* Llama's default base URL ([https://api.llama.com/compat/v1/](https://api.llama.com/compat/v1/))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Llama,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let llama = Llama::cerebras_llama_4_maverick_17b_128e_instruct();
let response = LanguageModelRequest::builder()
.model(llama)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Llama::builder()`
### API Key
```rust
let llama = Llama::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `LLAMA_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let llama = Llama::::builder()
.base_url("https://api.llama.com/compat/v1/")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let llama = Llama::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let llama = Llama::::builder()
.provider_name("Llama")
.build()?;
```
### Full Custom Configuration Example
```rust
let llama = Llama::::builder()
.api_key("your-api-key")
.base_url("https://api.llama.com/compat/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Llama")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Llama;
// Specify model as a string at runtime
let llama = Llama::model_name("cerebras-llama-4-maverick-17b-128e-instruct");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Llama,
};
let llama = Llama::::builder()
.model_name("cerebras-llama-4-maverick-17b-128e-instruct")
.api_key("your-api-key")
.base_url("https://api.llama.com/compat/v1/")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Llama")
.build()?;
```
**Warning**: When using `DynamicModel`, model capabilities are **not validated at compile time**.
This means there's no guarantee the model supports requested features (e.g., tool calls, structured output).
For compile-time safety, use the typed methods like `Llama::cerebras_llama_4_maverick_17b_128e_instruct()`.
## Next Steps
* Take a deeper look at text generation features [Generating Text](/docs/concepts/generating-text#generate_text) / [Streaming Text](/docs/concepts/generating-text#stream_text)
* Explore [Structured Output](/docs/concepts/structured-output) for reliable agent data.
* Learn how to create [Custom Tools](/docs/concepts/tools).
* Learn more about [Agents](/docs/concepts/agents).
# Lmstudio (/docs/providers/lmstudio)
AISDK provides first-class support for Lmstudio with fully typed model APIs.
Model capabilities are enforced at compile time using Rust's type system.
This prevents model capability mismatches and guarantees the selected model is valid for the task (e.g. tool calling).
## Installation
Enable the Lmstudio provider feature:
```bash
cargo add aisdk --features lmstudio
```
This installs AISDK with the Lmstudio provider enabled. Once you have enabled the Lmstudio provider, you can use all aisdk features with it.
## Create a Provider Instance
To create a provider instance, call `Lmstudio::model_name()`, where **model\_name** is the Lmstudio model you want to use.
Model names are exposed as snake-case methods.
```rust
use aisdk::providers::Lmstudio;
let lmstudio = Lmstudio::openai_gpt_oss_20b();
```
This initializes the provider with:
* Model: `"openai/gpt-oss-20b"`
* API key from environment (if set with `LMSTUDIO_API_KEY`)
* Lmstudio's default base URL ([http://127.0.0.1:1234/v1](http://127.0.0.1:1234/v1))
## Basic Text Generation
Example using [LanguageModelRequest](https://docs.rs/aisdk/latest/aisdk/core/struct.LanguageModelRequest.html) for text generation.
```rust
use aisdk::{
core::LanguageModelRequest,
providers::Lmstudio,
};
#[tokio::main]
async fn main() -> Result<(), Box> {
let lmstudio = Lmstudio::openai_gpt_oss_20b();
let response = LanguageModelRequest::builder()
.model(lmstudio)
.prompt("Write a short poem about Rust.")
.build()
.generate_text()
.await?;
println!("Response text: {:?}", response.text());
Ok(())
}
```
## Provider Settings
You can customize provider configuration using `Lmstudio::builder()`
### API Key
```rust
let lmstudio = Lmstudio::::builder()
.api_key("your-api-key")
.build()?;
```
If not specified, AISDK uses the `LMSTUDIO_API_KEY` environment variable.
### Base URL
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
```rust
let lmstudio = Lmstudio::::builder()
.base_url("http://127.0.0.1:1234/v1")
.build()?;
```
### Path (Full URL Override)
Use `.path(...)` to override the full request URL instead of only the base URL.
```rust
let lmstudio = Lmstudio::::builder()
.path("https://full-url.example/v1/chat/completions")
.build()?;
```
### Provider Name
For logging, analytics, and observability.
```rust
let lmstudio = Lmstudio::::builder()
.provider_name("Lmstudio")
.build()?;
```
### Full Custom Configuration Example
```rust
let lmstudio = Lmstudio::::builder()
.api_key("your-api-key")
.base_url("http://127.0.0.1:1234/v1")
.path("https://full-url.example/v1/chat/completions")
.provider_name("Lmstudio")
.build()?;
```
## Dynamic Model Selection
For runtime model selection (e.g., loading models from config files), use `DynamicModel`:
### Using model\_name() Method with Default Settings
```rust
use aisdk::providers::Lmstudio;
// Specify model as a string at runtime
let lmstudio = Lmstudio::model_name("openai/gpt-oss-20b");
```
### Using Builder Pattern with Custom Settings
```rust
use aisdk::{
core::DynamicModel,
providers::Lmstudio,
};
let lmstudio = Lmstudio::