AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Custom LLM API Keys and Model Parameters in AgentGPT to Manage Token Usage

Seah Yen Ping · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Autonomous AI agents sound magical until you check your OpenAI bill. AgentGPT, built by Reworkd, lets you deploy goal-driven autonomous agents directly in your browser. Instead of answering a single prompt, AgentGPT writes a plan, creates subtasks, executes each task sequentially, evaluates its progress, and loops until the objective is completed—or until your token balance hits zero.

At 365Finds, we appreciate the sheer velocity of AgentGPT’s execution loop, but we also know how quickly an unconstrained recursive agent turns into an expensive token furnace. Feeding an autonomous agent an unmonitored API key without configuring parameter limits is the fastest way to burn through your developer credit quota.

Here is how to configure your custom LLM API key and tune model parameters in AgentGPT to keep your autonomous runs strictly within your token budget.


1. Connecting Your Custom API Key

AgentGPT allows you to run agents on its cloud demo tier, but that tier comes with strict execution limits. Supplying your personal API key unlocks deeper execution runs, billed directly to your provider account rather than AgentGPT's servers.

On the Web Interface (agentgpt.reworkd.ai)

  1. Open AgentGPT in your browser.
  2. In the bottom-left sidebar, click the Settings gear icon.
  3. In the Settings modal, locate the API Key or Model tab.
  4. Paste your secret key into the OpenAI API Key field (formatted as sk-...).
  5. Click Save to store the key.

AgentGPT stores this key locally in your browser session or local storage, sending it with outgoing requests rather than persisting it across shared servers. When you run an agent, inference requests route directly against your provider quota.

On Self-Hosted Deployments (Docker / Local)

If you run AgentGPT locally from the GitHub repository, configure keys at the environment level to ensure persistent settings across restarts:

  1. Open your project root directory and inspect the .env file (or copy from .env.example).
  2. Populate the core provider variable:
    OPENAI_API_KEY=sk-your-openai-api-key-here
    
  3. If you route through Azure OpenAI, a self-hosted proxy, or an OpenAI-compatible local endpoint (such as LocalAI or vLLM), configure the base URL override:
    REWORKD_PLATFORM_OPENAI_API_BASE=http://localhost:8000/v1
    
  4. Restart your Docker containers (docker-compose down && docker-compose up -d) to apply the environment changes.

2. Tuning Model Parameters to Tame Token Burn

The real reason autonomous agents consume tokens so rapidly is context accumulation. Every iteration cycles through five steps: goal ingestion, subtask planning, step execution, result evaluation, and task queue rewriting. With every completed subtask, AgentGPT passes previous findings and prompt histories back into the LLM context. This compound accumulation means step five consumes far more tokens than step one.

To stop runaway consumption, tune these four parameters directly in AgentGPT's Advanced Settings or backend configuration.

Model Selection (gpt-3.5-turbo vs. gpt-4)

Inside the Settings modal, select the model assigned to your agent runs.

Temperature (Recommended: 0.0 to 0.2)

Temperature controls the randomness and variability of model outputs. While a temperature of 0.7 to 1.0 suits creative writing, high temperature is disastrous for autonomous agents.

Loop Limit / Max Loops (Recommended: 3 to 6)

The single most effective brake on token consumption is the iteration loop cap. In the web UI's advanced settings—or via NEXT_PUBLIC_MAX_LOOPS in local .env files—you can define how many iterative steps the agent is permitted to execute before terminating.

Max Tokens (Response Token Cap)

The Max Tokens parameter defines the ceiling for how many tokens the model can generate in a single response cycle.


3. Essential Guardrails Outside AgentGPT

At 365Finds, we never rely solely on an application’s front-end settings to protect our API wallet. Client-side state resets, browser cache wipes, or platform updates can occasionally revert local UI sliders to application defaults.

To protect yourself against accidental overspending:

  1. Set Hard Usage Caps in OpenAI: Navigate to platform.openai.com > Billing > Usage limits. Set a monthly soft limit for email warnings and a strict hard limit (for example, $10 or $25) where all API requests are rejected immediately if exceeded.
  2. Assign Granular Goals: Vague prompts like "Research artificial intelligence trends" force the agent into open-ended, boundless subtask generation. Bounded prompts like "List the top 3 open-source vector databases on GitHub created after 2023 with their core repository links" give the agent clear exit criteria, allowing it to shut down its loop naturally.
  3. Monitor the Provider Dashboard in Real Time: While AgentGPT displays its execution logs on-screen, the exact token tally—input context tokens plus completion tokens—is reported live on your provider's API dashboard.

OpenAI calculates billing based on cumulative prompt tokens plus completion tokens across every subtask call; in an unconstrained 10-step agent run with expanding prompt history, prompt tokens make up over 80 percent of the total billed consumption.

References