Skip to main content

Overview

Presets endpoints

Available Operations

List

Lists all presets for the authenticated user, ordered by most recently updated first.

Example Usage

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"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.List(ctx, optionalnullable.From[int64](nil), nil)
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
opts[]operations.Option:heavy_minus_sign:The options for this request.

Response

*operations.ListPresetsResponse, error

Errors

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

Get

Retrieves a preset by its slug with its currently designated version inline.

Example Usage

package main

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

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

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

    res, err := s.Presets.Get(ctx, "my-preset")
    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.my-preset
opts[]operations.Option:heavy_minus_sign:The options for this request.

Response

*components.GetPresetResponse, error

Errors

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

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*/*

ListVersions

Lists all versions of a preset, ordered by version number ascending (oldest first).

Example Usage

package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"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.ListVersions(ctx, "my-preset", optionalnullable.From[int64](nil), nil)
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
slugstring:heavy_check_mark:URL-safe slug identifying the preset.my-preset
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
opts[]operations.Option:heavy_minus_sign:The options for this request.

Response

*operations.ListPresetVersionsResponse, error

Errors

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

GetVersion

Retrieves a specific version of a preset by its slug and version number.

Example Usage

package main

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

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

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

    res, err := s.Presets.GetVersion(ctx, "my-preset", "1")
    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.my-preset
versionstring:heavy_check_mark:Version number of the preset.1
opts[]operations.Option:heavy_minus_sign:The options for this request.

Response

*components.GetPresetVersionResponse, error

Errors

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