LINKORA
OverviewQuickstart

Model Fallbacks

Automatic failover between models

The models parameter lets you automatically try other models if the primary model's providers are down, rate-limited, or refuse to reply due to content moderation.

How it works

Provide an array of model IDs in priority order. If the first model returns an error, Linkora will automatically try the next model in the list.

import { Linkora } from '@linkora/sdk';

const linkora = new Linkora({
  apiKey: '<LINKORA_API_KEY>',
});

const response = await linkora.responses.send({
  responsesRequest: {
    models: ['~anthropic/claude-sonnet-latest', 'gryphe/mythomax-l2-13b'],
    input: 'What is the meaning of life?',
  },
});

if (!('output' in response)) {
  throw new Error('Expected a non-streaming response');
}

const message = [...response.output].reverse().find((item) => item.type === 'message');
console.log(message?.content.find((part) => part.type === 'output_text')?.text);

Fallback behavior

If the model you selected returns an error, Linkora will try to use the fallback model instead. If the fallback model is down or returns an error, Linkora will return that error.

By default, any error can trigger the use of a fallback model, including:

  • Context length validation errors
  • Moderation flags for filtered models
  • Rate-limiting
  • Downtime

Pricing

Requests are priced using the model that was ultimately used, which will be returned in the model attribute of the response body.

This applies to :free models too. If a :free model is followed by a paid model in models and Linkora falls back to the paid model, you're billed at the paid model's price. To keep a request free, list only :free models.

Using with the Anthropic Messages API

The Anthropic Messages API endpoint (/api/v1/messages) accepts the fallbacks parameter, matching the shape used by Anthropic's SDKs. Each entry names a fallback model to try in order, and the list maps to Linkora's models routing, so fallbacks trigger on the same errors listed above (rate limits, downtime, moderation refusals), not only on refusals.

Linkora handles this fallback routing itself. The fallbacks parameter does not use Anthropic's server-side fallback feature.
import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  baseURL: 'https://link-ora.net/api',
  apiKey: '<LINKORA_API_KEY>',
});

const message = await anthropic.beta.messages.create({
  model: 'anthropic/claude-sonnet-4.5',
  max_tokens: 1024,
  fallbacks: [{ model: 'anthropic/claude-opus-4.1' }],
  messages: [{ role: 'user', content: 'What is the meaning of life?' }],
});

Limitations

  • Each fallbacks entry accepts only the model field. Per-attempt overrides such as max_tokens, thinking, speed, or output_config are rejected with a 400 error.
  • fallbacks cannot be combined with the models parameter; sending both returns a 400 error.
  • fallbacks accepts at most 3 entries; longer lists return a 400 error.

Using with the OpenAI SDK

To use the models array with the OpenAI SDK, include it in the extra_body parameter. In the example below, ~openai/gpt-sol-latest will be tried first, and the models array will be tried in order as fallbacks.

from openai import OpenAI

openai_client = OpenAI(
  base_url="https://link-ora.net/api/v1",
  api_key="<LINKORA_API_KEY>",
)

response = openai_client.responses.create(
    model="~openai/gpt-sol-latest",
    extra_body={
        "models": ["~anthropic/claude-sonnet-latest", "gryphe/mythomax-l2-13b"],
    },
    input="What is the meaning of life?"
)

print(response.output_text)