{"record":{"id":"31c27ab930e39409","repo":"HKUDS/DeepTutor","slug":"openai-sdk-request-failed-exc","errorCode":null,"errorMessage":"OpenAI SDK request failed: {exc}","messagePattern":"OpenAI SDK request failed: (.+?)","errorType":"exception","errorClass":"EmbeddingProviderError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/embedding/adapters/openai_sdk.py","lineNumber":88,"sourceCode":"            \"input\": request.texts,\n            # Unlike the gateway adapter (which omits `encoding_format` to avoid\n            # HTTP 400s), the official OpenAI/Azure API accepts it and callers\n            # expect float vectors, so pin \"float\" when none is set explicitly.\n            \"encoding_format\": request.encoding_format or \"float\",\n        }\n        dim_value = request.dimensions or self.dimensions\n        if dim_value and self._should_send_dimensions(model):\n            kwargs[\"dimensions\"] = dim_value\n\n        client = self._build_client()\n        try:\n            response = await client.embeddings.create(**kwargs)\n        except APIStatusError as exc:\n            try:\n                body = exc.response.text\n            except Exception:\n                body = str(exc)\n            raise EmbeddingProviderError(\n                f\"OpenAI SDK request failed: {exc}\",\n                status=getattr(exc, \"status_code\", None),\n                body=body,\n                model=model,\n                url=self.base_url,\n                provider=\"openai_sdk\",\n            ) from exc\n        except APIConnectionError as exc:\n            raise EmbeddingProviderError(\n                f\"OpenAI SDK connection error: {exc}\",\n                model=model,\n                url=self.base_url,\n                provider=\"openai_sdk\",\n            ) from exc\n        except APIError as exc:\n            raise EmbeddingProviderError(\n                f\"OpenAI SDK API error: {exc}\",\n                model=model,","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/embedding/adapters/openai_sdk.py#L70-L106","documentation":"The official OpenAI SDK's client.embeddings.create() raised APIStatusError — the server answered with an HTTP error status (4xx/5xx). The adapter wraps it in EmbeddingProviderError preserving status_code, response body, model, and URL.","triggerScenarios":"401 invalid API key, 404 unknown model, 400 bad parameters (e.g. unsupported dimensions), 429 rate limit (SDK already retried twice), 5xx provider outage — any non-2xx from api.openai.com or Azure embeddings endpoint.","commonSituations":"Expired/rotated OPENAI_API_KEY; typo'd model name; dimensions sent to a model that rejects it; Azure deployment name wrong or missing api-version; upstream outage.","solutions":["Check err.status and err.body — they carry the provider's exact error","401: fix the API key env var; 404: fix model/deployment name; Azure: verify deployment + api-version on base_url","400 mentioning dimensions: set send_dimensions=False or drop the dimensions override","429/5xx: back off and retry; check status.openai.com"],"exampleFix":"# before\nmodel = \"text-embedding-3-larg\"  # 404 model not found\n# after\nmodel = \"text-embedding-3-large\"","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    resp = await adapter.embed(req)\nexcept EmbeddingProviderError as e:\n    if e.status in (401, 403):\n        raise AuthError(e.body) from e          # key/deployment issue — do not retry\n    if e.status == 429 or e.status >= 500:\n        await asyncio.sleep(2 ** attempt); retry()  # transient — retry with backoff\n    raise ConfigurationError(e.body) from e    # 400/404 — fix model or params","preventionTips":["Validate model names against the provider's model list at startup","Wrap batch indexing with per-status handling: retry 429/5xx, fail fast 4xx"],"tags":["openai-sdk","http-error","embeddings","auth","bad-request"],"backgroundTag":"http-4xx-5xx-provider-error","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}