# Access OpenAI LLM through SAP Proxy Client

**URL:** <https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684>\
**Category:** CrewAI Community Support\
**Created:** [January 11, 2025, 2:07pm UTC](https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684 "2025-01-11T14:07:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gava1012](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@gava1012](https://community.crewai.com/u/gava1012)\
**Post date:** [January 11, 2025, 2:07pm UTC](https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684/1 "2025-01-11T14:07:47Z")

</div>

Hello everyone,

I am new to Crewai and trying to use an OpenAI model through the SAP proxy client. My code looks like this:

from gen\_ai\_hub.proxy.langchain.openai import ChatOpenAI  
from gen\_ai\_hub.proxy.core.proxy\_clients import get\_proxy\_client

def **init** (self):  
proxy\_client = get\_proxy\_client(‘gen-ai-hub’)  
self.llm\_model = ChatOpenAI(proxy\_model\_name=‘gpt-4o’, proxy\_client=proxy\_client, temperature=0)

@agent  
def researcher(self) → Agent:  
return Agent(  
config=self.agents\_config[‘researcher’],  
verbose=True,  
llm = self.llm\_model  
)

To get this working, I have set the following environment variables:  
AICORE\_CLIENT\_ID  
AICORE\_CLIENT\_SECRET  
AICORE\_BASE\_URL

However, when I run the code, I get an error stating that the OpenAI API key is missing. I do not have any API key since I do not have access to the OpenAI API directly.

Error: 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

Is there a way to avoid this error while using the proxy client, or am I possibly missing a configuration step? Any guidance would be greatly appreciated!

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Rakesh\_Teki](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/rakesh_teki/32/3013_2.png) [@Rakesh\_Teki](https://community.crewai.com/u/Rakesh_Teki)\
**Post date:** [March 12, 2025, 6:39am UTC](https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684/2 "2025-03-12T06:39:52Z")

</div>

Hi @gava1012 ,  
I got the same question… Let me know if you were able to find a work around of accessing the LLM through the SAP proxy client.

Thanks  
Rakesh

---

<div class="post-metadata">

**Author:** ![Pavan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/pavan/32/3448_2.png) [@Pavan](https://community.crewai.com/u/Pavan)\
**Post date:** [April 19, 2025, 7:41am UTC](https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684/3 "2025-04-19T07:41:53Z")

</div>

@Rakesh_Teki @gava1012 did the issue resolved, are you able to connect to sap proxy without using openaiapi key

---

<div class="post-metadata">

**Author:** ![Robin](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/robin/32/4460_2.png) [@Robin](https://community.crewai.com/u/Robin)\
**Post date:** [September 29, 2025, 3:07pm UTC](https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684/4 "2025-09-29T15:07:07Z")

</div>

Hi,  
I ran into the same issue. While I wasn’t able to fully resolve the root cause - namely, that CrewAI expects an OpenAI API key even when you want to use a custom LLM - I did manage to find a workaround.

CrewAI defines an abstract class called `BaseLLM`, which outlines the methods required for any (custom) llm integration. To use your own llm, you only need to implement the `call` function, ensuring it accepts the proper arguments and returns the model’s response. Here’s a minimal example:

```python
from gen_ai_hub.proxy.native.openai import chat

class MyLLM(BaseLLM):
    def call(self, messages, **args):
        kwargs = dict(model_name=self.model, messages=messages)
        response = chat.completions.create(**kwargs)
        #callbacks = args.get("callbacks", None)
        return response.choices[0].message.content

llm = MyLLM("gpt-4o-mini")

```

Next, pass your custom llm instance to the agent:

```python
agent = Agent(
    llm = llm,
    ...
)

```

Hope this helps!

---

<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:** [September 30, 2025, 3:07pm UTC](https://community.crewai.com/t/access-openai-llm-through-sap-proxy-client/2684/5 "2025-09-30T15:07:57Z")

</div>

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