Presets

Create a preset from a messages request body

Changed on

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. Requires a read-write management key; inference API keys are rejected.

post/presets/{slug}/messages

Request

  • Base URL
    https://openrouter.ai/api/v1
  • Auth
    HTTP bearer

Path parameters

slug, string required

URL-safe slug identifying the preset. Created if it does not exist.

Example:my-preset

Query parameters

workspace_id, string uuid

Workspace to act in. Also accepted as a workspace_id field in a JSON request body. Defaults to the key's workspace for a key limited to one workspace, otherwise to the account's default workspace.

Example:750e8400-e29b-41d4-a716-446655440002

Request body

MessagesRequest required

Request schema for Anthropic Messages API endpoint

cache_control, AnthropicCacheControlDirective

Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. When set on an individual content block, it marks an explicit cache breakpoint; block-level markers also work on OpenAI models that support explicit prompt caching — OpenRouter converts them to the provider's native format.

context_management, object nullable
deferred_tools, DeferredToolsControl

Opt-in versioned router-level deferred-tool protocol. Replay assistant reasoning unchanged on continuation. The portable profile needs the catalog unchanged across a continuation; the universal profile accepts a changed catalog and, with announce_catalog_changes, tells the model about it.

fallbacks, MessagesFallbackParam[] nullable

Fallback models to try if the primary model fails or refuses, in order. Handled by OpenRouter multi-model routing rather than Anthropic server-side fallbacks; cannot be combined with models. Each entry accepts only model. Maximum of 3 entries.

max_tokens, integer
messages, MessagesMessageParam[] nullable required
metadata, object
model, string required
models, string[]
output_config, MessagesOutputConfig

Configuration for controlling output behavior. Supports the effort parameter and structured output format.

plugins, union[]

Plugins you want to enable for this request, including their settings.

provider, ProviderPreferences nullable

When multiple model providers are available, optionally indicate your routing preference.

route, 'fallback' | 'sort' | 'null' nullable

DEPRECATED Use providers.sort.partition instead. Backwards-compatible alias for providers.sort.partition. Accepts legacy values: "fallback" (maps to "model"), "sort" (maps to "none").

safeguards, AnthropicSafeguard[] nullable
service_tier, string
session_id, string

A unique identifier for grouping related requests (e.g., a conversation or agent workflow). When provided, OpenRouter uses it as the sticky routing key, routing all requests in the session to the same provider to maximize prompt cache hits. Also used for observability grouping. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters.

speed, intersection

Controls output generation speed. When set to fast, uses a higher-speed inference configuration at premium pricing. Defaults to standard when omitted.

stop_sequences, string[]
stop_server_tools_when, StopServerToolsWhenCondition[]

Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls. When a condition fires while the model is still emitting tool calls, the pending tool calls are executed and one final turn is made with tool calls disabled so the response ends with a natural-language answer instead of an unfinished tool call.

stream, boolean
system, union
temperature, number double
thinking, union
tool_choice, union
tools, union[]
top_k, integer
top_p, number double
trace, TraceConfig

Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.

user, string

A unique identifier representing your end-user, which helps distinguish between different users of your app. This allows your app to identify specific users in case of abuse reports, preventing your entire app from being affected by the actions of individual users. Maximum of 256 characters.

Example request

{
  "max_tokens": 1024,
  "messages": [
    {
      "content": "Hello, how are you?",
      "role": "user"
    }
  ],
  "model": "anthropic/claude-4.5-sonnet-20250929",
  "temperature": 0.7
}

Response

Preset created or updated successfully.

CreatePresetFromInferenceResponse required

Response containing the created preset with its designated version.

data, PresetWithDesignatedVersion required

A preset with its currently designated version.

Example response

{
  "data": {
    "created_at": "2026-04-20T10:00:00Z",
    "creator_user_id": "user_2dHFtVWx2n56w6HkM0000000000",
    "description": null,
    "designated_version": {
      "config": {
        "model": "openai/gpt-4o",
        "temperature": 0.7
      },
      "created_at": "2026-04-20T10:00:00Z",
      "creator_id": "user_2dHFtVWx2n56w6HkM0000000000",
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "preset_id": "650e8400-e29b-41d4-a716-446655440001",
      "system_prompt": "You are a helpful assistant.",
      "updated_at": "2026-04-20T10:00:00Z",
      "version": 1
    },
    "designated_version_id": "550e8400-e29b-41d4-a716-446655440000",
    "id": "650e8400-e29b-41d4-a716-446655440001",
    "name": "my-preset",
    "slug": "my-preset",
    "status": "active",
    "status_updated_at": null,
    "updated_at": "2026-04-20T10:00:00Z",
    "workspace_id": "750e8400-e29b-41d4-a716-446655440002"
  }
}

Changes

    • info

      added the new optional request property provider/options/celeris

    • info

      added the new Celeris enum value to the request property provider/ignore/items/anyOf[#/components/schemas/ProviderName]

    • info

      added the new Celeris enum value to the request property provider/only/items/anyOf[#/components/schemas/ProviderName]

    1 more change in this revision