{"record":{"id":"966d429e67ffa11b","repo":"microsoft/semantic-kernel","slug":"type-self-service-failed-to-generate-embeddings-966d42","errorCode":null,"errorMessage":"{type(self)} service failed to generate embeddings","messagePattern":"(.+?) service failed to generate embeddings","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py","lineNumber":118,"sourceCode":"            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the prompt\",\n                ex,\n            ) from ex\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to complete the prompt\",\n                ex,\n            ) from ex\n\n    async def _send_embedding_request(self, settings: OpenAIEmbeddingPromptExecutionSettings) -> list[Any]:\n        \"\"\"Send a request to the OpenAI embeddings endpoint.\"\"\"\n        try:\n            response = await self.client.embeddings.create(**settings.prepare_settings_dict())\n\n            self.store_usage(response)\n            return [x.embedding for x in response.data]\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to generate embeddings\",\n                ex,\n            ) from ex\n\n    async def _send_text_to_image_request(self, settings: OpenAITextToImageExecutionSettings) -> ImagesResponse:\n        \"\"\"Send a request to the OpenAI text to image endpoint.\"\"\"\n        try:\n            response: ImagesResponse = await self.client.images.generate(\n                **settings.prepare_settings_dict(),\n            )\n            self.store_usage(response)\n            return response\n        except Exception as ex:\n            raise ServiceResponseException(f\"Failed to generate image: {ex}\") from ex\n\n    async def _send_image_edit_request(\n        self,\n        image: list[FileTypes],","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py#L100-L136","documentation":"Raised as ServiceResponseException in _send_embedding_request when any exception occurs during client.embeddings.create. The handler catches all exceptions and wraps them, meaning the original cause (network error, invalid input, rate limit, unsupported model) is available in ex.__cause__.","triggerScenarios":"Calling the embedding generation path with invalid inputs: empty text list, text exceeding the model's token limit, an unsupported embedding model id, a network failure, or a rate-limit error during client.embeddings.create.","commonSituations":"Passing an empty list of texts to embed; using a deprecated embedding model name; batch input that exceeds per-request token limits; network or quota issues during high-volume embedding generation.","solutions":["Check ex.__cause__ for the specific OpenAI SDK exception to diagnose root cause","Ensure the input texts list is non-empty and each text is within the model's token limit","Verify the embedding model id is current and supported (e.g., text-embedding-3-small)","For rate limits, batch fewer inputs per request or implement backoff"],"exampleFix":"# before\nembeddings = await service.generate_embeddings([])\n# after — validate input first\ntexts = [t for t in texts if t.strip()]\nif not texts:\n    raise ValueError('No non-empty texts to embed')\nembeddings = await service.generate_embeddings(texts)","handlingStrategy":"retry","validationCode":"texts = [t for t in texts if t and t.strip()]\nif not texts:\n    raise ValueError('Cannot generate embeddings for an empty input list')\nMAX_TOKENS = 8191  # for text-embedding-3-small\nfor t in texts:\n    if len(t) > 20000:  # rough heuristic guard\n        logger.warning('Text may exceed model token limit')","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResponseException\nfrom openai import RateLimitError\n\ntry:\n    embeddings = await service.generate_embeddings(texts)\nexcept ServiceResponseException as e:\n    if isinstance(e.__cause__, RateLimitError):\n        await asyncio.sleep(backoff)\n        embeddings = await service.generate_embeddings(texts)\n    raise","preventionTips":["Pre-validate that the texts list is non-empty before calling the embedding API","Batch large embedding requests to stay within token-per-request limits"],"tags":["openai","embeddings","network","retry","catch-all"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}