-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (33 loc) · 737 Bytes
/
Copy pathmain.go
File metadata and controls
40 lines (33 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"fmt"
"log"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
)
const listLimit = 10
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Models.List(ctx, nil)
if err != nil {
log.Fatal(err)
}
if res == nil {
log.Fatal("empty models response")
}
fmt.Printf("%d models (showing first %d)\n", len(res.Result.Data), listLimit)
for i, model := range res.Result.Data {
if i >= listLimit {
break
}
contextLen := "?"
if model.ContextLength != nil {
contextLen = fmt.Sprintf("%d", *model.ContextLength)
}
fmt.Printf(" %-40s ctx=%-8s %s\n", model.ID, contextLen, model.Name)
}
}