# Output\_pydantic llm confugration

**URL:** <https://community.crewai.com/t/output-pydantic-llm-confugration/5261>\
**Category:** General\
**Tags:** task, crewai\
**Created:** [April 10, 2025, 12:18pm UTC](https://community.crewai.com/t/output-pydantic-llm-confugration/5261 "2025-04-10T12:18:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josip\_Pavicic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/josip_pavicic/32/2419_2.png) [@Josip\_Pavicic](https://community.crewai.com/u/Josip_Pavicic)\
**Post date:** [April 10, 2025, 12:18pm UTC](https://community.crewai.com/t/output-pydantic-llm-confugration/5261/1 "2025-04-10T12:18:03Z")

</div>

I have set up an Agent with function\_call\_llm and llm. Also I passed the exact same llm objects to the crew. I have found out that there is a class `InternalInstructor` with a method `to_pydantic` that uses the same llm name as the agent llm or agent function\_calling\_llm, but never takes theri api keys resulting in an error when trying to get a pydantic response from a task:  
`crewai.utilities.converter.ConverterError: Failed to convert text into a Pydantic model due to error: litellm.AuthenticationError: AuthenticationError: OpenAIException - The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable`

Can someone help me how to pass a llm instance to be used here if possible, if not, how to atleas use the api\_key of the agent llms?

Using it from env is not an options since I want to change keys basically on each request.

---

<div class="post-metadata">

**Author:** ![Josip\_Pavicic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/josip_pavicic/32/2419_2.png) [@Josip\_Pavicic](https://community.crewai.com/u/Josip_Pavicic)\
**Post date:** [April 10, 2025, 12:43pm UTC](https://community.crewai.com/t/output-pydantic-llm-confugration/5261/2 "2025-04-10T12:43:27Z")

</div>

The soulution might be to just add in the `InternalInstructor` class in `to_pydantic` method from this

```auto
    def to_pydantic(self):
        messages = [{"role": "user", "content": self.content}]
        model = self._client.chat.completions.create(
            model=self.llm.model, response_model=self.model, messages=messages
        )
        return model

```

to this

```auto
    def to_pydantic(self):
        messages = [{"role": "user", "content": self.content}]
        model = self._client.chat.completions.create(
            model=self.llm.model, response_model=self.model, messages=messages, api_key=self.model.api_key, base_url=self.model.base_url
        )
        return model

```
