For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
    • Overview
    • Usage for Agents
  • TypeScript SDK
    • Overview
  • Python SDK
    • Overview
  • Go SDK
      • Analytics
      • APIKeys
      • Byok
      • Chat
      • Credits
      • Datasets
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
      • OAuth
      • Observability
      • Organization
      • Presets
      • Providers
      • Rerank
      • Beta.Responses
      • Transcriptions
      • Speech
      • VideoGeneration
      • Workspaces
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Overview
  • Available Operations
  • CreatePresetsChatCompletions
  • Example Usage
  • Parameters
  • Response
  • Errors
  • CreatePresetsMessages
  • Example Usage
  • Parameters
  • Response
  • Errors
Go SDKAPI Reference

Presets - Go SDK

Presets method reference
Was this page helpful?
Previous

Providers - Go SDK

Providers method reference
Next
Built with

The Go SDK and docs are currently in beta. Report issues on GitHub.

Overview

Presets endpoints

Available Operations

  • CreatePresetsChatCompletions - Create a preset from a chat-completions request body
  • CreatePresetsMessages - Create a preset from a messages request body

CreatePresetsChatCompletions

Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. messages, stream, prompt) are silently ignored.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/models/components"
8 "github.com/OpenRouterTeam/go-sdk/optionalnullable"
9 "log"
10)
11
12func main() {
13 ctx := context.Background()
14
15 s := openrouter.New(
16 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
17 )
18
19 res, err := s.Presets.CreatePresetsChatCompletions(ctx, "my-preset", components.ChatRequest{
20 Messages: []components.ChatMessages{
21 components.CreateChatMessagesSystem(
22 components.ChatSystemMessage{
23 Content: components.CreateChatSystemMessageContentStr(
24 "You are a helpful assistant.",
25 ),
26 Role: components.ChatSystemMessageRoleSystem,
27 },
28 ),
29 components.CreateChatMessagesUser(
30 components.ChatUserMessage{
31 Content: components.CreateChatUserMessageContentStr(
32 "Hello!",
33 ),
34 Role: components.ChatUserMessageRoleUser,
35 },
36 ),
37 },
38 Model: openrouter.Pointer("openai/gpt-5.4"),
39 Temperature: optionalnullable.From(openrouter.Pointer[float64](0.7)),
40 })
41 if err != nil {
42 log.Fatal(err)
43 }
44 if res != nil {
45 // handle response
46 }
47}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
slugstring✔️URL-safe slug identifying the preset. Created if it does not exist.my-preset
chatRequestcomponents.ChatRequest✔️N/A{"max_tokens": 150,"messages": [{"content": "You are a helpful assistant.","role": "system"},
{"content": "What is the capital of France?","role": "user"}
],
“model”: “openai/gpt-4”,
“temperature”: 0.7
}
opts[]operations.Option➖The options for this request.

Response

*components.CreatePresetFromInferenceResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.ForbiddenResponseError403application/json
sdkerrors.NotFoundResponseError404application/json
sdkerrors.ConflictResponseError409application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

CreatePresetsMessages

Creates a preset (or a new version of an existing one) from an inference request body. Only fields that overlap with the preset config are persisted; other fields (e.g. messages, stream, prompt) are silently ignored.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/models/components"
8 "log"
9)
10
11func main() {
12 ctx := context.Background()
13
14 s := openrouter.New(
15 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
16 )
17
18 res, err := s.Presets.CreatePresetsMessages(ctx, "my-preset", components.MessagesRequest{
19 MaxTokens: openrouter.Pointer[int64](1024),
20 Messages: []components.MessagesMessageParam{
21 components.MessagesMessageParam{
22 Content: components.CreateMessagesMessageParamContentUnion5Str(
23 "Hello!",
24 ),
25 Role: components.MessagesMessageParamRoleUser,
26 },
27 },
28 Model: "anthropic/claude-4.6-sonnet",
29 System: openrouter.Pointer(components.CreateSystemStr(
30 "You are a helpful assistant.",
31 )),
32 })
33 if err != nil {
34 log.Fatal(err)
35 }
36 if res != nil {
37 // handle response
38 }
39}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
slugstring✔️URL-safe slug identifying the preset. Created if it does not exist.my-preset
messagesRequestcomponents.MessagesRequest✔️N/A{"max_tokens": 1024,"messages": [{"content": "Hello, how are you?","role": "user"}
],
“model”: “anthropic/claude-4.5-sonnet-20250929”,
“temperature”: 0.7
}
opts[]operations.Option➖The options for this request.

Response

*components.CreatePresetFromInferenceResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.ForbiddenResponseError403application/json
sdkerrors.NotFoundResponseError404application/json
sdkerrors.ConflictResponseError409application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*