Skip to content

Quick Start

Arian edited this page Dec 24, 2025 · 3 revisions

Quick Start

Setup

  1. Set your API key (choose one or more):
# OpenRouter (default - access all models via one API)
export OPENROUTER_API_KEY="sk-or-..."

# Or use direct provider APIs:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
# Ollama requires no key (runs locally)
  1. Import the package:
import ai "gopkg.in/dragon-born/go-llm.v1"

Basic Usage

One-Liners

// Ask using default model (GPT-5)
resp, err := ai.Ask("What is 2+2?")

// Ask with system prompt
resp, err := ai.AskWith("Be brief", "Explain quantum physics")

// Ask specific model
resp, err := ai.AskModel(ai.ModelClaudeOpus, "Hello!")

Fluent API

// Chain methods
resp, err := ai.GPT5().
    System("You are a helpful assistant").
    Temperature(0.2).
    ThinkLow().
    User("Hello!").
    Send()

// Or use Ask() shorthand
resp, err := ai.Claude().
    System("Be concise").
    Ask("What is AI?")

Using Different Models

// OpenAI
ai.GPT5()        // GPT-5.2 (general purpose)
ai.GPT5Codex()   // GPT-5.2-Codex (code-specialized)
ai.GPT4o()       // GPT-4o

// Anthropic
ai.Claude()       // Claude Opus 4.5
ai.ClaudeSonnet() // Claude Sonnet 4.5
ai.ClaudeHaiku()  // Claude Haiku 3.5

// Google
ai.GeminiPro()   // Gemini 3 Pro (high precision, 1M context)
ai.Gemini()      // Gemini 3 Flash (ultra-fast)

// xAI
ai.GrokFast()    // Grok 4.1 Fast (2M context)
ai.Grok()        // Grok 3

// Any model by string
ai.Use("mistralai/mistral-large")

Direct Provider Access

Skip OpenRouter and call providers directly:

// Direct to Anthropic
ai.Anthropic().Claude().Ask("Hello")
ai.Anthropic().ClaudeSonnet().Ask("Hello")

// Direct to OpenAI
ai.OpenAI().GPT4o().Ask("Hello")
ai.OpenAI().O1().ThinkHigh().Ask("Complex reasoning task")

// Local Ollama (no API key needed)
ai.Ollama().Use("llama3:8b").Ask("Hello")
ai.Ollama().Use("mistral").Ask("Hello")

// Ollama on different host
ai.OllamaAt("http://gpu-server:11434").Use("llama3:70b").Ask("Hello")

Loading Prompts from Files

// Load from prompts/ directory
ai.GPT5().
    SystemFile("prompts/analyst.md").
    Ask("Analyze the market")

// Or use the Prompt shortcut
ai.Prompt("analyst").Ask("Analyze the market")

Template Variables

// prompts/analyst.md contains: "You analyze {{domain}} markets"
ai.GPT5().
    SystemFile("prompts/analyst.md").
    With(ai.Vars{"domain": "crypto"}).
    Ask("What's trending?")

// Or single variable
ai.Prompt("analyst").
    Var("domain", "stocks").
    Ask("Market update?")

Next Steps

Clone this wiki locally