azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

[OpenAI] Support for other request path than "/openai"

Open ralscha opened this issue 1 year ago • 4 comments

Query/Question

Our endpoint on Azure uses a different path /openai-gpt-4o instead of the standard path /openai. We use different API Management setups so we route them to the desired one with this path.

But the Java SDK always adds /openai to the endpoint. Is there a way to overwrite that?

Given this example. The SDK sends the request to https://this-and-that.azure-api.net/openai-gpt-4o/openai/deployments/gpt-4o/chat/completions. Notice the additional /openai/ in the path. But this fails because this URL does not exist.

		String endpoint = "https://this-and-that.azure-api.net/openai-gpt-4o";

		var client = new OpenAIClientBuilder().credential(new AzureKeyCredential(apiKey))
				.endpoint(endpoint)
				.buildClient();

		List<ChatRequestMessage> chatMessages = new ArrayList<>();
		chatMessages.add(new ChatRequestUserMessage("Hello, how are you?"));

		ChatCompletionsOptions chatCompletionsOptions = new ChatCompletionsOptions(
				chatMessages);
		chatCompletionsOptions.setTemperature(0.0);
		chatCompletionsOptions.setMaxTokens(100);

		var response = client.getChatCompletions("gpt-4o", chatCompletionsOptions);
		System.out.println(response.getChoices().get(0).getMessage().getContent());

Setup (please complete the following information if applicable):

  • Java 21
  • com.azure.azure-ai-openai 1.0.0-beta.10

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [x] Query Added
  • [x] Setup information Added

ralscha avatar Aug 06 '24 18:08 ralscha

@ralscha Thank you for reaching out to us. The reason why we have a fixed path is from this line. Do you know what the APIM endpoint pattern is? Can the path parameter be any value?

mssfang avatar Aug 22 '24 21:08 mssfang

Hi @ralscha. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] avatar Aug 23 '24 00:08 github-actions[bot]

@mssfang Our endpoint currently is /openai-gpt-4o. It could be any value. But I can easily fix it in the APIM by creating a path /openai-gpt-4o/openai. The Python SDK from OpenAI does not have a problem with the path /openai-gpt-4o. Looks like their implementation does not hardcode /openai

ralscha avatar Aug 23 '24 07:08 ralscha

@mssfang Our endpoint currently is /openai-gpt-4o. It could be any value. But I can easily fix it in the APIM by creating a path /openai-gpt-4o/openai. The Python SDK from OpenAI does not have a problem with the path /openai-gpt-4o. Looks like their implementation does not hardcode /openai

Yeah. Python SDK is not using the same spec to generate. This hardcode /openai only affect those generated language SDKs based on the spec. Currently, Java is one of them depends on the spec.

mssfang avatar Aug 23 '24 16:08 mssfang

Hi @ralscha. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] avatar Aug 06 '25 08:08 github-actions[bot]

Hi @ralscha, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

github-actions[bot] avatar Aug 13 '25 10:08 github-actions[bot]