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 OpenAI 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) and a valid OpenAI API key for Chat Completions access.

Description

This environment provides the runtime context for the OpenAILLM implementation. It requires the official `openai` Python package (>=1.55.3) which provides the `OpenAI` and `AsyncOpenAI` sync/async clients. The OpenAI Chat Completions API is the reference protocol for native tool calling, streaming, and structured output. Cost tracking is handled via the `litellm` library's `cost_per_token` utility, so `litellm` must also be installed.

Usage

Use this environment whenever you instantiate OpenAILLM with an OpenAILLMConfig. It is the mandatory prerequisite for running any agent, workflow, benchmark, or debate that is configured to use an OpenAI model (e.g., `gpt-4o-mini`, `gpt-4o`, `o1`).

System Requirements

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

Dependencies

System Packages

  • None OS-specific

Python Packages

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

Credentials

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

  • `openai_key` in OpenAILLMConfig: OpenAI API key for Chat Completions (Read/Write access to models).

Quick Install

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

Code Evidence

Model validation from `evoagentx/models/openai_model.py:36`:

if self.config.model not in get_openai_model_cost():
    raise KeyError(f"'{self.config.model}' is not a valid OpenAI model name!")

Client initialization from `evoagentx/models/openai_model.py:46-49`:

def _init_client(self, config: OpenAILLMConfig):
    return OpenAI(api_key=config.openai_key)

def _init_async_client(self, config: OpenAILLMConfig):
    return AsyncOpenAI(api_key=config.openai_key)

Native tool calling support from `evoagentx/models/openai_model.py:38-43`:

def supports_native_tool_calling(self) -> bool:
    return True

Common Errors

Error Message Cause Solution
`'xxx' is not a valid OpenAI model name!` Model name not in LiteLLM cost map Use a valid OpenAI model name (e.g., `gpt-4o-mini`)
`AuthenticationError` Invalid or missing API key Set `openai_key` in `OpenAILLMConfig`
`No usage data in stream response` Streaming without `stream_options` Set `stream_options={'include_usage': True}` (auto-set by default)

Compatibility Notes

  • Streaming cost tracking: When `stream=True`, the code auto-sets `stream_options.include_usage=True` so usage data is included for cost tracking.
  • o1 models: Use `max_completion_tokens` instead of `max_tokens` (which is deprecated for o1 series).

Related Pages

Page Connections

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