AllToken Go SDK
Official Go SDK with raw HTTP wrapper for OpenAI and Anthropic surfaces.
Installation
go get
$ go get github.com/alltoken-ai/alltoken-goRequires Go 1.24+.
Quick start
One API key gives you both OpenAI-compatible and Anthropic-compatible endpoints:
Go
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "fmt" |
| 7 | "os" |
| 8 | |
| 9 | "github.com/alltoken-ai/alltoken-go" |
| 10 | ) |
| 11 | |
| 12 | func main() { |
| 13 | client, _ := alltoken.New(alltoken.Config{ |
| 14 | APIKey: os.Getenv("ALLTOKEN_API_KEY"), |
| 15 | }) |
| 16 | |
| 17 | // OpenAI-compatible (maps to /v1) |
| 18 | resp, _ := client.OpenAI.Raw.Do(context.Background(), "POST", "/chat/completions", map[string]any{ |
| 19 | "model": "gpt-4o", |
| 20 | "messages": []map[string]string{{"role": "user", "content": "Hello!"}}, |
| 21 | }) |
| 22 | defer resp.Body.Close() |
| 23 | |
| 24 | var out map[string]any |
| 25 | json.NewDecoder(resp.Body).Decode(&out) |
| 26 | fmt.Println(out) |
| 27 | } |
Configuration
Go
| 1 | client, err := alltoken.New(alltoken.Config{ |
| 2 | APIKey: "...", // required |
| 3 | BaseURL: "https://api.alltoken.ai", // optional |
| 4 | HTTPClient: &http.Client{Timeout: 60 * time.Second}, // optional |
| 5 | DefaultHeaders: map[string]string{"X-My-Tag": "a"}, // optional |
| 6 | }) |
API surface
.Raw is an HTTP client wrapper. Base URL and auth are set; call .Do(ctx, method, path, body) to hit any route. The body is JSON-encoded automatically. Types generated from the OpenAPI specs via oapi-codegen live under internal/gen/.
| Field | Base URL |
|---|---|
client.OpenAI.Raw | https://api.alltoken.ai/v1 |
client.Anthropic.Raw | https://api.alltoken.ai/anthropic |