Skip to main content
The Go SDK and docs are currently in beta. Report issues on GitHub.

Overview

Presets endpoints

Available Operations

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

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"github.com/OpenRouterTeam/go-sdk/optionalnullable"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Presets.CreatePresetsChatCompletions(ctx, "my-preset", components.ChatRequest{
        Messages: []components.ChatMessages{
            components.CreateChatMessagesSystem(
                components.ChatSystemMessage{
                    Content: components.CreateChatSystemMessageContentStr(
                        "You are a helpful assistant.",
                    ),
                    Role: components.ChatSystemMessageRoleSystem,
                },
            ),
            components.CreateChatMessagesUser(
                components.ChatUserMessage{
                    Content: components.CreateChatUserMessageContentStr(
                        "Hello!",
                    ),
                    Role: components.ChatUserMessageRoleUser,
                },
            ),
        },
        Model: openrouter.Pointer("openai/gpt-5.4"),
        Temperature: optionalnullable.From(openrouter.Pointer[float64](0.7)),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
slugstring:heavy_check_mark:URL-safe slug identifying the preset. Created if it does not exist.my-preset
chatRequestcomponents.ChatRequest:heavy_check_mark: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:heavy_minus_sign: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

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Presets.CreatePresetsMessages(ctx, "my-preset", components.MessagesRequest{
        MaxTokens: openrouter.Pointer[int64](1024),
        Messages: []components.MessagesMessageParam{
            components.MessagesMessageParam{
                Content: components.CreateMessagesMessageParamContentUnion5Str(
                    "Hello!",
                ),
                Role: components.MessagesMessageParamRoleUser,
            },
        },
        Model: "anthropic/claude-4.6-sonnet",
        System: openrouter.Pointer(components.CreateSystemStr(
            "You are a helpful assistant.",
        )),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
slugstring:heavy_check_mark:URL-safe slug identifying the preset. Created if it does not exist.my-preset
messagesRequestcomponents.MessagesRequest:heavy_check_mark: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:heavy_minus_sign: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*/*

CreatePresetsResponses

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

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"github.com/OpenRouterTeam/go-sdk/optionalnullable"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Presets.CreatePresetsResponses(ctx, "my-preset", components.ResponsesRequest{
        Input: openrouter.Pointer(components.CreateInputsUnionStr(
            "Hello!",
        )),
        Instructions: optionalnullable.From(openrouter.Pointer("You are a helpful assistant.")),
        Model: openrouter.Pointer("openai/gpt-5.4"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
slugstring:heavy_check_mark:URL-safe slug identifying the preset. Created if it does not exist.my-preset
responsesRequestcomponents.ResponsesRequest:heavy_check_mark:N/A{"input": [{"content": "Hello, how are you?","role": "user","type": "message"}
],
“model”: “anthropic/claude-4.5-sonnet-20250929”,
“temperature”: 0.7,
“tools”: [
{"description": "Get the current weather in a given location","name": "get_current_weather","parameters": {"properties": {"location": {"type": "string"}
},
“type”: “object”
},
“type”: “function”
}
],
“top_p”: 0.9
}
opts[]operations.Option:heavy_minus_sign: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*/*