Integrating Artificial Intelligence (AI) with Robotic Process Automation (RPA) is transforming how organizations automate and optimize workflows. By combining the structured, rule-based automation of RPA with the cognitive power of AI, businesses can automate not just repetitive tasks, but also complex processes involving unstructured data, decision-making, and natural language understanding.
As we covered in our complete guide to business process automation with AI, this area deserves a deeper look—especially for teams ready to move beyond basic automation. In this tutorial, you’ll learn how to integrate a leading RPA tool (UiPath) with an AI service (OpenAI GPT-4 API) to build seamless, intelligent workflow automations.
Whether you’re looking to automate invoice processing, customer support, or document classification, this guide will give you the practical, step-by-step knowledge to get started.
Prerequisites
- UiPath Studio (Community or Enterprise Edition, version 2022.10 or later)
- UiPath Orchestrator account (for deploying and managing bots)
- OpenAI API Key (sign up at OpenAI Platform)
- Basic knowledge of:
- RPA concepts and UiPath Studio workflow development
- REST APIs and JSON
- Python scripting (optional, for advanced AI integration scenarios)
- Internet access (for API calls)
1. Set Up Your RPA and AI Environments
-
Install UiPath Studio
Download and install UiPath Studio from the official UiPath site. Follow the installer prompts and activate via Community or Enterprise license.
-
Sign up for OpenAI and generate an API key
Visit OpenAI Platform, create an account, and navigate toAPI Keysin your dashboard. ClickCreate new secret keyand copy the key to a safe place.
-
Test API access from your machine
Open a terminal and run:curl https://api.openai.com/v1/models \ -H "Authorization: Bearer YOUR_OPENAI_API_KEY"You should receive a JSON response listing available models (e.g.,gpt-4). If not, check your network and credentials.
2. Create a New UiPath Project
-
Launch UiPath Studio and select
Processto create a new automation project. Name itAI_RPA_Integrationand choose a suitable location.
-
In the
Manage Packagespanel, search for and install:UiPath.WebAPI.Activities(for HTTP requests)UiPath.System.Activities(should be present by default)
3. Build the RPA Workflow Skeleton
- Drag a Sequence activity onto the Main workflow.
-
Add activities for your RPA steps. For this tutorial, let’s automate the extraction and AI-based classification of text from incoming emails (a common use case).
- Get IMAP Mail Messages (retrieve emails)
- For Each (iterate through emails)
- Assign (extract email body)
- HTTP Request (send text to OpenAI API)
- Deserialize JSON (parse AI response)
- Log Message / Write Line (output result)
Your workflow should look like this:
4. Configure the HTTP Request to the AI API
-
Drag an HTTP Request activity into your workflow (inside the
For Eachloop). -
Set the properties:
- Endpoint:
https://api.openai.com/v1/chat/completions - Method:
POST - Headers:
Authorization:Bearer YOUR_OPENAI_API_KEYContent-Type:application/json
- Body: Use the following JSON template (replace
emailBodywith your variable):{ "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that classifies emails." }, { "role": "user", "content": "Classify this email: " + emailBody } ] }
In UiPath, you can use an
Assignactivity to build the JSON body dynamically:jsonBody = "{ ""model"": ""gpt-4"", ""messages"": [ {""role"": ""system"", ""content"": ""You are a helpful assistant that classifies emails.""}, {""role"": ""user"", ""content"": ""Classify this email: " + emailBody + """} ] }"Then, set the
Bodyproperty of the HTTP Request tojsonBody. - Endpoint:
5. Parse and Use the AI Response
-
After the HTTP Request, add a Deserialize JSON activity.
- Input:
response.Content(from the HTTP Request output) - Output:
aiResult(a JObject variable)
- Input:
-
Extract the AI’s classification using an
Assignactivity:classification = aiResult("choices")(0)("message")("content").ToString -
Add a Log Message or Write Line activity to display the classification:
"Email classified as: " + classification
At this point, your RPA bot fetches emails, sends them to GPT-4 for classification, and logs the result—fully automating a previously manual, knowledge-based step.
6. Deploy and Test the Automated Workflow
-
Click Run in UiPath Studio to test your workflow locally. Watch the output panel for classifications.
-
For production, publish your process to UiPath Orchestrator. In Studio, click
Publish, then deploy in Orchestrator for scheduling and monitoring.
7. (Optional) Advanced: Call Custom AI Models or Python Scripts
For specialized use cases—such as document extraction, sentiment analysis, or using a private LLM—you might want to call a custom AI model or Python script from UiPath.
-
Install Python and Required Libraries
pip install openai pandas numpy -
Create a Python script (ai_processor.py):
import sys import openai openai.api_key = 'YOUR_OPENAI_API_KEY' def classify_email(email_body): response = openai.ChatCompletion.create( model="gpt-4", messages=[ {"role": "system", "content": "You are a helpful assistant that classifies emails."}, {"role": "user", "content": f"Classify this email: {email_body}"} ] ) return response['choices'][0]['message']['content'] if __name__ == '__main__': email_body = sys.argv[1] print(classify_email(email_body)) -
In UiPath Studio, use the
Python ScopeandInvoke Python Methodactivities to call your script and process the results.
Common Issues & Troubleshooting
- API Authentication Errors: Double-check your OpenAI API key and ensure it's active. If you see HTTP 401/403 errors, regenerate the key and update your workflow.
-
Invalid JSON or Deserialization Failures: Use UiPath’s
Write Lineto output the raw API response. Validate your JSON structure using an online validator. -
Timeouts or Network Issues: Ensure your firewall/proxy allows outgoing HTTPS requests to
api.openai.com. Increase the timeout property in the HTTP Request activity if needed. -
API Rate Limits: OpenAI enforces rate limits. If you receive HTTP 429 errors, add
Delayactivities between requests or request a quota increase. - UiPath Package Conflicts: If you see package dependency errors, update all packages to the latest compatible versions.
-
Python Integration Issues: If using Python scripts, make sure the correct Python version is installed and the
Python Scopeactivity points to the right executable.
Next Steps
Congratulations! You’ve now built a working integration between AI and RPA, unlocking new levels of workflow automation. Here’s how to take your solution further:
- Explore more advanced AI use cases, such as document extraction, summarization, or natural language-driven process automation.
- Add human-in-the-loop steps for review and exception handling, especially for critical business processes.
- Monitor and measure your automation’s ROI—see Key Metrics for Measuring AI Workflow Automation ROI in 2026 for practical guidance.
- Investigate common bottlenecks in AI workflow automation and how to resolve them as you scale.
- For industry-specific examples, see our deep dives on AI-driven workflow automation in healthcare or learn how to build end-to-end contract workflows with RAG and LLMs.
For a broader perspective on use cases, challenges, and success factors, don’t miss our parent guide to business process automation with AI.
By combining the strengths of RPA and AI, you’re well on your way to building intelligent, resilient, and scalable automations for the future of work.
