> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CrewAI framework integration

> Connect CrewAI to Orq.ai's AI Router for complete observability, built-in reliability, and access to 300+ LLMs across 20+ providers.

<CardGroup cols={2}>
  <Card title="AI Router" icon="arrow-right-arrow-left" href="#ai-router">
    Route your LLM calls through the AI Router with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.
  </Card>

  <Card title="Observability" icon="chart-line" href="#observability">
    Instrument your code with OpenTelemetry to capture traces, logs, and metrics for every LLM call, agent step, and tool use.
  </Card>
</CardGroup>

## AI Router

### Overview

CrewAI is a framework for orchestrating multi-agent teams with role-based agents, hierarchical task management, and collaborative AI workflows. By connecting CrewAI to Orq.ai's AI Router, you get access to 300+ models for your agent crews with a single configuration change.

### Key Benefits

Orq.ai's AI Router enhances your CrewAI applications with:

<CardGroup cols={2}>
  <Card title="Complete Observability" icon="chart-line">
    Track every agent task, tool use, and crew interaction with detailed traces
  </Card>

  <Card title="Built-in Reliability" icon="shield-check">
    Automatic fallbacks, retries, and load balancing for production resilience
  </Card>

  <Card title="Cost Optimization" icon="chart-pie">
    Real-time cost tracking and spend management across all your AI operations
  </Card>

  <Card title="Multi-Provider Access" icon="cubes">
    Access 300+ LLMs and 20+ providers through a single, unified integration
  </Card>
</CardGroup>

### Prerequisites

Before integrating CrewAI with Orq.ai, ensure you have:

* An Orq.ai account and [API Key](/docs/administer/api-keys)
* Python 3.10 or higher

<Info>
  To setup your API key, see [API keys & Endpoints](/docs/administer/api-keys).
</Info>

### Installation

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install crewai
```

### Configuration

Configure CrewAI to use Orq.ai's AI Router via the `LLM` class with a custom `base_url`:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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 Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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], tracing=False)
result = crew.kickoff()
print(result)
```

### Multi-Agent Crew

Orchestrate multiple agents with specialized roles:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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], tracing=False)
result = crew.kickoff()
print(result)
```

### Model Selection

With **Orq.ai**, you can use any supported model from 20+ providers:

<Note>
  Always prefix model IDs with `openai/` when using **CrewAI** with the **AI Router**. 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.
</Note>

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from crewai import LLM
import os

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

# Use Gemini
gemini_llm = LLM(
    model="openai/google/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",
)
```

## Observability

### Getting Started

CrewAI enables powerful multi-agent coordination for complex AI workflows. Tracing CrewAI with Orq.ai provides comprehensive insights into agent interactions, task execution, tool usage, and crew performance to optimize your multi-agent systems.

### Prerequisites

Before you begin, ensure you have:

* An Orq.ai account and [API Key](/docs/administer/api-keys)
* CrewAI installed in your project
* Python 3.8+
* OpenAI API key (or other LLM provider credentials)

### Install Dependencies

<CodeGroup>
  ```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  # OpenTelemetry, crewai, openinference
  pip install crewai openinference-instrumentation-crewai
  pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http

  # LLM providers
  pip install openai anthropic

  # Optional: Advanced tools and integrations
  pip install crewai-tools
  ```
</CodeGroup>

### Configure Orq.ai

Set up your environment variables to connect to Orq.ai's OpenTelemetry collector:

**Unix/Linux/macOS:**

<CodeGroup>
  ```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.orq.ai/v2/otel"
  export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <ORQ_API_KEY>"
  export OTEL_RESOURCE_ATTRIBUTES="service.name=crewai-app,service.version=1.0.0"
  export OPENAI_API_KEY="<YOUR_OPENAI_API_KEY>"
  ```
</CodeGroup>

**Windows (PowerShell):**

<CodeGroup>
  ```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  $env:OTEL_EXPORTER_OTLP_ENDPOINT = "https://api.orq.ai/v2/otel"
  $env:OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Bearer <ORQ_API_KEY>"
  $env:OTEL_RESOURCE_ATTRIBUTES = "service.name=crewai-app,service.version=1.0.0"
  $env:OPENAI_API_KEY = "<YOUR_OPENAI_API_KEY>"
  ```
</CodeGroup>

**Using .env file:**

<CodeGroup>
  ```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
  OTEL_EXPORTER_OTLP_ENDPOINT=https://api.orq.ai/v2/otel
  OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer <ORQ_API_KEY>
  OTEL_RESOURCE_ATTRIBUTES=service.name=crewai-app,service.version=1.0.0
  OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
  ```
</CodeGroup>

### Integrations Example

<Info>
  We'll be using OpenInference as TracerProvider with CrewAI
</Info>

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from openinference.instrumentation.crewai import CrewAIInstrumentor
  from openinference.instrumentation.openai import OpenAIInstrumentor
  from opentelemetry import trace
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
  from opentelemetry.sdk import trace as trace_sdk
  from opentelemetry.sdk.trace.export import BatchSpanProcessor
  from crewai import Agent, Task, Crew

  # Initialize OpenTelemetry
  tracer_provider = trace_sdk.TracerProvider()
  tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(
      endpoint="https://api.orq.ai/v2/otel/v1/traces",
      headers={"Authorization": "Bearer <ORQ_API_KEY>"}
  )))
  trace.set_tracer_provider(tracer_provider)

  # Instrument CrewAI
  CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
  OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)

  # Your CrewAI code is automatically traced
  researcher = Agent(
      role='Market Research Analyst',
      goal='Gather comprehensive market data and trends',
      backstory='Expert in analyzing market dynamics and consumer behavior'
  )

  task = Task(
      description='Research the latest trends in AI and machine learning',
      agent=researcher,
      expected_output='Comprehensive report on AI and ML trens with key insights and recommendations'
  )

  crew = Crew(agents=[researcher], tasks=[task], tracing=False)
  result = crew.kickoff()
  ```
</CodeGroup>

### View Traces

<Frame caption="Traces from your CrewAI execution will be visible within the Traces menu in your orq.ai studio.">
  <img src="https://mintcdn.com/orqai/XbJWQ7lqn4sIVHea/images/docs/da76c6c7c00274d05f560db4306b291a0437135937b7711cdce2f0ab012ee5ea-Screenshot_2025-10-20_at_11.37.23.png?fit=max&auto=format&n=XbJWQ7lqn4sIVHea&q=85&s=3396c8b9da6047f822754976d7ec51a8" alt="Traces from your CrewAI execution will be visible within the Traces menu in your orq.ai studio." width="1073" height="805" data-path="images/docs/da76c6c7c00274d05f560db4306b291a0437135937b7711cdce2f0ab012ee5ea-Screenshot_2025-10-20_at_11.37.23.png" />

  [Traces](/docs/observability/traces)
</Frame>

## Evaluations & Experiments

Once your agents are running, use **Evaluatorq** to score outputs across a dataset and **Experiments** to compare configurations side-by-side.

<CardGroup cols={2}>
  <Card title="Run Evaluations with Evaluatorq" icon="flask" href="/docs/evaluators/build#evaluatorq">
    Run parallel evaluations across your agents and compare results.
  </Card>

  <Card title="Run Experiments via the API" icon="flask-vial" href="/docs/experiments/api">
    Compare agent configurations and view results in the AI Studio.
  </Card>
</CardGroup>
