OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

[Bug]: Azure Resource Not Found Error with GPT4o

Open ElderBlade opened this issue 1 week ago • 4 comments

Is there an existing issue for the same bug?

  • [x] I have checked the existing issues.

Describe the bug and reproduction steps

I'm unable to connect to my azure model, using Debian WSL (version 5.15.167.4-microsoft-standard-WSL2), getting this error:

19:50:33 - openhands:ERROR: retry_mixin.py:55 - litellm.APIError: AzureException APIError - Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}. Attempt #1 | You can customize retry values in the configuration.

I followed the instructions listed here: https://docs.all-hands.dev/modules/usage/llms/azure-llms

Here is my docker-compose.yml

services:
  openhands-app:
    image: docker.all-hands.dev/all-hands-ai/openhands:0.24
    container_name: openhands-app
    environment:
      - SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.24-nikolaik
      - LOG_ALL_EVENTS=true
      - LLM_API_VERSION="2024-08-01-preview"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ~/.openhands-state:/.openhands-state
    ports:
      - 3000:3000
    extra_hosts:
      - "host.docker.internal:host-gateway"
    pull_policy: always
    stdin_open: true
    tty: true

Here is my advanced setttings (url is redacted):

Image

I suspect OpenHands is not building the endpoint url correctly because I am able to connect just fine with request REST API, langchain, and openai AzureOpenAI package, which all use an explicit endpoint url.

Here is my working code with requests:

import requests

# Configuration
API_KEY = "my_api_key"
headers = {
    "Content-Type": "application/json",
    "api-key": API_KEY,
}

# Payload for the request
payload = {
  "messages": [
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "You are an AI assistant that helps people find information."
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
                "type": "text",
                "text": "Hi how are you"
        }
      ]
    },
  ],
  "temperature": 0.7,
  "top_p": 0.95,
  "max_tokens": 800
}

ENDPOINT = "https://xxx.openai.azure.com/openai/deployments/gpt4o/chat/completions?api-version=2024-08-01-preview"

# Send request
try:
    response = requests.post(ENDPOINT, headers=headers, json=payload)
    response.raise_for_status()  # Will raise an HTTPError if the HTTP request returned an unsuccessful status code
except requests.RequestException as e:
    raise SystemExit(f"Failed to make the request. Error: {e}")

# Handle the response as needed (e.g., print or process)
print(response.json())

Is there a way to configure OpenHands to use an endpoiont I specify?

OpenHands Installation

Docker command in README

OpenHands Version

0.24

Operating System

WSL on Windows

Logs, Errors, Screenshots, and Additional Context

No response

ElderBlade avatar Feb 17 '25 23:02 ElderBlade