{"record":{"id":"31594ce901b9c5e5","repo":"roboflow/supervision","slug":"azure-api-returned-an-error-azure-result-error","errorCode":null,"errorMessage":"Azure API returned an error {azure_result['error']['message']}","messagePattern":"Azure API returned an error (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":1022,"sourceCode":"\n            endpoint = \"https://.cognitiveservices.azure.com/\"\n            subscription_key = \"\"\n\n            headers = {\n                \"Content-Type\": \"application/octet-stream\",\n                \"Ocp-Apim-Subscription-Key\": subscription_key\n             }\n\n            response = requests.post(endpoint,\n                headers=self.headers,\n                data=image\n             ).json()\n\n            detections = sv.Detections.from_azure_analyze_image(response)\n            ```\n        \"\"\"\n        if \"error\" in azure_result:\n            raise ValueError(\n                f\"Azure API returned an error {azure_result['error']['message']}\"\n            )\n\n        xyxy, confidences, class_ids = [], [], []\n\n        is_dynamic_mapping = class_map is None\n        if class_map is None:\n            class_map = {}\n\n        inverted_map: dict[str, int] = {value: key for key, value in class_map.items()}\n\n        for detection in azure_result[\"objectsResult\"][\"values\"]:\n            bbox = detection[\"boundingBox\"]\n\n            tags = detection[\"tags\"]\n\n            x0 = bbox[\"x\"]\n            y0 = bbox[\"y\"]","sourceCodeStart":1004,"sourceCodeEnd":1040,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L1004-L1040","documentation":"Detections.from_azure_analyze_image parses the JSON body returned by the Azure AI Vision Image Analysis 4.0 API. Azure reports failures inside the 200-response body as an 'error' object rather than an HTTP error status, so supervision checks for that key and re-raises the message as a ValueError.","triggerScenarios":"Calling from_azure_analyze_image(azure_result) where the dict contains an 'error' key — typically because the requests.post to the endpoint returned an auth failure, quota exhaustion, wrong endpoint URL, or invalid request payload, and .json() of that response was passed through.","commonSituations":"Wrong or expired Ocp-Apim-Subscription-Key; using a free-tier key against a feature not enabled; wrong endpoint region; forgetting that the response must come from the analyze endpoint with 'objects' output; Azure returning 401/429 bodies.","solutions":["Inspect azure_result['error'] fully (code + message) — it states the real cause (auth, quota, bad request).","Verify the subscription key and endpoint: key must match the endpoint's region, and the endpoint must be the Image Analysis .../computervision/imageanalysis:analyze URL.","If quota/billing is the cause, enable the tier that covers the 'objects' feature or wait for the rate window to reset.","Only pass responses where the call succeeded; check 'error' in response before feeding into from_azure_analyze_image."],"exampleFix":"# before\nresponse = requests.post(endpoint, headers=headers, data=image).json()\ndetections = sv.Detections.from_azure_analyze_image(response)  # crashes on error body\n\n# after\nresponse = requests.post(endpoint, headers=headers, data=image)\nresponse.raise_for_status()\nresult = response.json()\nif 'error' in result:\n    raise RuntimeError(f\"Azure API failed: {result['error']['message']}\")\ndetections = sv.Detections.from_azure_analyze_image(result)","handlingStrategy":"try-catch","validationCode":"def is_azure_success(result: dict) -> bool:\n    return isinstance(result, dict) and 'error' not in result and 'objectsResult' in result\n\nif not is_azure_success(response_json):\n    raise RuntimeError(f\"Azure failed: {response_json.get('error', 'missing objectsResult')}\")\ndetections = sv.Detections.from_azure_analyze_image(response_json)","typeGuard":null,"tryCatchPattern":"try:\n    detections = sv.Detections.from_azure_analyze_image(result)\nexcept ValueError as e:\n    if 'Azure API returned an error' in str(e):\n        logger.error('azure vision failed: %s', result.get('error'))\n        detections = sv.Detections.empty()  # explicit policy, not silent fallback\n    else:\n        raise","preventionTips":["response.raise_for_status() plus an 'error'-in-body check before parsing","Keep key and endpoint region matched; rotate expiring keys","Wrap paid API calls in retry with backoff for 429s"],"tags":["azure","api","auth","network","vision"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}