openrouter_box 0.0.4 copy "openrouter_box: ^0.0.4" to clipboard
openrouter_box: ^0.0.4 copied to clipboard

An OpenRouter AI provider based on ai_box.

openrouter_box #

An OpenRouter AI provider based on ai_box.

OpenRouter exposes a single OpenAI-compatible endpoint that routes to many underlying models (OpenAI, Anthropic, Google, Meta, and more). Specify a model with the provider/model form, e.g. openai/gpt-5.4-mini.

Usage #

import 'package:ai_box/ai_box.dart';
import 'package:openrouter_box/openrouter_box.dart';

Future<void> main() async {
  final ai = OpenRouter(apiKey: 'sk-or-...');

  // One-shot text generation.
  final answer = await ai.generateText(
    model: 'openai/gpt-5.4-mini',
    message: 'Say hello in one short sentence.',
  );
  print(answer);

  // Multi-turn chat.
  final res = await ai.chat(
    model: 'openai/gpt-5.4-mini',
    messages: [
      LLMContent.system('You are concise.'),
      LLMContent.user('What is the capital of Japan?'),
    ],
    maxTokens: 32,
  );
  print(res.text);
  print(res.usage); // token usage
}

Optional ranking headers #

Pass referer / title to send OpenRouter's optional HTTP-Referer / X-Title ranking headers:

final ai = OpenRouter(
  apiKey: 'sk-or-...',
  referer: 'https://your-app.example',
  title: 'Your App',
);

Models and key info #

// Rich model metadata (pricing, modalities, context length, ...).
final models = await ai.listOpenRouterModels();
final free = models.where((m) => m.isFree).map((m) => m.id).toList();

// Common ai_box model list.
final aiModels = await ai.getModels();

// API key balance / limits.
final info = await ai.getKeyInfo();
print('usage: \$${info.usage} / limit: \$${info.limit}');

// Validate the key.
final ok = await ai.validateKey();
0
likes
130
points
56
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

An OpenRouter AI provider based on ai_box.

Repository (GitHub)
View/report issues

Topics

#ai #openrouter #ai-box #llm

License

MIT (license)

Dependencies

ai_box, api_http

More

Packages that depend on openrouter_box