HKUDS/DeepTutor · error · EmbeddingProviderError

OpenAI SDK request failed: {exc}

Error message

OpenAI SDK request failed: {exc}

What it means

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.

Source

Thrown at deeptutor/services/embedding/adapters/openai_sdk.py:88

            "input": request.texts,
            # Unlike the gateway adapter (which omits `encoding_format` to avoid
            # HTTP 400s), the official OpenAI/Azure API accepts it and callers
            # expect float vectors, so pin "float" when none is set explicitly.
            "encoding_format": request.encoding_format or "float",
        }
        dim_value = request.dimensions or self.dimensions
        if dim_value and self._should_send_dimensions(model):
            kwargs["dimensions"] = dim_value

        client = self._build_client()
        try:
            response = await client.embeddings.create(**kwargs)
        except APIStatusError as exc:
            try:
                body = exc.response.text
            except Exception:
                body = str(exc)
            raise EmbeddingProviderError(
                f"OpenAI SDK request failed: {exc}",
                status=getattr(exc, "status_code", None),
                body=body,
                model=model,
                url=self.base_url,
                provider="openai_sdk",
            ) from exc
        except APIConnectionError as exc:
            raise EmbeddingProviderError(
                f"OpenAI SDK connection error: {exc}",
                model=model,
                url=self.base_url,
                provider="openai_sdk",
            ) from exc
        except APIError as exc:
            raise EmbeddingProviderError(
                f"OpenAI SDK API error: {exc}",
                model=model,

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Check err.status and err.body — they carry the provider's exact error
  2. 401: fix the API key env var; 404: fix model/deployment name; Azure: verify deployment + api-version on base_url
  3. 400 mentioning dimensions: set send_dimensions=False or drop the dimensions override
  4. 429/5xx: back off and retry; check status.openai.com

Example fix

# before
model = "text-embedding-3-larg"  # 404 model not found
# after
model = "text-embedding-3-large"
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try:
    resp = await adapter.embed(req)
except EmbeddingProviderError as e:
    if e.status in (401, 403):
        raise AuthError(e.body) from e          # key/deployment issue — do not retry
    if e.status == 429 or e.status >= 500:
        await asyncio.sleep(2 ** attempt); retry()  # transient — retry with backoff
    raise ConfigurationError(e.body) from e    # 400/404 — fix model or params

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/31c27ab930e39409. Report an issue: GitHub.