# litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable Using raw output instead

**URL:** <https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316>\
**Category:** CrewAI Community Support\
**Tags:** openai, agent, crewai\
**Created:** [November 9, 2024, 8:44pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316 "2024-11-09T20:44:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmosguy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/cmosguy/32/950_2.png) [@cmosguy](https://community.crewai.com/u/cmosguy)\
**Post date:** [November 9, 2024, 8:44pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/1 "2024-11-09T20:44:45Z")

</div>

I am getting this error message using Azure when combining the LLM using the the langchain azure chat open ai clas:

Failed to convert text into a pydantic model due to the following error: litellm.APIError: AzureException APIError - argument of type ‘NoneType’ is not iterable Using raw output instead.

The issue was also reported by someone else here:

> <https://github.com/BerriAI/litellm/issues/6581>
>
> \### What happened?
> 
> A bug happened!
> 
> \### Relevant log output
> 
> \`\`\`shell
> Failed to… convert text into a pydantic model due to the following error: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable Using raw output instead.
> \`\`\`
> 
> 
> \### Twitter / LinkedIn details
> 
> \_No response\_

---

<div class="post-metadata">

**Author:** ![alvarolj23](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/alvarolj23/32/972_2.png) [@alvarolj23](https://community.crewai.com/u/alvarolj23)\
**Post date:** [November 11, 2024, 5:50pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/2 "2024-11-11T17:50:08Z")

</div>

I also had the same problem, still couldn’t find the fix

---

<div class="post-metadata">

**Author:** ![cmosguy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/cmosguy/32/950_2.png) [@cmosguy](https://community.crewai.com/u/cmosguy)\
**Post date:** [November 13, 2024, 3:49pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/3 "2024-11-13T15:49:46Z")

</div>

I fixed it by having to do this:

```auto
os.environ["OPENAI_API_KEY"] = os.getenv("AZURE_OPENAI_KEY_openai_4o")
os.environ["AZURE_API_KEY"] = os.getenv("AZURE_OPENAI_KEY_openai_4o")
os.environ["AZURE_API_BASE"] = os.getenv("AZURE_OPENAI_ENDPOINT_openai_4o")
os.environ["AZURE_API_VERSION"] = "2024-02-01"

llm = LLM(
    model="azure/gpt-4o",
)

```

I do not understand why I cannot feed as arguments directly in LLM() instance. It is what it is… this is version of `crewai==0.79.4`

---

<div class="post-metadata">

**Author:** ![tonykipkemboi](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tonykipkemboi/32/4070_2.png) [@tonykipkemboi](https://community.crewai.com/u/tonykipkemboi)\
**Post date:** [November 13, 2024, 9:19pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/4 "2024-11-13T21:19:03Z")

</div>

You can also use the **agents.yaml** file to instantiate the model and save the **env variables** in **.env** file in root folder.

Example **.env** file:

```env
AZURE_API_KEY=your-api-key-here # Replace with KEY1 or KEY2
AZURE_API_BASE=https://example.openai.azure.com/ # Replace with your endpoint
AZURE_API_VERSION=2024-08-01-preview # API version 

```

Then modify the **agents.yaml** to include the **llm** like so:

```yaml
researcher:
  role: >
    {topic} Senior Data Researcher
  goal: >
    Uncover cutting-edge developments in {topic}
  backstory: >
    You're a seasoned researcher with a knack for uncovering the latest
    developments in {topic}. Known for your ability to find the most relevant
    information and present it in a clear and concise manner.
  llm: azure/gpt-4o-mini

reporting_analyst:
  role: >
    {topic} Reporting Analyst
  goal: >
    Create detailed reports based on {topic} data analysis and research findings
  backstory: >
    You're a meticulous analyst with a keen eye for detail. You're known for
    your ability to turn complex data into clear and concise reports, making
    it easy for others to understand and act on the information you provide.
  llm: azure/gpt-4o-mini # replace with your deployed model from Azure

```

---

<div class="post-metadata">

**Author:** ![bigilad](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/bigilad/32/935_2.png) [@bigilad](https://community.crewai.com/u/bigilad)\
**Post date:** [November 14, 2024, 9:25am UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/5 "2024-11-14T09:25:41Z")

</div>

what if i dont use yaml file?  
not everyone is using that latest configuration…  
you mentioned this is need to set in azure openai, but i took it “out of the box” didn’t do any change there.  
they are indicating different end points which is also confusing  
button line i can connect to azure openai when using crewai

---

<div class="post-metadata">

**Author:** ![tonykipkemboi](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/tonykipkemboi/32/4070_2.png) [@tonykipkemboi](https://community.crewai.com/u/tonykipkemboi)\
**Post date:** [November 14, 2024, 3:36pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/6 "2024-11-14T15:36:47Z")

</div>

Here’s an example without the YAML config.

**1. Set `env` varibales**

```bash
export AZURE_API_KEY="your-api-key"
export AZURE_API_BASE="https://your-endpoint.openai.azure.com/"
export AZURE_API_VERSION="2024-08-01-preview"

```

**2. Code**

```Python
from crewai import Agent, Task, Crew, Process, LLM
from crewai_tools import SerperDevTool
import os

# Configure the LLM to use Azure OpenAI
azure_llm = LLM(
    model="azure/gpt-4o-mini",
    api_key=os.environ.get("AZURE_API_KEY"), # Replace with KEY1 or KEY2
    base_url=os.environ.get("AZURE_API_BASE"), # example: https://example.openai.azure.com/
    api_version=os.environ.get("AZURE_API_VERSION"), # example: 2024-08-01-preview
)

# Agent definition
researcher = Agent(
    role='{topic} Senior Researcher',
    goal='Uncover groundbreaking technologies in {topic} for year 2024',
    backstory='Driven by curiosity, you explore and share the latest innovations.',
    tools=[SerperDevTool()],
    llm=azure_llm
)

# Define a research task for the Senior Researcher agent
research_task = Task(
    description='Identify the next big trend in {topic} with pros and cons.',
    expected_output='A 3-paragraph report on emerging {topic} technologies.',
    agent=researcher,
)

def main():
    # Forming the crew and kicking off the process
    crew = Crew(
        agents=[researcher],
        tasks=[research_task],
        process=Process.sequential,
        verbose=True
    )
    result = crew.kickoff(inputs={'topic': 'AI Agents'})
    print(result)

if __name__ == " __main__":
    main()

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex025/uploads/crewai/original/1X/ecda97e72f77c7100e0a761444b1c991925cc789.png) [@system](https://community.crewai.com/u/system)\
**Post date:** [November 15, 2024, 3:37pm UTC](https://community.crewai.com/t/litellm-apierror-azureexception-apierror-argument-of-type-nonetype-is-not-iterable-using-raw-output-instead/1316/7 "2024-11-15T15:37:43Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
