dspy icon indicating copy to clipboard operation
dspy copied to clipboard

[Bug] Unable to run DSPy on AzureOpenAI

Open ajayarunachalam opened this issue 2 months ago • 7 comments

What happened?

Backing off 0.4 seconds after 1 tries calling function <function AzureOpenAI.request at 0x7fb1079549d0> with kwargs {} Backing off 1.9 seconds after 2 tries calling function <function AzureOpenAI.request at 0x7fb1079549d0> with kwargs {}

Steps to reproduce

Configure DSPy

dspy.settings.configure( lm=dspy.AzureOpenAI( api_base=AZURE_ENDPOINT, api_version=API_VERSION, api_key=API_KEY, model=DEPLOYMENT ) )

DSPy version

3.0.3

ajayarunachalam avatar Oct 03 '25 18:10 ajayarunachalam

@ajayarunachalam Thanks for reporting the issue! This doesn't look like a DSPy error though, could you try directly calling litellm.completion with your setup?

chenmoneygithub avatar Oct 04 '25 03:10 chenmoneygithub

Okay, sure. I will do that. Can you point any reference example?

ajayarunachalam avatar Oct 04 '25 12:10 ajayarunachalam

@chenmoneygithub I tried with litellm and running into this error - BadRequestError: litellm.BadRequestError: AzureException BadRequestError - Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. Just to your context: I am using GPT5 and I noticed there is an outstanding issue - https://github.com/BerriAI/litellm/issues/13432

ajayarunachalam avatar Oct 06 '25 07:10 ajayarunachalam

Can you share the full reproduction code and the litellm version?

TomeHirata avatar Oct 06 '25 09:10 TomeHirata

@ajayarunachalam are you using a deployment endpoint or response endpoint, this format is only applicable for deployment endpoint in azure.

visatenags avatar Oct 07 '25 07:10 visatenags

With the deployed endpoint you can do it like this:

dspy.configure(
    lm=dspy.LM(
        "azure/gpt-4o-mini",
        api_base="https://xxx.openai.azure.com/",
        api_key="foobar"
    )
)

nielsgl avatar Oct 13 '25 18:10 nielsgl

This is how i setup my Azureopenai into the dspy, behind the scene it uses the litellm. This is how you can configure

`import os, dspy

lm = dspy.LM( model=f'azure/{deployment}', custom_llm_provider='azure', api_key=azure_key, api_base=azure_base, api_version=azure_version, )

dspy.configure(lm=lm) print('Configured DSPy with Azure OpenAI deployment =', deployment) print('Using Azure API version =', azure_version)`

rawathemant246 avatar Oct 15 '25 05:10 rawathemant246