AI
Go SDK
Last updated April 17, 2026
Official Go client for Cencori. Idiomatic Go with context support, typed responses, and streaming.
Installation
go get github.com/cencori/cencori-goBasic Usage
package main
import (
"context"
"fmt"
"os"
"github.com/cencori/cencori-go"
)
func main() {
client, err := cencori.NewClient(
cencori.WithAPIKey(os.Getenv("CENCORI_API_KEY")),
)
if err != nil {
panic(err)
}
resp, err := client.Chat.Create(context.TODO(), cencori.ChatParams{
Model: "gpt-4o",
Messages: []cencori.Message{
{Role: "user", Content: "Hello from Go!"},
},
})
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}Context And Cancellation
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
resp, err := client.Chat.Create(ctx, params)
if err != nil {
// Handle error
}Error Handling
if err != nil {
fmt.Println(err)
}Streaming
stream, err := client.Chat.Stream(context.TODO(), cencori.ChatParams{
Model: "gpt-4o",
Messages: []cencori.Message{
{Role: "user", Content: "Tell me a story"},
},
})
if err != nil {
panic(err)
}
for chunk := range stream {
if chunk.Err != nil {
panic(chunk.Err)
}
if len(chunk.Choices) > 0 {
fmt.Print(chunk.Choices[0].Delta.Content)
}
}Configuration
You can override the base URL or timeout if needed.
client, err := cencori.NewClient(
cencori.WithAPIKey(os.Getenv("CENCORI_API_KEY")),
cencori.WithBaseURL("https://cencori.com"),
cencori.WithTimeout(30*time.Second),
)