Skip to main content

AI Gateway

Overview

CrewAI is a framework for orchestrating multi-agent teams with role-based agents, hierarchical task management, and collaborative AI workflows. Connecting CrewAI to Orq.ai’s AI Gateway provides access to 300+ models with a single configuration change.

Key Benefits

Orq.ai’s AI Gateway enhances CrewAI applications with:

Complete Observability

Track every agent task, tool use, and crew interaction with detailed traces

Built-in Reliability

Automatic fallbacks, retries, and load balancing for production resilience

Cost Optimization

Real-time cost tracking and spend management across all AI operations

Multi-Provider Access

Access 300+ LLMs and 20+ providers through a single, unified integration

Prerequisites

Before integrating CrewAI with Orq.ai, ensure the following are in place:
  • An Orq.ai account and API Key
  • Python 3.10 or higher
To set up an API key, see API keys & Endpoints.

Installation

pip install crewai

Configuration

Configure CrewAI to use Orq.ai’s AI Gateway via the LLM class with a custom base_url:
Python
from crewai import LLM
import os

llm = LLM(
    model="openai/gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router",
)
base_url: https://api.orq.ai/v3/router

Basic Agent Example

Python
from crewai import Agent, Task, Crew, LLM
import os

llm = LLM(
    model="openai/gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router",
)

researcher = Agent(
    role="Research Analyst",
    goal="Provide accurate and concise information on topics",
    backstory="Expert analyst with broad knowledge across many domains.",
    llm=llm,
)

task = Task(
    description="In two sentences, explain what machine learning is.",
    agent=researcher,
    expected_output="A concise two-sentence explanation of machine learning.",
)

crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
print(result)

Multi-Agent Crew

Orchestrate multiple agents with specialized roles:
Python
from crewai import Agent, Task, Crew, LLM
import os

llm = LLM(
    model="openai/gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router",
)

researcher = Agent(
    role="Research Analyst",
    goal="Research topics and gather key facts",
    backstory="Expert at finding and summarizing information.",
    llm=llm,
)

writer = Agent(
    role="Content Writer",
    goal="Write clear, engaging content",
    backstory="Skilled at turning research into readable content.",
    llm=llm,
)

research_task = Task(
    description="Research the key benefits of renewable energy in 3 bullet points.",
    agent=researcher,
    expected_output="3 bullet points about renewable energy benefits.",
)

write_task = Task(
    description="Write a one-paragraph summary based on the research.",
    agent=writer,
    expected_output="A single paragraph summarizing renewable energy benefits.",
    context=[research_task],
)

crew = Crew(agents=[researcher, writer], tasks=[research_task, write_task])
result = crew.kickoff()
print(result)

Model Selection

With Orq.ai, any supported model from 20+ providers can be used:
Always prefix model IDs with openai/ when using CrewAI with the AI Gateway. Without it, CrewAI may route the request through a matching native provider client (notably its built-in Google client) that ignores base_url, producing misleading errors like “API key not valid”. The openai/ prefix forces the OpenAI-compatible code path, which respects base_url for every provider.
Python
from crewai import LLM
import os

# Use Claude
claude_llm = LLM(
    model="openai/anthropic/claude-sonnet-4-6",
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router",
)

# Use Gemini
gemini_llm = LLM(
    model="openai/google-ai/gemini-2.5-flash",
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router",
)

# Use Groq
groq_llm = LLM(
    model="openai/groq/llama-3.3-70b-versatile",
    api_key=os.getenv("ORQ_API_KEY"),
    base_url="https://api.orq.ai/v3/router",
)