Skip to main content

Setup

First, create a Terramind provider instance:

Text Generation

Simple Text Generation

Generate a single text response:

With System Message

Add context with a system message:

Multi-turn Conversation

Have a conversation with message history:

Streaming

Stream Text

Stream responses in real-time:

Stream with Full Response

Access both streaming and final result:

Object Generation

Generate Structured Data

Create type-safe structured output:

Stream Objects

Stream objects as they’re generated:

Tool Calling

Single Tool

Define and use a single tool:

Multiple Tools

Use multiple tools together:

Tool Call Results

Access tool call information:

Advanced Usage

Retry Logic

Implement retry logic for failed requests:

Cost Tracking

Track token usage and costs:

Abort Requests

Cancel long-running requests:

Framework Integration

Next.js App Router

Use in Next.js server actions:

Next.js API Routes

Create an API endpoint:

Express.js

Use with Express:

Best Practices

Cache Provider Instance

Reuse the provider instance across requests:

Environment Variables

Store sensitive data securely:
Never commit API keys to version control!

Error Boundaries

Wrap AI calls in error boundaries:

Next Steps

Available Models

See all available models and their capabilities

CLI Usage

Learn about the Terramind CLI