{"record":{"id":"8403045f927b2e75","repo":"conductor-oss/conductor","slug":"embeddings-api-failed-with-status-d-s","errorCode":null,"errorMessage":"Embeddings API failed with status %d: %s","messagePattern":"Embeddings API failed with status (.+?): (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/org/conductoross/conductor/ai/providers/openai/api/OpenAIEmbeddingsApi.java","lineNumber":75,"sourceCode":"        this(httpClient, apiKey, baseUrl, false);\n    }\n\n    public EmbeddingResult createEmbeddings(EmbeddingRequest request) throws IOException {\n        String jsonBody = objectMapper.writeValueAsString(request);\n\n        Request httpRequest =\n                new Request.Builder()\n                        .url(baseUrl + \"/embeddings\")\n                        .header(authHeaderName, authHeaderValue)\n                        .header(\"Content-Type\", \"application/json\")\n                        .post(RequestBody.create(jsonBody, JSON))\n                        .build();\n\n        try (Response response = httpClient.newCall(httpRequest).execute()) {\n            ResponseBody body = response.body();\n            String responseBody = body != null ? body.string() : \"\";\n            if (!response.isSuccessful()) {\n                throw new IOException(\n                        \"Embeddings API failed with status %d: %s\"\n                                .formatted(response.code(), responseBody));\n            }\n            return objectMapper.readValue(responseBody, EmbeddingResult.class);\n        }\n    }\n\n    @JsonInclude(JsonInclude.Include.NON_NULL)\n    public record EmbeddingRequest(String model, String input, Integer dimensions) {}\n\n    @JsonIgnoreProperties(ignoreUnknown = true)\n    public record EmbeddingResult(String object, List<EmbeddingData> data, String model) {}\n\n    @JsonIgnoreProperties(ignoreUnknown = true)\n    public record EmbeddingData(String object, Integer index, List<Float> embedding) {}\n}\n","sourceCodeStart":57,"sourceCodeEnd":92,"githubUrl":"https://github.com/conductor-oss/conductor/blob/cf7c3e4a8adfb158be778ab1ec525323c363cd3a/ai/src/main/java/org/conductoross/conductor/ai/providers/openai/api/OpenAIEmbeddingsApi.java#L57-L92","documentation":"OpenAIEmbeddingsApi.createEmbeddings() throws IOException with message \"Embeddings API failed with status %d: %s\" when the HTTP response is not 2xx. The %d is the HTTP status code, %s is the raw response body. This is the low-level OkHttp client for POST {baseUrl}/embeddings. The auth header is configurable (Bearer token or api-key for Azure).","triggerScenarios":"POST {baseUrl}/embeddings returns non-2xx. Common: 401 (invalid/expired API key), 429 (rate limit — embeddings are high-volume so this is frequent), 404 (wrong baseURL or model not found), 400 (invalid dimensions parameter for the model, input too long), 500 (server error).","commonSituations":"Expired API key; requesting dimensions on a model that doesn't support it (e.g. text-embedding-ada-002 ignores dimensions; text-embedding-3-small/large support it); input text exceeding the model's token limit; rate limit during bulk vector-store indexing; wrong baseURL.","solutions":["Read the status code and body from the IOException message.","For 401: verify the API key is valid and not expired.","For 429: implement batch processing with rate-limit-aware backoff; embeddings have per-minute token limits.","For 400: check if the dimensions parameter is valid for the model (ada-002 doesn't support custom dimensions).","For 400 input-too-long: chunk the input text before embedding."],"exampleFix":"// before\nnew OpenAIEmbeddingsApi.EmbeddingRequest(\"text-embedding-ada-002\", veryLongText, 256)\n// after — ada-002 doesn't support custom dimensions\nnew OpenAIEmbeddingsApi.EmbeddingRequest(\"text-embedding-ada-002\", veryLongText, null)\n// or use a model that supports dimensions\nnew OpenAIEmbeddingsApi.EmbeddingRequest(\"text-embedding-3-small\", veryLongText, 256)","handlingStrategy":"retry","validationCode":"// Validate embedding request before calling\nOpenAIEmbeddingsApi.EmbeddingRequest request = /* ... */;\nif (request.model() == null || request.model().isBlank()) {\n    throw new IllegalArgumentException(\"Embedding model is required\");\n}\nif (request.input() == null || request.input().isBlank()) {\n    throw new IllegalArgumentException(\"Input text is required\");\n}\n// Validate dimensions is only set for models that support it\nif (request.dimensions() != null && request.model().equals(\"text-embedding-ada-002\")) {\n    throw new IllegalArgumentException(\n        \"text-embedding-ada-002 does not support custom dimensions; use text-embedding-3-small/large\");\n}","typeGuard":"null","tryCatchPattern":"int maxRetries = 3;\nfor (int attempt = 0; attempt <= maxRetries; attempt++) {\n    try {\n        return api.createEmbeddings(request);\n    } catch (IOException e) {\n        String msg = e.getMessage();\n        if (msg.contains(\"429\") && attempt < maxRetries) {\n            long delay = (long) Math.pow(2, attempt) * 2000; // longer backoff for rate limits\n            Thread.sleep(delay);\n            continue;\n        }\n        throw e;\n    }\n}","preventionTips":["Validate the embedding model name is a supported OpenAI embeddings model.","Don't set dimensions for text-embedding-ada-002 (it doesn't support it).","Implement batch processing with rate-limit-aware backoff for bulk indexing.","Chunk long input text to avoid exceeding the model's token limit.","Monitor per-minute token usage to stay under rate limits."],"tags":["openai","embeddings","http-error","network","api-error","ai"],"backgroundTag":null,"analyzedSha":"cf7c3e4a8adfb158be778ab1ec525323c363cd3a","analyzedAt":"2026-08-14T03:33:19.897Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}