How to Use a Custom LLM with MoneyPrinterTurbo: Complete Integration Guide

Yes, MoneyPrinterTurbo supports custom LLMs through its provider abstraction layer in app/services/llm.py, allowing you to integrate any OpenAI-compatible API or build a custom client by extending the configuration and dispatch logic.

MoneyPrinterTurbo is an open-source automated video generation framework that abstracts Large Language Model access behind a configurable provider system. While it ships with native support for providers like OpenAI, Azure, and Ollama, the modular architecture in the harry0703/MoneyPrinterTurbo repository allows you to wire any custom LLM endpoint into the video generation pipeline. This integration requires modifying only two files: the configuration and the service dispatcher.

How MoneyPrinterTurbo Handles LLM Providers

The LLM abstraction resides in app/services/llm.py, where the internal helper _generate_response routes requests based on the llm_provider configuration value. At runtime, the system reads the provider setting from config.toml:

llm_provider = config.app.get("llm_provider", "openai")  # app/services/llm.py L20-L23

Based on this value, the module instantiates the appropriate client. The codebase currently supports the following provider patterns:

  • g4f: Uses g4f.ChatCompletion.create for free-model gateway access (L22-L30)
  • OpenAI-compatible APIs: Including OpenAI, Azure, Moonshot, DeepSeek, Gemini, and others using standard OpenAI client or direct requests calls (L31-L84, L92-L132, L138-L171)
  • Custom providers: Any service you define by adding a new elif block following the existing pattern

All credentials and endpoint settings are externalized to config.toml, with templates available in config.example.toml.

Step-by-Step Custom LLM Integration

1. Configure Your Provider in config.toml

Add your custom provider identifier and credentials to the configuration file. Create entries following the existing naming convention:

llm_provider = "myprovider"
myprovider_api_key = "your-api-key-here"
myprovider_base_url = "https://api.myprovider.com/v1"
myprovider_model_name = "custom-model-v1"

The application loads these values via app/config/config.py and makes them available to the service layer at runtime.

2. Extend the LLM Service Dispatcher

Open app/services/llm.py and locate the provider dispatch logic. Insert a new elif block following the pattern used for existing providers (around L31-L84):

elif llm_provider == "myprovider":
    api_key = config.app.get("myprovider_api_key")
    model_name = config.app.get("myprovider_model_name")
    base_url = config.app.get("myprovider_base_url")
    
    client = OpenAI(api_key=api_key, base_url=base_url)
    
    response = client.chat.completions.create(
        model=model_name,
        messages=messages,
        **params
    )
    return response.choices[0].message.content

This pattern aligns with the existing implementation for OpenAI-compatible endpoints, ensuring consistency in error handling and response processing.

3. Adapt Response Parsing (Optional)

If your custom LLM returns a non-standard JSON structure, modify the parsing logic where the code extracts the completion text. The default pattern expects response.choices[0].message.content. Adjust this extraction in your custom block if your API returns different field names or wrapper objects.

Code Examples for Custom LLM Integration

Direct Python Usage

Once configured, invoke the LLM functions directly from your Python scripts:

from app.services import llm

# Ensure config.toml points to your custom provider

script = llm.generate_script(
    video_subject="Quantum Computing Applications",
    language="en",
    paragraph_number=3
)
print("Generated script:", script)

terms = llm.generate_terms(
    video_subject="Quantum Computing Applications",
    video_script=script,
    amount=5
)
print("Search terms:", terms)

This works when the project root is in your PYTHONPATH, which is automatically handled when running python main.py.

HTTP API Requests

The FastAPI controllers in app/controllers/v1/llm.py expose endpoints that automatically use your configured provider. Generate a script via HTTP:

curl -X POST http://localhost:8080/v1/llm/scripts \
  -H "Content-Type: application/json" \
  -d '{
        "video_subject": "Quantum Computing Applications",
        "video_language": "en",
        "paragraph_number": 3
      }'

Expected response:

{
  "code": 200,
  "msg": "success",
  "data": {
    "video_script": "Quantum computing represents a paradigm shift..."
  }
}

To generate search terms, POST to /v1/llm/terms with the video_script included in the payload (L33-L45 in the controller).

Key Files and Architecture

File Purpose Relevant Lines
app/services/llm.py Core LLM provider dispatch and response handling L20-L23 (config reading), L31-L84 (provider logic)
app/config/config.py Configuration loader for config.toml Entire file
config.example.toml Template showing supported providers and required keys L21-L34
app/controllers/v1/llm.py FastAPI endpoints for script and term generation L18-L30 (/scripts), L33-L45 (/terms)

Summary

  • MoneyPrinterTurbo uses a provider abstraction in app/services/llm.py that reads the llm_provider value from config.toml at runtime.
  • Adding a custom LLM requires two changes: extend config.toml with your endpoint credentials and add a dispatch block in app/services/llm.py.
  • OpenAI-compatible APIs integrate easily using the existing OpenAI client pattern with custom base_url parameters.
  • FastAPI endpoints (/v1/llm/scripts and /v1/llm/terms) automatically route to your custom provider once configured.
  • Direct Python imports from app.services.llm allow scripting without HTTP overhead.

Frequently Asked Questions

Does MoneyPrinterTurbo support local LLMs like Ollama?

Yes, Ollama is supported natively. Set llm_provider = "ollama" in config.toml and configure ollama_base_url pointing to your local instance (typically http://localhost:11434/v1). The implementation follows the same OpenAI-compatible client pattern used for other custom providers.

What format should my custom LLM API endpoint return?

Your endpoint should return a JSON object compatible with the OpenAI chat completions schema. Specifically, the code expects to extract text from response.choices[0].message.content. If your API returns different field names, modify the extraction logic in your custom elif block within app/services/llm.py.

Do I need to modify the FastAPI controllers to use a custom LLM?

No. The controllers in app/controllers/v1/llm.py call llm.generate_script() and llm.generate_terms() without knowledge of the specific provider. Once you add your custom logic to app/services/llm.py and update config.toml, the REST endpoints automatically use your new provider.

Can I use the G4F free provider instead of a custom API?

Yes, set llm_provider = "g4f" to use the free-model gateway. This requires no API key and uses the g4f.ChatCompletion.create interface (L22-L30). However, for production stability or specific model requirements, a custom provider with your own API keys is recommended.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →