Go SDK
Install and configure the official Go client.
On this page
The official Go client for the Caedral API gateway. Authenticate with a cd_live_ API key. Chat completions may set Notre via the request struct (mode off|auto, telemetry). Runtime is included on every plan and applied on eligible POST /v1/chat/completions when the platform runs Notre — not on embeddings, rerank, voice, or images. Idiomatic patterns: context.Context, functional options, and channel-based streaming. Module: github.com/trycaedral/caedral-go.
Installation
go get github.com/trycaedral/caedral-goQuickstart
package main import ( "context" "fmt" "log" "time" "github.com/trycaedral/caedral-go") func main() { client, err := caedral.NewClient( "cd_live_...", caedral.WithBaseURL("http://localhost:5001"), ) if err != nil { log.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() prompt := "Hello!" completion, err := client.Chat.Completions.Create(ctx, caedral.ChatCompletionRequest{ Model: "anthropic/claude-haiku-4.5", Messages: []caedral.ChatMessage{ {Role: "user", Content: &prompt}, }, }) if err != nil { log.Fatal(err) } fmt.Println(completion.Choices[0].Message["content"])}Repository: github.com/trycaedral/caedral-go — see sdk-go/ in the Caedral monorepo.
| Option | Default | Description |
|---|---|---|
| WithBaseURL(url) | https://api.caedral.com | API gateway base URL |
| WithHTTPClient(c) | http.Client{Timeout: 120s} | Custom HTTP client |
| WithMaxRetries(n) | 3 | Retries for idempotent GET requests |
| WithTimeout(d) | 120s | Request timeout |
client.Chat.Completions.Create(ctx, req)
Create a chat completion. Pass Stream: true in ChatCompletionRequest for streaming.
completion, err := client.Chat.Completions.Create(ctx, caedral.ChatCompletionRequest{ Model: "anthropic/claude-sonnet-4.5", Messages: []caedral.ChatMessage{ {Role: "user", Content: &prompt}, },})Streaming (channels)
req := caedral.ChatCompletionRequest{ Model: "anthropic/claude-haiku-4.5", Messages: []caedral.ChatMessage{{Role: "user", Content: &prompt}}, Stream: true,}chunks, errCh, err := client.Chat.Completions.CreateStream(ctx, req)if err != nil { log.Fatal(err) } for chunk := range chunks { if len(chunk.Choices) > 0 { if text, ok := chunk.Choices[0].Delta["content"].(string); ok { fmt.Print(text) } }}if streamErr := <-errCh; streamErr != nil { log.Fatal(streamErr)}Streaming (iterator-style)
stream, err := client.Chat.Completions.OpenStream(ctx, req)if err != nil { log.Fatal(err) }defer stream.Close() for { chunk, err := stream.Recv() if err == io.EOF { break } if err != nil { log.Fatal(err) } _ = chunk}client.Models.List(ctx)
models, err := client.Models.List(ctx)client.Usage.Get(ctx)
usage, err := client.Usage.Get(ctx)fmt.Println(usage.AccountStatus)// Pools carry usedMilli / limitMilli / percentUsed for caedral and externalclient.Embeddings.Create(ctx, req)
result, err := client.Embeddings.Create(ctx, caedral.EmbeddingCreateRequest{ Model: "caedral-embed", Input: "Caedral unifies frontier models behind one API.",})client.Images.Generate(ctx, req)
image, err := client.Images.Generate(ctx, caedral.ImageGenerateRequest{ Model: "caedral-vision", Prompt: "A minimal geometric logo on a dark background",})client.Audio.Generate(ctx, req)
audio, err := client.Audio.Generate(ctx, caedral.AudioGenerateRequest{ Model: "caedral-voice", Input: "Welcome to Caedral.", Voice: "alloy",})client.Rerank.Create(ctx, req)
topN := 2ranked, err := client.Rerank.Create(ctx, caedral.RerankCreateRequest{ Model: "caedral-rerank", Query: "billing and subscription plans", Documents: []string{"Caedral bills by subscription", "Local gateway port 5001"}, TopN: &topN,})Errors
completion, err := client.Chat.Completions.Create(ctx, req)if err != nil { var apiErr *caedral.APIError if errors.As(err, &apiErr) { log.Printf("status=%d type=%s msg=%s", apiErr.StatusCode, apiErr.Type, apiErr.Message) } return err}