Skip to content

Azure example doesn't recognize endpoint URL #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mzattera opened this issue May 11, 2025 · 3 comments
Open

Azure example doesn't recognize endpoint URL #467

mzattera opened this issue May 11, 2025 · 3 comments
Labels
question Further information is requested

Comments

@mzattera
Copy link

When running the Azure example provided in example folder, I get the below exception.

It seems base URL is not properly recognized.

Exception in thread "main" java.io.UncheckedIOException: java.net.UnknownHostException: www.example.com
	at com.azure.core.http.netty.NettyAsyncHttpClient.sendSync(NettyAsyncHttpClient.java:201)
	at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:51)
	at com.azure.core.http.policy.BearerTokenAuthenticationPolicy.processSync(BearerTokenAuthenticationPolicy.java:175)
	at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
	at com.azure.core.http.HttpPipeline.sendSync(HttpPipeline.java:138)
	at com.azure.identity.AuthenticationUtil.lambda$getBearerTokenSupplier$0(AuthenticationUtil.java:56)
	at com.openai.credential.BearerTokenCredential.token(BearerTokenCredential.kt:35)
	at com.openai.core.ClientOptions$Builder.build(ClientOptions.kt:295)
	at com.openai.client.okhttp.OpenAIOkHttpClient$Builder.build(OpenAIOkHttpClient.kt:196)
	at test.AzureEntraIdExample.main(AzureEntraIdExample.java:29)
Caused by: java.net.UnknownHostException: www.example.com
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1335)
	at java.net.InetAddress.getAllByName0(InetAddress.java:1288)
	at java.net.InetAddress.getAllByName(InetAddress.java:1203)
	at java.net.InetAddress.getAllByName(InetAddress.java:1127)
	at io.netty.util.internal.SocketUtils$9.run(SocketUtils.java:169)
	at io.netty.util.internal.SocketUtils$9.run(SocketUtils.java:166)
	at java.security.AccessController.doPrivileged(Native Method)
	at io.netty.util.internal.SocketUtils.allAddressesByName(SocketUtils.java:166)
	at io.netty.resolver.DefaultNameResolver.doResolveAll(DefaultNameResolver.java:50)
	at io.netty.resolver.SimpleNameResolver.resolveAll(SimpleNameResolver.java:79)
	at io.netty.resolver.SimpleNameResolver.resolveAll(SimpleNameResolver.java:71)
	at io.netty.resolver.InetSocketAddressResolver.doResolveAll(InetSocketAddressResolver.java:73)
	at io.netty.resolver.InetSocketAddressResolver.doResolveAll(InetSocketAddressResolver.java:31)
	at io.netty.resolver.AbstractAddressResolver.resolveAll(AbstractAddressResolver.java:158)
	at reactor.netty.transport.TransportConnector.doResolveAndConnect(TransportConnector.java:329)
	at reactor.netty.transport.TransportConnector.lambda$connect$6(TransportConnector.java:165)
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:125)
	at reactor.netty.transport.TransportConnector$MonoChannelPromise._subscribe(TransportConnector.java:631)
	at reactor.netty.transport.TransportConnector$MonoChannelPromise.lambda$subscribe$0(TransportConnector.java:543)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
	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.lang.Thread.run(Thread.java:750)

I have provided both AZURE_OPENAI_KEY and OPENAI_BASE_URL in my environment and I am testing they are read correctly by my app, I get the same error even if I specify the endpoint using:

		OpenAIClient client = OpenAIOkHttpClient.builder()
				.fromEnv()
				.baseUrl("https://<my endpoint>.openai.azure.com/")
				.credential(BearerTokenCredential.create(AuthenticationUtil.getBearerTokenSupplier(
						new DefaultAzureCredentialBuilder().build(), "https://cognitiveservices.azure.com/.default")))
				.build();

If it helps, my POM file is below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Test</name>
  <description>Test for OpenAI Java SDK</description>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

		<!-- Java version -->
		<maven.compiler.source>11</maven.compiler.source>
		<maven.compiler.target>11</maven.compiler.target>
	</properties>
	<dependencies>
		<!-- Official OpenAI Java SDK -->
		<dependency>
		  <groupId>com.openai</groupId>
		  <artifactId>openai-java</artifactId>
		  <version>1.6.1</version>
		</dependency>		
		<!-- To access Azure OpenAI Gognitive Services -->
		<dependency>
		    <groupId>com.azure.resourcemanager</groupId>
		    <artifactId>azure-resourcemanager-cognitiveservices</artifactId>
		    <version>1.1.0</version>
		</dependency>
		<dependency>
		    <groupId>com.azure</groupId>
		    <artifactId>azure-identity</artifactId>
		    <version>1.16.0</version>
		    <scope>compile</scope>
		</dependency>
	</dependencies>
</project>
@mzattera mzattera changed the title Azure example doesn't recognize URL Azure example doesn't recognize endpoint URL May 11, 2025
@TomerAberbach
Copy link
Collaborator

I see it says Caused by: java.net.UnknownHostException: www.example.com in your exception. Are you trying to set www.example.com as your base URL via your env? That seems odd.

@TomerAberbach TomerAberbach added the question Further information is requested label May 14, 2025
@mzattera
Copy link
Author

I see it says Caused by: java.net.UnknownHostException: www.example.com in your exception. Are you trying to set www.example.com as your base URL via your env? That seems odd.

Hi, no, that's exactly my point. Seems the client is using that URL which is typically used when no URL is set for OkhttpClient (I believe), hence my comment that OpenAIClient is not reading/passing/setting the URL properly.

@jpalvarezl
Copy link

Hi @mzattera, have you tried enabling logging? I was able to hit an azure endpoint using the sample. Admittedly, I had to add also the azureServiceVersion. Building my client looks like this:

OpenAIClient client = OpenAIOkHttpClient.builder()
                // Gets the API key from the `AZURE_OPENAI_KEY` environment variable
                .fromEnv()
                // Set the Azure Entra ID
                .credential(BearerTokenCredential.create(AuthenticationUtil.getBearerTokenSupplier(
                        new DefaultAzureCredentialBuilder().build(), "https://cognitiveservices.azure.com/.default")))
                .azureServiceVersion(AzureOpenAIServiceVersion.getV2025_01_01_PREVIEW())
                .build();

        ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
                .model(ChatModel.of("Your deployment name"))
                .maxCompletionTokens(2048)
                .addDeveloperMessage("Make sure you mention Stainless!")
                .addUserMessage("Tell me a story about building the best SDK!")
                .build();

I am setting the following environment variables:

AZURE_OPENAI_KEY=<your key value>
OPENAI_BASE_URL=<your endpoint value>
OPENAI_LOG=debug

I would triple check that you are passing a URL that parses correctly in the OPENAI_BASE_URL value. Although the parsing error is actually very clear, if you weren't doing that.

I would also recommend updating to the latest version of the SDK in your pom.xml file if you can, just so that you are taking in any fixes that may have been deployed on the mean time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants