> ## Documentation Index
> Fetch the complete documentation index at: https://nestcrate.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# nestrs-ai API

> Reference for AiModule, AiService, FakeModel, generate_text / generate_object, and AgentToolRegistry.

Crate: [`nestrs-ai`](https://docs.rs/nestrs-ai/1.7.1) · Feature: `ai` · Guide: [AI](https://nestcrate.dev/ecosystem/ai.md)

```toml theme={null}
nestrs-ai = "1.7.1"
# or nestrs = { version = "1.7.1", features = ["ai"] }
```

## `AiModule::register`

Exports `AiService`.

## `AiOptions`

| Field | Role |
| - | - |
| `models` | `HashMap<String, Arc<dyn LanguageModel>>` — key `"default"` used when request model is `None` |
| `defaults_timeout_ms` | Passed to resilience timeout |
| `max_steps` | Agent loop bound |

## `AiService`

```rust theme={null}
pub fn new(options: AiOptions) -> Self
pub fn with_tools(self, tools: Arc<AgentToolRegistry>) -> Self
pub async fn generate_text(&self, req: GenerateTextRequest) -> Result<GenerateResult, AiError>
pub async fn generate_object(&self, req: GenerateObjectRequest) -> Result<GenerateResult, AiError>
```

`GenerateResult { text, object, steps, finish_reason }`.

## `LanguageModel`

```rust theme={null}
async fn call(&self, request: ModelCall) -> Result<ModelResponse, AiError>
```

`ModelResponse { text, tool_calls: Vec<ToolCall> }`.

## `FakeModel`

```rust theme={null}
FakeModel::new(vec![Ok(json!({"text": "…"})), Ok(json!({
  "tool_calls": [{"name": "echo", "arguments": {}}],
  "text": ""
}))])
```

## `AgentToolRegistry`

`register(AgentFunction { name, description, handler })` · `call(name, args).await`.

## `AiError`

`Configuration` · `Output` (validation / tool) · `Transport` (timeout / resilience).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.