Back to Blog
Guide
OpenRouter Deployment

How to Deploy an AI Companion with OpenRouter in 2026

A production-focused guide to launching an AI companion with OpenRouter, Telegram, and edge infrastructure. Includes current pricing, routing strategy, rate-limit constraints, and a battle-tested deployment checklist.

A
Amine Afia@eth_chainId
11 min read

Most AI companion projects fail at deployment, not prompting. Developers get a demo running in one afternoon, then lose momentum when they need uptime, provider failover, budget controls, and messaging platform constraints. OpenRouter is now one of the fastest ways to solve that deployment layer because it gives you one API surface across hundreds of models while keeping provider flexibility. If your goal in 2026 is to ship a real companion that users trust daily, this guide is the practical path.

The strategy here is simple. Use OpenRouter as the model gateway, run the bot logic on an edge runtime, keep memory and analytics outside the model call path, and enforce cost ceilings from day one. If you want the shortest route, use getclaw and launch with the managed path in minutes. If you want full control, the same architecture can be run manually with Cloudflare Workers and your own persistence layer. Both approaches benefit from OpenRouter's routing and model optionality.

Before diving in, review our Get Started docs and the platform comparison for Telegram, Slack, and Discord if you are still choosing your first channel.

Why OpenRouter Is a Strong Default in 2026

OpenRouter's quickstart and API reference confirm a unified OpenAI-compatible endpoint at https://openrouter.ai/api/v1 with standardized chat completions semantics. That matters because you can swap models without rewriting your orchestration code. Their provider routing also lets you define ordered provider preference, fallback behavior, and filters such as zero data retention constraints.

The pricing model is also clear enough for production planning. OpenRouter passes through underlying model inference prices, then applies platform fees at the account level. Current public docs show a 5.5% fee on pay-as-you-go credit purchases, plus BYOK terms where the first 1M BYOK requests each month are free and usage above that carries a 5% fee. This is a better tradeoff than hard vendor lock-in for most companion products because you preserve model portability.

You should still choose models intentionally. OpenRouter is a gateway, not a quality guarantee. Model and provider selection determine latency, cost, and output reliability. Treat routing as part of product design, not just infrastructure.

Reference Architecture for a Production Companion

A stable companion stack has four layers:

  1. Channel Layer: Telegram webhook receives user messages and delivery callbacks.
  2. Runtime Layer: Edge function validates updates, loads memory, calls OpenRouter, and sends responses.
  3. State Layer: Conversation summaries, user profile fields, and feature flags in durable storage.
  4. Control Layer: Budget limits, rate limits, and routing policies for model and provider choice.

This design keeps the hot path minimal. Every extra network hop in your webhook handler creates more 429 and timeout risk under burst load. Keep it lean, then add asynchronous jobs for analytics or long-running enrichment.

Step 1: Set a Cost Envelope Before You Write Code

Start with a target cost per conversation and back into model choices. If you skip this step, your companion will eventually get popular and then become financially painful. Use current public rates from provider pricing pages and calculate a realistic blended cost.

ModelInput / 1M tokensOutput / 1M tokensOperational Role
OpenAI GPT-5 mini$0.25$2.00High-volume default chat and intent routing
OpenAI GPT-5.2$1.75$14.00Escalations and difficult reasoning turns
Anthropic Claude Sonnet 4$3.00$15.00Long-form guidance and nuanced support

These numbers come from current provider pricing pages. OpenAI also publishes cached-input discounts for supported models, and Anthropic documents prompt caching and batch discounts. For companion workloads with repeated system instructions, caching is often your easiest immediate margin win.

Budget for OpenRouter fees explicitly. If you are using OpenRouter credits, include the platform fee in your monthly budget model. If you are on BYOK, remember the fee waiver only covers the first 1M BYOK requests each month. Plan above that threshold if your bot is consumer facing.

Step 2: Create the OpenRouter Integration Correctly

Use the OpenAI SDK or raw fetch. Both are valid because OpenRouter mirrors the chat completions shape. Keep your initial implementation boring and observable. Include request IDs, latency timers, and token usage logging from the response object.

import OpenAI from "openai";

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

export async function generateReply(input: string, memory: string) {
  const completion = await client.chat.completions.create({
    model: "openai/gpt-5-mini",
    messages: [
      { role: "system", content: "You are a concise AI companion for productivity." },
      { role: "system", content: `Conversation memory: ${memory}` },
      { role: "user", content: input },
    ],
    temperature: 0.4,
  });

  return completion.choices[0]?.message?.content ?? "I could not generate a reply.";
}

Next, query key status via GET /api/v1/key to monitor credit limits and usage counters. OpenRouter's limits reference documents free-tier constraints, including free-model request caps and per-minute limits. You should poll this endpoint and alert before your balance becomes a production incident.

Step 3: Add Provider Routing and Fallbacks

The biggest deployment mistake is hardcoding one provider path and hoping it stays healthy. Use OpenRouter's provider object to define preferred order and fallback behavior. You can also enforce parameter compatibility and data policies.

const completion = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4",
  messages,
  provider: {
    order: ["anthropic", "google-vertex"],
    allow_fallbacks: true,
    require_parameters: true,
    data_collection: "deny",
    zdr: true
  }
});

If you run BYOK, configure key priority intentionally. OpenRouter BYOK docs note that your BYOK endpoint can take priority even when provider ordering is specified. Validate your effective routing path in staging so billing and reliability match expectations.

Step 4: Respect Telegram Delivery Constraints

Companion quality is not only model quality. Telegram transport limits shape your user experience as much as prompt design. Telegram Bot API documentation and FAQ pages publish practical message throughput constraints you must design around.

ConstraintCurrent LimitDesign Impact
Single chat send rateAbout 1 message per secondQueue per-user replies and avoid burst loops
Group send rate20 messages per minuteBatch moderation notices and summarize updates
Global broadcast default30 messages per secondUse fanout queues for announcements
Paid broadcastsUp to 1000 messages per second at 0.1 Stars per message above free quotaUse only for time-sensitive campaigns

Always treat 429 as a first-class path. Implement exponential backoff with jitter, preserve idempotency keys, and surface delivery lag metrics in your dashboard. Users forgive occasional delays. They do not forgive duplicate spam and silent drops.

Step 5: Choose a Runtime That Matches Real Traffic

Cloudflare Workers remains a strong runtime for companion webhooks because the free plan includes 100,000 requests per day and 10 ms CPU per invocation, with paid usage scaling beyond that. Workers limits also continue to evolve. In February 2026, Cloudflare removed the old 1000 subrequest ceiling for paid plans and moved to a higher configurable model. This matters for agentic workflows with multiple tool calls.

If you are building this stack manually, you still need to own secret management, retries, memory schema evolution, and deployment rollbacks. If you want to skip that operational burden, getclaw gives you the same architecture with managed deployment, logs, and simpler model configuration. That is why many teams use getclaw as the launch path and only go full custom when they truly need bespoke infrastructure behavior.

DIY Stack vs getclaw for OpenRouter Companions

DimensionDIY OpenRouter + Workersgetclaw + OpenRouter
Initial launch speedDays to weeksMinutes to hours
Routing controlFull manual controlConfig-first with practical defaults
Ops overheadHigh, you own monitoring and incident responseLow, managed runtime and tooling
Team fitInfra-heavy engineering teamsProduct-focused builders and lean teams

Production Checklist You Should Not Skip

  • Use two model tiers: a cheap default model and a premium escalation model.
  • Track token economics: store prompt, completion, and cached token metrics per message.
  • Cap blast radius: configure key credit limits and alerting via the OpenRouter key endpoint.
  • Implement queue-based outbound sends: never write Telegram fanout inline in webhook handlers.
  • Persist compact memory: summarize long threads instead of replaying full transcripts every turn.
  • Test failure paths: simulate provider outage, timeout, and 429 behavior before launch.
  • Add regression prompts: keep a fixed set of user scenarios to evaluate model changes.

If you want a practical baseline for prompt structure before your first release, use our system prompt guide. It helps reduce token waste and improves response consistency immediately.

A Realistic Cost Walkthrough

Assume 20,000 daily messages, average 450 input tokens and 120 output tokens, mostly routed to GPT-5 mini with 15% escalation to Claude Sonnet 4. At that volume, model spend dominates. Runtime cost is typically secondary unless your code path is inefficient or your state layer is over-queried.

The important insight is margin stability, not just monthly total. Routing discipline and cached prompt strategy can reduce spend volatility when usage spikes. If your companion is tied to marketing campaigns or product launches, those spikes are guaranteed. Build for predictable per-message cost now so growth does not break your budget later.

Conclusion

Deploying an AI companion with OpenRouter in 2026 is straightforward if you treat routing, limits, and cost controls as core product requirements. Start with a clear envelope, implement routing policies early, and respect Telegram transport constraints. Then choose your operational model: fully DIY or a managed path on getclaw.

For implementation details, read the API reference, the Telegram deployment tutorial, and our Claude vs GPT guide for bot builders. If speed matters and you want less infrastructure drag, getclaw remains the simplest AI-first path from idea to production companion.

Sources

Filed Under
OpenRouter
AI Companion
Telegram Bot
BYOK
Cloudflare Workers
Deployment

Deploy your AI assistant

Create an autonomous AI assistant in minutes.