docs/guides/api-integration.md
One of Agent Zero's most powerful capabilities is the ability to integrate external APIs on the fly without writing any code. By simply providing API documentation or code snippets, the agent can learn to use new services and remember how to use them in future conversations.
This tutorial demonstrates how to integrate Google's image generation API from Google AI Studio - but the same process works for any public API.
Agent Zero can:
This means you can add capabilities like image generation, translation services, payment processing, or any other API-based feature simply by showing the agent how it works once.
Let's walk through adding image generation capabilities using Google's Gemini API.
First, we need the code snippet that shows how to use the API.
[!TIP] Most API platforms (OpenAI, Anthropic, Replicate, etc.) provide similar "Get Code" features or have documentation with ready-to-use snippets.
Now we'll tell Agent Zero to use this code:
Agent Zero will analyze the code and understand:
google-genai package)On first run, Agent Zero will attempt to use the API but discover it needs an API key:
Agent Zero will tell you:
GEMINI_API_KEY)You have two options for storing credentials:
Option 1: Global Secrets (available to all chats and projects)
GEMINI_API_KEY=your_actual_key_hereOption 2: Project Secrets (available only within a specific project)
[!NOTE] Global secrets are ideal for APIs you use frequently across different projects. Project secrets are better for client-specific or project-specific integrations.
After configuring the API key, tell Agent Zero to proceed:
"I set the API key in secrets. Now you can use it."
Agent Zero will:
google-genai package)The agent confirms:
/root/agent_zero_logo_0.jpgAgent Zero can save useful API patterns in memory so you do not have to explain the same integration every time.
For example, it may remember:
[!IMPORTANT] Memory still needs curation. If Agent Zero keeps using an old API pattern, wrong credential name, or outdated package, open Memory and fix or remove that memory. Memory should help the agent think, not trap it in yesterday's answer.
See the Memory Guide for cleanup and curation tips.
This approach works for any external API. Common examples:
Always use code snippets from official documentation or API providers' "Get Code" features. These are:
For personal/global APIs:
SERVICE_API_KEY, SERVICE_SECRETFor project-specific APIs:
When integrating APIs for a specific project, add notes to the project instructions:
## Available APIs
This project has access to:
- **Gemini Image Generation**: Use for creating visuals and illustrations
- Credentials: GEMINI_API_KEY (configured in project secrets)
- Best for: Professional graphics, concept art, UI mockups
- **SendGrid Email**: Use for sending automated emails
- Credentials: SENDGRID_API_KEY
- Best for: Notifications, reports, customer communications
This helps the agent understand what tools are available for the current project.
For APIs you use frequently, you can have Agent Zero create reusable wrapper functions:
"Create a Python module called image_gen.py with a function generate_image(prompt, style='professional') that uses the Gemini API. Include error handling and save the image to the current project folder."
Agent Zero will:
Then in future chats:
"Use the image_gen module to create a logo", and it just works!
By showing Agent Zero a working API example, you can:
This is not magic permanence. It works best when you keep the example, secrets, project instructions, and memories tidy.