Louis_Frolio
Databricks Employee
Databricks Employee

Hello @jAAmes_bentley , I did some digging and here is what I found.

Root Cause: Unsupported Temperature Parameter

The primary issue with your `AI_QUERY` call to o1-mini is the temperature parameter. OpenAI's o1-series models (o1, o1-mini, o1-preview, o3-mini) do not support the `temperature` parameter at all—even when set to the default value of 1. When you include `modelParameters => named_struct('temperature', 1)`, it causes the OpenAI API to reject the request, resulting in the misleading "Invalid prompt" error.

The o1 reasoning models also don't support other sampling parameters like `top_p`, `presence_penalty`, `frequency_penalty`, and several others that work with GPT-4o and earlier models.

Solution for o1-mini

Remove the `modelParameters` argument entirely when calling o1-mini:

```python
spark.sql("""
SELECT AI_QUERY(
'o1-mini',
request => 'What is the capital of United Kingdom?',
failOnError => false
)
""").display()
```

This should resolve the intermittent 400 errors you're experiencing.

Embedding Model Issue

The `text-embedding-ada-002` error is separate and indicates a response parsing issue rather than a parameter problem. The error `Missing valid errors field in remote response` suggests that Databricks `AI_QUERY` is receiving an unexpected response format from the embedding endpoint.

For embeddings through `AI_QUERY`, ensure your endpoint configuration matches the expected response schema. Since the model works in the ML playground, this may be a temporary API integration issue between Databricks and Azure OpenAI that emerged in the March 2025 release timeframe.

Why It Works in ML Playground

The ML playground likely handles model-specific parameter restrictions automatically, stripping unsupported parameters before sending requests to OpenAI. The `AI_QUERY` function passes parameters directly, requiring you to manually ensure compatibility with each model's constraints.

Hope this helps, Louis.