API Integrations in AgentForge

June 8, 2026 ยท View on GitHub

This is an advanced provider integration reference.

Use First Real Model Run before creating custom APIs.

AgentForge provides a unified interface for integrating with a variety of Large Language Model (LLM) APIs. All API integrations are built on the BaseModel class, which standardizes prompt handling, retries, logging, and parameter management. Adding a new API is as simple as subclassing BaseModel and registering your model in configuration.


Core API Integration: BaseModel

All API classes inherit from BaseModel, which provides:

  • Unified Prompt and Media Handling: Supports text, image, audio-input, and audio-output modalities when the selected provider class implements them.
  • Retry and Backoff Logic: Automatic retries for rate limits and connection errors.
  • Consistent Logging: All prompts, responses, and errors are logged.
  • Parameter Filtering: Only relevant parameters are passed to the API.

Key Methods and Attributes:

class BaseModel:
    default_retries = 3
    default_backoff = 2
    supported_modalities = {"text"}

    def __init__(self, model_name, **kwargs):
        self.model_name = model_name
        self.num_retries = kwargs.get("num_retries", self.default_retries)
        self.base_backoff = kwargs.get("base_backoff", self.default_backoff)
        self.allowed_params = None
        self.excluded_params = None

    def generate(self, model_prompt=None, *, images=None, **params):
        # Main entry point for generating responses (text and/or images)
        ...

    def _do_api_call(self, prompt, **filtered_params):
        # Subclasses must implement this method
        raise NotImplementedError

    def _process_response(self, raw_response):
        # Subclasses may override to post-process API responses
        return raw_response
  • To add image/multimodal support, set supported_modalities and implement _prepare_image_payload as needed.
  • See Vision and Multimodal Support for details.

Built-in API Integrations

AgentForge ships with the following built-in API classes. Each is configured via YAML and can be used in agents or cogs by specifying the appropriate API and model.

API ClassConfig KeyDescription
GPTopenai_apiOpenAI chat models
O1Seriesopenai_apiOpenAI reasoning-series models
STTopenai_apiOpenAI speech-to-text models
TTSopenai_apiOpenAI text-to-speech models
Codexopenai_apiOpenAI Codex via OAuth
Ollamaollama_apiOllama local LLM API
LMStudiolm_studio_apiLM Studio local LLM API
LMStudioVisionlm_studio_apiLM Studio image-capable API
OpenRouteropenrouter_apiOpenRouter API
Geminigemini_apiGoogle Gemini API
GeminiVisiongemini_apiGoogle Gemini with image support
Claudeanthropic_apiAnthropic Claude API
GroqAPIgroq_apiGroq API
LiteLLMlitellm_apiLiteLLM routing for configured endpoints
VLLMvllm_apivLLM-compatible local/server API

Adding a Custom API

  1. Create a Python module in .agentforge/custom_apis/ and subclass BaseModel.
  2. Implement _do_api_call (required) and override _process_response or _prepare_prompt as needed.
  3. Register your API in YAML under model_library.<api_key>.<ClassName>.models.<model_key>.identifier.
  4. Select your API with default_model or model_overrides using the api key and model key; AgentForge discovers the provider class from model_library.

The api_key maps to the provider module, and ClassName must be an exported class from that module. Keep the class layer in the YAML even when an API has only one class.


Example Agent Configuration

model_library:
  my_custom_api:
    MyCustomModel:
      models:
        my_model:
          identifier: provider-model-name
          params:
            temperature: 0.7
      params:
        temperature: 0.7

default_model:
  api: my_custom_api
  model: my_model

Need Help?