githubmodels-go is a Go client library for interacting with the GitHub Models API, inspired by the OpenAI Go SDK (openai-go).
It allows you to list models, perform chat/inference completions, and supports streaming responses using your GITHUB_TOKEN for authentication.
- List available models in the GitHub Models catalog
- Create chat completions (like OpenAI’s
ChatCompletion) - Optional streaming support for real-time responses
- Supports organization-scoped endpoints
- Easy-to-use Go client interface
go get github.com/tigillo/githubmodels-gopackage main
import (
"context"
"fmt"
"os"
githubmodels "github.com/tigillo/githubmodels-go/client"
)
func main() {
token := os.Getenv("GITHUB_TOKEN")
client := githubmodels.NewClient(token)
ctx := context.Background()
// Example: list models
models, err := client.ListModels(ctx)
if err != nil {
panic(err)
}
for _, m := range models {
fmt.Println(m.ID, "-", m.Description)
}
}
resp, err := client.ChatCompletion(ctx, githubmodels.ChatRequest{
Model: "github/code-chat",
Messages: []githubmodels.Message{
{Role: "user", Content: "Write a Go function to reverse a string"},
},
})
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
The library uses the GITHUB_TOKEN environment variable by default for authentication.
Ensure your token has the required scopes:
models:readfor catalog accessmodels:executefor inference/chat completions
Contributions are welcome! Feel free to:
- Open issues for bugs or feature requests
- Submit pull requests for enhancements or fixes
- Add examples or tests