Docs/AI SDK

AI

Go SDK

Last updated April 17, 2026

Official Go client for Cencori. Idiomatic Go with context support, typed responses, and streaming.

Installation

Codetext
go get github.com/cencori/cencori-go

Basic Usage

Codetext
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

Codetext
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

Codetext
if err != nil {
    fmt.Println(err)
}

Streaming

Codetext
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.

Codetext
client, err := cencori.NewClient(
    cencori.WithAPIKey(os.Getenv("CENCORI_API_KEY")),
    cencori.WithBaseURL("https://cencori.com"),
    cencori.WithTimeout(30*time.Second),
)