@@ -11,6 +11,8 @@ It allows you to list models, perform chat/inference completions, and supports s
1111
1212- List available models in the GitHub Models catalog
1313- Create chat completions (like OpenAI’s ` ChatCompletion ` )
14+ - Rate limit tracking (headers parsed automatically)
15+ - Token usage tracking (prompt, completion, total)
1416- Optional streaming support for real-time responses
1517- Supports organization-scoped endpoints
1618- Easy-to-use Go client interface
@@ -25,15 +27,17 @@ go get github.com/tigillo/githubmodels-go
2527
2628## Usage
2729### Initialize Client
28- ```
30+ ``` go
2931package main
3032
3133import (
3234 " context"
3335 " fmt"
3436 " os"
37+ " time"
3538
3639 githubmodels " github.com/tigillo/githubmodels-go/client"
40+ " github.com/tigillo/githubmodels-go/models"
3741)
3842
3943func main () {
@@ -43,30 +47,41 @@ func main() {
4347 ctx := context.Background ()
4448
4549 // Example: list models
46- models , err := client.ListModels(ctx)
50+ modelsList , err := client.ListModels (ctx)
4751 if err != nil {
4852 panic (err)
4953 }
5054
51- for _, m := range models {
55+ for _ , m := range modelsList {
5256 fmt.Println (m.ID , " -" , m.Description )
5357 }
5458}
5559```
5660
5761### Create Chat Completion
58- ```
59- resp, err := client.ChatCompletion(ctx, githubmodels .ChatRequest{
62+ ``` go
63+ resp , err := client.ChatCompletion (ctx, models .ChatRequest {
6064 Model : " github/code-chat" ,
61- Messages: []githubmodels .Message{
65+ Messages : []models .Message {
6266 {Role: " user" , Content: " Write a Go function to reverse a string" },
6367 },
6468})
69+
70+ // Check for rate limit info even on error
71+ if resp != nil && resp.RateLimit .Limit > 0 {
72+ fmt.Printf (" Rate Limit: %d /%d remaining\n " , resp.RateLimit .Remaining , resp.RateLimit .Limit )
73+ fmt.Printf (" Resets at: %s \n " , time.Unix (resp.RateLimit .Reset , 0 ))
74+ }
75+
6576if err != nil {
6677 panic (err)
6778}
6879
6980fmt.Println (resp.Choices [0 ].Message .Content )
81+
82+ // Check token usage
83+ fmt.Printf (" Token Usage: %d prompt + %d completion = %d total\n " ,
84+ resp.Usage .PromptTokens , resp.Usage .CompletionTokens , resp.Usage .TotalTokens )
7085```
7186
7287## Environment Variables
0 commit comments