Compatible Gateways

OpenRouter

Use OpenRouter as an OpenAI-compatible gateway and inspect available models.

OpenRouter exposes an OpenAI-compatible API at https://openrouter.ai/api/v1. In Anvia, use OpenAIClient with that baseUrl, then pass OpenRouter model ids to completionModel(...).

Create the Client

import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";

const client = new OpenAIClient({
  baseUrl: "https://openrouter.ai/api/v1",
  apiKey: process.env.OPENROUTER_API_KEY,
});

const model = client.completionModel("openai/gpt-5.5");

const agent = new AgentBuilder("support", model)
  .instructions("Answer support questions clearly.")
  .build();

const response = await agent.prompt("Hello!").send();

console.log(response.output);

baseUrl makes Anvia use the OpenAI-compatible chat completion adapter. The model id is the OpenRouter id, not an Anvia-specific alias.

Get the Model List

OpenRouter's models API returns the model ids and metadata you can use when choosing a model. Because the client was created with baseUrl, listModels() calls OpenRouter's /models endpoint.

const models = await client.listModels();

console.table(
  models.data.map((model) => ({
    id: model.id,
    name: model.name,
    contextLength: model.contextLength,
  })),
);

Use the id field directly:

const model = client.completionModel("anthropic/claude-opus-4.6");

Filter Models

OpenRouter supports query parameters on the models endpoint. Use them when your UI or configuration screen only needs models with specific capabilities.

listModels() does not expose gateway-specific filters. Use fetch directly when you need OpenRouter query parameters.

const response = await fetch(
  "https://openrouter.ai/api/v1/models?supported_parameters=tools",
  {
    headers: {
      Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
    },
  },
);

You can also filter by output modality:

const response = await fetch(
  "https://openrouter.ai/api/v1/models?output_modalities=text",
  {
    headers: {
      Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
    },
  },
);

Notes

  • OpenRouter API keys are passed as bearer tokens.
  • Optional OpenRouter headers such as HTTP-Referer and X-Title are for app attribution on OpenRouter. Add them in your own HTTP layer or OpenAI SDK client when needed.
  • Model capabilities still vary by upstream model and route. Check OpenRouter model metadata before enabling tools, reasoning, structured output, images, or other model-specific behavior.

For OpenRouter's current API details, see the OpenRouter quickstart and models API reference.