-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdoc.go
More file actions
48 lines (35 loc) · 1.36 KB
/
Copy pathdoc.go
File metadata and controls
48 lines (35 loc) · 1.36 KB
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
41
42
43
44
45
46
47
48
/*
Package openrouter provides an OpenAI-compatible API client with additional OpenRouter features.
The OpenRouter API offers OpenAI-compatible endpoints with additional features like model routing,
provider selection, and unified billing.
This SDK is in beta. Pin to a specific module version to avoid unexpected breaking changes:
go get github.com/OpenRouterTeam/go-sdk@v0.8.22
For full API documentation, visit: https://openrouter.ai/docs/client-sdks/go/overview
Authentication:
import (
"context"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
)
sdk := openrouter.New(
openrouter.WithSecurity("your-api-key"),
)
The API key can also be read from the OPENROUTER_API_KEY environment variable when using [New]
without [WithSecurity].
For license information, see the LICENSE file at the repository root.
Examples:
Basic chat completion:
ctx := context.Background()
res, err := sdk.Chat.Send(ctx, components.ChatRequest{
Model: openrouter.Pointer("openai/gpt-4o"),
Messages: []components.ChatMessages{
components.CreateChatMessagesUser(
components.ChatUserMessage{
Role: components.ChatUserMessageRoleUser,
Content: components.CreateChatUserMessageContentStr("Hello!"),
},
),
},
}, nil)
*/
package openrouter