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:666ghj BettaFish OpenAI Compatible LLM API

From Leeroopedia
Knowledge Sources
Domains NLP, LLMs, API_Integration
Last Updated 2026-10-08 21:30 GMT

Overview

OpenAI-compatible chat completion API access for Insight, Media, Query, Report, and Forum engines, supporting multiple LLM providers via configurable base URLs.

Description

This environment provides access to any LLM provider that exposes an OpenAI-compatible chat completion API. The BettaFish system uses the `openai` Python SDK with configurable `base_url` and `api_key` parameters, allowing each engine to connect to a different provider. Supported providers include Moonshot (Kimi), DeepSeek, Gemini (via proxy), SiliconFlow, and any OpenAI-compatible endpoint. Each engine has its own set of environment variables for independent API configuration.

Usage

Use this environment for any search, summarization, report generation, or forum moderation task that requires LLM inference. It is the mandatory prerequisite for all pipeline node implementations (search, summary, reflection, formatting, chapter generation, layout, word budget, and template selection) as well as the DeepSearchAgent orchestrator.

System Requirements

Category Requirement Notes
OS Any (Linux, macOS, Windows) Docker deployment recommended for production
Hardware CPU sufficient No GPU required — API calls are remote
Disk <1GB Only Python packages needed
Network Outbound HTTPS Required to reach LLM provider endpoints

Dependencies

System Packages

  • None required beyond Python runtime

Python Packages

  • `openai` >= 1.3.0
  • `pydantic-settings` >= 2.2.1
  • `loguru` >= 0.7.0
  • `python-dotenv` >= 1.0.0

Credentials

The following environment variables must be set in `.env`:

  • `INSIGHT_ENGINE_API_KEY`: API key for Insight Engine LLM (recommended: Moonshot/Kimi)
  • `INSIGHT_ENGINE_BASE_URL`: Base URL (default: `https://api.moonshot.cn/v1`)
  • `INSIGHT_ENGINE_MODEL_NAME`: Model name (recommended: `kimi-k2-0711-preview`)
  • `MEDIA_ENGINE_API_KEY`: API key for Media Engine LLM (recommended: Gemini via proxy)
  • `MEDIA_ENGINE_BASE_URL`: Base URL for Media Engine
  • `MEDIA_ENGINE_MODEL_NAME`: Model name (recommended: `gemini-2.5-pro`)
  • `QUERY_ENGINE_API_KEY`: API key for Query Engine LLM (recommended: DeepSeek)
  • `QUERY_ENGINE_BASE_URL`: Base URL (default: `https://api.deepseek.com`)
  • `QUERY_ENGINE_MODEL_NAME`: Model name (recommended: `deepseek-chat`)
  • `REPORT_ENGINE_API_KEY`: API key for Report Engine LLM (recommended: Gemini via proxy)
  • `REPORT_ENGINE_BASE_URL`: Base URL for Report Engine
  • `REPORT_ENGINE_MODEL_NAME`: Model name (recommended: `gemini-2.5-pro`)
  • `LLM_REQUEST_TIMEOUT`: Optional global timeout override (default: 1800s)

Quick Install

# Install required packages
pip install openai>=1.3.0 pydantic-settings>=2.2.1 loguru>=0.7.0 python-dotenv>=1.0.0

Code Evidence

LLM client initialization with API key validation from `InsightEngine/llms/base.py:34-55`:

def __init__(self, api_key: str, model_name: str, base_url: Optional[str] = None):
    if not api_key:
        raise ValueError("Insight Engine INSIGHT_ENGINE_API_KEY is required.")
    if not model_name:
        raise ValueError("Insight Engine INSIGHT_ENGINE_MODEL_NAME is required.")

    self.api_key = api_key
    self.base_url = base_url
    self.model_name = model_name
    timeout_fallback = os.getenv("LLM_REQUEST_TIMEOUT") or os.getenv("INSIGHT_ENGINE_REQUEST_TIMEOUT") or "1800"
    try:
        self.timeout = float(timeout_fallback)
    except ValueError:
        self.timeout = 1800.0

    client_kwargs: Dict[str, Any] = {
        "api_key": api_key,
        "max_retries": 0,
    }
    if base_url:
        client_kwargs["base_url"] = base_url
    self.client = OpenAI(**client_kwargs)

Configuration field definitions from `config.py:45-62`:

INSIGHT_ENGINE_API_KEY: Optional[str] = Field(None, description="Insight Agent API 密钥")
INSIGHT_ENGINE_BASE_URL: Optional[str] = Field("https://api.moonshot.cn/v1")
INSIGHT_ENGINE_MODEL_NAME: str = Field("kimi-k2-0711-preview")

MEDIA_ENGINE_API_KEY: Optional[str] = Field(None)
MEDIA_ENGINE_BASE_URL: Optional[str] = Field("https://inferera.com/v1")
MEDIA_ENGINE_MODEL_NAME: str = Field("gemini-2.5-pro")

QUERY_ENGINE_API_KEY: Optional[str] = Field(None)
QUERY_ENGINE_BASE_URL: Optional[str] = Field("https://api.deepseek.com")
QUERY_ENGINE_MODEL_NAME: str = Field("deepseek-chat")

Common Errors

Error Message Cause Solution
`ValueError: INSIGHT_ENGINE_API_KEY is required.` API key not set in `.env` Set `INSIGHT_ENGINE_API_KEY` in `.env` file
`openai.AuthenticationError` Invalid or expired API key Re-apply for API key from the provider's platform
`Timeout` after 1800s LLM provider overloaded or unreachable Increase `LLM_REQUEST_TIMEOUT` or switch provider
`ConnectionError` Network issue reaching base_url Verify `INSIGHT_ENGINE_BASE_URL` is correct and accessible

Compatibility Notes

  • Moonshot/Kimi: Recommended for Insight Engine. Apply at https://platform.moonshot.cn/
  • DeepSeek: Recommended for Query Engine and MindSpider. Apply at https://platform.deepseek.com/
  • Gemini (via proxy): Recommended for Media and Report engines. Any OpenAI-compatible proxy works.
  • SiliconFlow: Recommended for Forum Host and Keyword Optimizer. Apply at https://cloud.siliconflow.cn/
  • Timeout: Each engine supports per-engine timeout env vars (e.g. `INSIGHT_ENGINE_REQUEST_TIMEOUT`) with fallback to global `LLM_REQUEST_TIMEOUT` (default 1800s; Report Engine defaults to 3000s).

Related Pages

Page Connections

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