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

# Fast API

> Observing agents in a server environment

[//]: # "Card for video tutorial"

[//]: # "<Card title=\"REST Server + AgentOps\" icon=\"computer\" href=\"https://www.loom.com/share/cfcaaef8d4a14cc7a974843bda1076bf\">"

[//]: # "	Using agents in a REST server and observing"

[//]: # "	![thumbnail](https://cdn.loom.com/sessions/thumbnails/cfcaaef8d4a14cc7a974843bda1076bf-1713568618224-with-play.gif)"

[//]: # "</Card>"

## Adding AgentOps to Crew agents

<Steps>
  <Step title="Install the AgentOps SDK">
    <CodeGroup>
      ```bash pip theme={null}
      pip install agentops
      ```

      ```bash poetry theme={null}
      poetry add agentops
      ```
    </CodeGroup>
  </Step>

  <Step title="Install Crew with AgentOps">
    <CodeGroup>
      ```bash pip theme={null}
      pip install 'crewai[agentops]'
      ```

      ```bash poetry theme={null}
      poetry add 'crewai[agentops]'
      ```
    </CodeGroup>
  </Step>

  <Step title="Add 3 lines of code">
    1. Before calling the `Crew()` constructor in your code, call `agentops.init()`
    2. At the end of your Crew run, call `agentops.end_session("Success")`

    <CodeGroup>
      ```python python theme={null}
      import agentops

      # Beginning of program (i.e. main.py, __init__.py)
      # IMPORTANT: Must be before calling the `Crew()` constructor
      agentops.init(<INSERT YOUR API KEY HERE>)
      ...
      # End of program (e.g. main.py)
      agentops.end_session("Success") # Success|Fail|Indeterminate
      ```
    </CodeGroup>

    <Check>
      Instantiating the AgentOps client will automatically instrument Crew, meaning you will be able to see all
      of your sessions on the AgentOps Dashboard along with the full LLM chat histories, cost, token counts, etc.
    </Check>

    <Tip>
      For more features see our [Usage](/v1/usage) section.
    </Tip>
  </Step>

  <Step title="Set your API key">
    Retrieve an API Key from your Settings > [Projects & API Keys](https://app.agentops.ai/settings/projects) page.

    <Frame type="glass" caption="Settings > Projects & API Keys">
      <img height="200" src="https://mintcdn.com/agentops/FtF2hCpmQ3f-_c4T/images/api-keys.png?fit=max&auto=format&n=FtF2hCpmQ3f-_c4T&q=85&s=28891e7d710e3468d60fd3208ce3f692" data-path="images/api-keys.png" />
    </Frame>

    <Info>
      API keys are tied to individual projects.<br />
      A Default Project has been created for you, so just click Copy API Key
    </Info>

    Set this API Key in your [environment variables](/v1/usage/advanced-configuration)

    ```python .env theme={null}
    AGENTOPS_API_KEY=<YOUR API KEY>
    ```
  </Step>

  <Step title="Run your crew">
    Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your Crew! 🕵️

    <Tip>
      After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard
    </Tip>

    <div />

    <Frame type="glass" caption="Clickable link to session">
      <img height="200" src="https://github.com/AgentOps-AI/agentops/blob/main/docs/images/link-to-session.gif?raw=true" />
    </Frame>
  </Step>
</Steps>

## Special Considerations with Crew

The Crew framework is capable of determining when all tasks have been accomplished and to halt execution. AgentOps will automatically end your active session
when this determination is made. If you don't want your AgentOps session to end at this time, add an optional parameter to your `agentops.init()` call.

```python theme={null}
agentops.init(skip_auto_end_session=True)
```

## Crew + AgentOps Examples

<CardGroup cols={3}>
  <Card title="Job Posting" icon="briefcase" href="https://github.com/Agentops-AI/crewAI-examples/tree/main/job-posting" />

  <Card title="Instagram Post" icon="instagram" href="https://github.com/Agentops-AI/crewAI-examples/tree/main/instagram_post" />

  <Card title="Markdown Validator" icon="markdown" href="https://github.com/Agentops-AI/crewAI-examples/tree/main/markdown_validator" />
</CardGroup>
