Repository navigation
Bug: HTTP 404 Error When Using OpenAI-Compatible Endpoint with Semantic Kernel 1.4.4-RC1 #330
Description
Describe the bug
When attempting to use an OpenAI-compatible endpoint (specifically https://api.siliconflow.cn/v1) with Semantic Kernel 1.4.4-RC1, I consistently receive HTTP 404 errors ("404 page not found") regardless of the invocation method.
Code Implementation
OpenAIAsyncClient client = new OpenAIClientBuilder().credential(new KeyCredential("sk-key")).endpoint("https://api.siliconflow.cn/v1").buildAsyncClient();
ChatCompletionService chatService = OpenAIChatCompletion.builder().withModelId("Qwen/Qwen2.5-32B-Instruct").withOpenAIAsyncClient(client).build();
Kernel kernel = Kernel.builder().withAIService(ChatCompletionService.class, chatService).withPlugin(lightPlugin).build();
Error Occurrence
Both invocation methods fail with the same 404 error:
1、Prompt invocation:
kernel.invokePromptAsync(prompt, argss).block();
2、Direct chat service invocation:
chatService.getChatMessageContentsAsync(history, kernel, invocationContext).block();
Error Details
Full stack trace shows:
00:37:50.318 [reactor-http-nio-1] WARN com.azure.core.implementation.serializer.HttpResponseBodyDecoder -- Failed to deserialize the error entity. Unsupported text Content-Type Type: class java.lang.Object Exception in thread "main" com.azure.core.exception.HttpResponseException: Status code 404, "404 page not found" at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:381) at com.azure.core.implementation.http.rest.AsyncRestProxy.lambda$ensureExpectedStatus$1(AsyncRestProxy.java:135) at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113) at reactor.core.publisher.MonoUsing$MonoUsingSubscriber.onNext(MonoUsing.java:231) at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:129) at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:224) at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onNext(FluxDoFinally.java:113) at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:194) at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) at reactor.core.publisher.Operators$BaseFluxToMonoOperator.completePossiblyEmpty(Operators.java:2096) at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:118) at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260) at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:413) at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:455) at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:509) at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:821) at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:115) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at com.azure.core.http.netty.implementation.AzureSdkHandler.channelRead(AzureSdkHandler.java:224) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1515) at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1389) at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1429) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:796) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:732) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:658) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:842) Suppressed: java.lang.Exception: #block terminated with an error at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:104) at reactor.core.publisher.Mono.block(Mono.java:1779) at com.example.semantickernel_example.TextGenerationExample.main(TextGenerationExample.java:65) Caused by: java.lang.IllegalStateException: Unsupported text Content-Type Type: class java.lang.Object at com.azure.core.util.serializer.JacksonAdapter.deserializeText(JacksonAdapter.java:453) at com.azure.core.util.serializer.JacksonAdapter.lambda$deserialize$9(JacksonAdapter.java:354) at com.azure.core.util.serializer.JacksonAdapter.useAccessHelper(JacksonAdapter.java:491) at com.azure.core.util.serializer.JacksonAdapter.deserialize(JacksonAdapter.java:347) at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.deserialize(HttpResponseBodyDecoder.java:176) at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.deserializeBody(HttpResponseBodyDecoder.java:150) at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.decodeByteArray(HttpResponseBodyDecoder.java:67) at com.azure.core.implementation.serializer.HttpResponseDecoder$HttpDecodedResponse.getDecodedBody(HttpResponseDecoder.java:93)
Troubleshooting Attempts
1、Verified the endpoint URL is correct and accessible
2、Confirmed the API key is valid
3、Tested the same endpoint with direct HTTP requests (works fine)
4、Tried with different model IDs
5、Verified network connectivity and firewall settings
Expected Behavior
The OpenAI-compatible endpoint should accept requests and return proper responses when used through Semantic Kernel's client.
Environment
Semantic Kernel version: 1.4.4-RC1
Java version: 17
OS: Windows 11 Pro
Additional Context
The endpoint https://api.siliconflow.cn/v1 is confirmed to work with standard OpenAI API requests, suggesting this may be a client configuration or SDK compatibility issue.
Questions
1、Are there any additional configuration requirements for using non-Azure OpenAI endpoints?
2、Is the OpenAIClientBuilderthe correct approach for third-party OpenAI-compatible services?
3、Are there known issues with the 1.4.4-RC1 version regarding custom endpoints?
Activity
johnoliver commentedon Aug 6, 2025
Can you run it again setting the environment variable
AZURE_HTTP_LOG_DETAIL_LEVEL=BODY_AND_HEADERSso I can see the response that should give something along the lines of:Be sure to remove and sensitive data if it contains any
GavinHwa commentedon Aug 6, 2025
00:44:30.716 [main] INFO com.azure.ai.openai.implementation.OpenAIClientImpl$OpenAIClientService.getChatCompletions -- {"az.sdk.message":"HTTP request","method":"POST","url":"https://api.siliconflow.cn/v1/openai/deployments/Qwen%2FQwen2.5-32B-Instruct/chat/completions?api-version=2025-01-01-preview","tryCount":1,"Date":"Wed, 06 Aug 2025 16:44:30 GMT","Content-Type":"application/json","x-ms-client-request-id":"4004c269-ef8c-45a3-8288-b9e859ae1248","Accept":"application/json","User-Agent":"azsdk-java-azure-ai-openai/1.0.0-beta.14 (17.0.15; Windows 11; 10.0) semantic-kernel-java/1.4.4-RC1","redactedHeaders":"Semantic-Kernel-Version,api-key","content-length":637,"body":"{\"messages\":[{\"role\":\"user\",\"content\":\"Turn on light 2\"}],\"model\":\"Qwen/Qwen2.5-32B-Instruct\",\"tools\":[{\"function\":{\"name\":\"LightsPlugin-get_lights\",\"description\":\"Gets a list of lights and their current state\",\"parameters\":{\"type\":\"object\",\"required\":[],\"properties\":{}}},\"type\":\"function\"},{\"function\":{\"name\":\"LightsPlugin-change_state\",\"description\":\"Changes the state of the light\",\"parameters\":{\"type\":\"object\",\"required\":[\"id\",\"isOn\"],\"properties\":{\"isOn\":{\"type\":\"string\",\"description\":\"The new state of the light\"},\"id\":{\"type\":\"string\",\"description\":\"The ID of the light to change\"}}}},\"type\":\"function\"}],\"tool_choice\":\"auto\"}"} 00:44:32.175 [reactor-http-nio-1] INFO com.azure.ai.openai.implementation.OpenAIClientImpl$OpenAIClientService.getChatCompletions -- {"az.sdk.message":"HTTP response","statusCode":404,"url":"https://api.siliconflow.cn/v1/openai/deployments/Qwen%2FQwen2.5-32B-Instruct/chat/completions?api-version=2025-01-01-preview","durationMs":1446,"content-length":18,"Date":"Wed, 06 Aug 2025 16:44:31 GMT","Connection":"keep-alive","Content-Type":"text/plain","content-length":18,"body":"404 page not found"} 00:44:32.184 [reactor-http-nio-1] WARN com.azure.core.implementation.serializer.HttpResponseBodyDecoder -- Failed to deserialize the error entity. Unsupported text Content-Type Type: class java.lang.Object Exception in thread "main" com.azure.core.exception.HttpResponseException: Status code 404, "404 page not found"Current Incorrect URL:
https://api.siliconflow.cn/v1/openai/deployments/Qwen%2FQwen2.5-32B-Instruct/chat/completions?api-version=2025-01-01-preview.Expected Correct URL:
https://api.siliconflow.cn/v1/chat/completionsCode: The issue lies in the URL concatenation logic within the
com.azure.ai.openai.implementation.OpenAIClientImpl.OpenAIClientServiceclass.johnoliver commentedon Aug 6, 2025
Unfortunately that class is on the azure-sdk-for-java repository (https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/implementation/OpenAIClientImpl.java) so the bug would have to go there, there is the NonAzureOpenAIClientImpl (https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/implementation/NonAzureOpenAIClientImpl.java) However that only works with api.openai.com
Realistically to support this we would probably need to migrate to a different OpenAI Client library