![](https://cdn.prod.website-files.com/637e5037f3ef83b76dcfc8f9/67a3934bc0ee8a74e0dc9a75_Execute%20Code%20Card.webp)
AI agents are only as powerful as the data they can access. While large language models (LLMs) generate responses from training data, they can’t retrieve real-time stock prices, process payments, or access CRM details—unless integrated with APIs.
APIs enable AI agents to access real-time data, execute logic, and trigger actions. To leverage them fully, agents need custom code.
The 'Execute Code' Card in Botpress Studio lets you write and execute JavaScript Inside a bot's workflow—seamlessly handling API calls, data processing, and bot behavior customization.
What is the Execute Code Card?
The Execute Code Card in Botpress empowers developers to run custom JavaScript within the bot's flow. It enables the following functions:
- Custom Logic Implementation: You can execute complex calculations or transform data in ways not covered by standard actions.
- Dynamic Interactions: Adjust responses based on user data or real-time computations.
- Data Integrations: Seamlessly connect with third-party services to fetch or send data.
- State Management: Access and modify the bot’s state to maintain context and personalize interactions.
- Error Handling: Implement custom error management to ensure robust operations.
The Execute Code Card features AI-generated code suggestions. Enter a prompt—like fetching API data—and the system generates JavaScript instantly. You can then review, edit, and refine it as needed, speeding up development.
Why AI Agents Need External APIs?
AI agents are only as useful as the data and services they access. While they can process inputs and generate responses, they lack real-time knowledge, transactional capabilities, and deep integrations without external APIs.
Whether you're integrating real-time data, automating workflows, or enhancing security, APIs make your bot more intelligent, responsive, and integrated.
5 Ways to Use the Execute Code Card
The Execute Code Card in Botpress Studio streamlines AI agent operations. Adding it to your workflow is simple—follow this quick tutorial:
Once added, here are key ways to leverage it in your Agentic Workflow.
1. Dynamic API Calls
Instead of using static API calls, the Execute Card lets you dynamically modify requests based on user intent, bot context, or previous conversations.
Example: Fetching custom data based on user preferences.
Prompt: A travel chatbot needs to retrieve hotel prices based on the user's destination, travel dates, and budget.
![](https://cdn.prod.website-files.com/637e5037f3ef83b76dcfc8f9/67a391aaeea335d318369d43_Feb%203%20Screenshot%20from%20CloudConvert%20(1).webp)
Note: The Execute Code Card can generate code from natural language. However, always verify the variables used in your generated code before deploying the workflow to production.
2. Post-Processing on LLM Responses
While Botpress provides built-in AI actions, sometimes you need to fine-tune responses before showing them to users—whether that’s formatting outputs, filtering certain words, or structuring data more clearly.
Example: Rewriting unstructured LLM responses into a defined table/format.
Prompt: AI fetches restaurant recommendations from an API, and I want you to format them into a clean table before displaying them.
![](https://cdn.prod.website-files.com/637e5037f3ef83b76dcfc8f9/67a391c6a06370ef604ece56_Feb%203%20Screenshot%20from%20CloudConvert%20(3).webp)
3. Rate-Limiting and Conditional Execution
Some APIs, including digital wallets, have usage limits. With the Execute Code Card, you can control user interactions by enforcing rate limits, setting fallbacks, and adding conditional logic based on API availability.
Example: Checking API Usage Before Calling It
Prompt: Check API quota from https://api.monitoring.com/usage?apikey=${workflow.userApiKey} before making a request. If fewer than 5 requests remain, return an error; otherwise, proceed. Ensure proper error handling in case of failures.
![](https://cdn.prod.website-files.com/637e5037f3ef83b76dcfc8f9/67a391df18e83fc1a5bfe182_Feb%203%20Screenshot%20from%20CloudConvert%20(4).webp)
4. Handling Permissions
If your bot needs to verify users before granting access to certain features, the card allows custom authentication flows that go beyond Botpress’s default options.
Example: Checking User Subscription Status Before Providing AI Responses
Prompt: Check a user's subscription via https://billing.example.com/user/{userId}. If on a free plan, prompt an upgrade; otherwise, allow access. Handle errors.
![](https://cdn.prod.website-files.com/637e5037f3ef83b76dcfc8f9/67a391fd3aa7d1dd3ba41493_Feb%203%20Screenshot%20from%20CloudConvert%20(6).webp)
5. Multi-Step API Chaining
Sometimes, a bot needs to combine data from multiple APIs before sending a final response. The card enables complex multi-step workflows by fetching, transforming, and passing data dynamically.
Example: Fetching Weather + Restaurant Reservation to Recommend the Best Time to Leave
Prompt: Fetch weather and traffic data for workflow.city using workflow.userApiKey. Based on conditions, return the best travel time. Handle failures.
![](https://cdn.prod.website-files.com/637e5037f3ef83b76dcfc8f9/67a392244235e9ac6c3f82d7_Feb%203%20Screenshot%20from%20CloudConvert%20(2).webp)
Seamless API Integrations for AI Agents
AI agents work best when they can tap into real-time data, automate workflows, and connect with external services.
Botpress Hub makes this seamless with pre-built API integrations, automation tools, and ready-to-use connectors—so you can focus on building, not configuring.
Start integrating powerful APIs into your bot’s workflows today—it's free.