Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:ANative Lab EvoAgentX OpenRouter API

From Leeroopedia
Knowledge Sources
Domains LLM, API, NLP
Last Updated 2026-10-21 00:00 GMT

Overview

Python 3.10+ environment with the `openai` SDK (>=1.55.3), an OpenRouter API key, and network access to the OpenRouter multi-provider gateway.

Description

This environment provides the runtime context for the OpenRouterLLM implementation. OpenRouter acts as an OpenAI-compatible proxy to multiple LLM providers (Anthropic, Google Gemini, Qwen, DeepSeek, OpenAI, etc.). The implementation uses the `openai` Python SDK with a custom `base_url` pointing to `https://openrouter.ai/api/v1`. It supports native tool calling, streaming, and optional prompt caching with provider-specific cache control breakpoints.

Usage

Use this environment whenever you instantiate OpenRouterLLM with an OpenRouterConfig. It is the mandatory prerequisite for running any agent, workflow, or RAG pipeline configured to use OpenRouter as the LLM provider.

System Requirements

Category Requirement Notes
OS Linux / macOS / Windows OS Independent
Hardware Any CPU Network-bound; no GPU required
Disk Minimal Only for pip packages
Network HTTPS to openrouter.ai Required for all API calls

Dependencies

System Packages

  • None OS-specific

Python Packages

  • `openai` >= 1.55.3
  • `tenacity` (for retry logic)
  • `pydantic` >= 2.9.0

Credentials

The following must be set (via config or environment):

  • `openrouter_key` in OpenRouterConfig: OpenRouter API key for authentication.
  • `openrouter_base` in OpenRouterConfig: Base URL (default: `https://openrouter.ai/api/v1`).

Quick Install

# Install core dependencies
pip install openai>=1.55.3 tenacity pydantic>=2.9.0

Code Evidence

Client initialization with custom base URL from `evoagentx/models/openrouter_model.py:138-142`:

def _init_client(self, config: OpenRouterConfig):
    return OpenAI(api_key=config.openrouter_key, base_url=config.openrouter_base)

def _init_async_client(self, config: OpenRouterConfig):
    return AsyncOpenAI(api_key=config.openrouter_key, base_url=config.openrouter_base)

Prompt caching provider detection from `evoagentx/models/openrouter_model.py:38`:

_PAID_CACHE_WRITE_PREFIXES: Tuple[str, ...] = ("anthropic/", "google/gemini", "qwen/")

Native tool calling support from `evoagentx/models/openrouter_model.py:45-48`:

def supports_native_tool_calling(self) -> bool:
    return True

Common Errors

Error Message Cause Solution
`usage.cost not present in response` OpenRouter did not return cost data Check OpenRouter dashboard; cost recorded as 0
`AuthenticationError` Invalid or missing OpenRouter API key Set `openrouter_key` in `OpenRouterConfig`
`No usage data in stream response` Streaming without usage info OpenRouter may not always return usage in streams

Compatibility Notes

  • Prompt caching: Opt in via `enable_prompt_caching=True` on OpenRouterConfig. Only Anthropic, Gemini, and Qwen models need explicit cache control breakpoints; OpenAI, DeepSeek, Grok, and Moonshot auto-cache server-side for free.
  • Cache write premium: On paid-cache providers, a single non-repeated call costs MORE than without caching. Only enable for agent loops with repeated shared prefixes.
  • Model naming: Must use OpenRouter model prefixes (e.g., `anthropic/claude-3.5-sonnet`, `google/gemini-2.0-flash`).

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment