v0.10.5

Getting Started

Last updated


Install go-llm-router, resolve an Agent from a provider@model name, and send a first request.

Requirements


  • Go 1.25 or newer
  • github.com/pardnchiu/go-pkg v0.13.14, the only direct dependency, pulled in by go get
  • A credential for the provider you target: an API key, an OAuth token for Copilot, Codex, or Grok, or a logged-in claude CLI on PATH for claude-code
  • Token storage through core/oauth uses the go-pkg keychain: macOS Keychain on darwin, secret-tool elsewhere with a .secrets file fallback

Install


  1. go get github.com/pardnchiu/go-llm-router

Build from source:
  1. git clone https://github.com/pardnchiu/go-llm-router.git
  2. cd go-llm-router
  3. go build ./...

Send a first request


Send always takes five arguments: a context, messages, tool definitions (nil is allowed), a Reasoning level, and a Mode. Every provider shares this signature, so switching models never changes the request loop.
  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "log"
  6. "os"
  7. "github.com/pardnchiu/go-llm-router/core"
  8. "github.com/pardnchiu/go-llm-router/core/router"
  9. )
  10. func main() {
  11. agent, err := router.New(router.Config{
  12. Name: "claude@claude-opus-5",
  13. APIKey: os.Getenv("ANTHROPIC_API_KEY"),
  14. })
  15. if err != nil {
  16. log.Fatalf("router.New: %v", err)
  17. }
  18. out, code, err := agent.Send(context.Background(),
  19. []llmrouter.Message{{Role: "user", Content: "Summarize Go generics in one sentence."}},
  20. nil, llmrouter.ReasoningDefault, llmrouter.ModeDefault)
  21. if err != nil {
  22. log.Fatalf("Send: http %d: %v", code, err)
  23. }
  24. if len(out.Choices) == 0 {
  25. log.Fatal("no choices returned")
  26. }
  27. fmt.Println(out.Choices[0].Message.Content)
  28. fmt.Printf("input=%d output=%d cache_read=%d\n",
  29. out.Usage.Input, out.Usage.Output, out.Usage.CacheRead)
  30. }

Errors carry the upstream HTTP status alongside them, so a retry policy can branch on code instead of parsing error strings.

Next steps


中文