> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Java SDK proxy configuration with authentication

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = undefined

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## Summary

**Goal:** Configure proxy authentication for the Braintrust Java SDK using a custom OkHttp client.

**Features:** Custom HTTP client configuration, OkHttp proxy authenticator, braintrust-java-core package.

## Configuration Steps

### Step 1: Replace dependency

Replace `braintrust-java` with `braintrust-java-core` in your project dependencies.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
<dependency>
  <groupId>com.braintrustdata.api</groupId>
  <artifactId>braintrust-java-core</artifactId>
  <version>VERSION</version>
</dependency>

```

### Step 2: Customize OkHttpClient

Copy the `OkHttpClient` class from `braintrust-java-client-okhttp` and add `proxyAuthenticator` support to the builder.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
class Builder internal constructor() {
    private var baseUrl: HttpUrl? = null
    private var timeout: Timeout = Timeout.default()
    private var proxy: Proxy? = null
    private var proxyAuthenticator: okhttp3.Authenticator? = null

    fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() }

    fun timeout(timeout: Timeout) = apply { this.timeout = timeout }

    fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }

    fun proxyAuthenticator(authenticator: okhttp3.Authenticator?) = apply {
        this.proxyAuthenticator = authenticator
    }

    fun build(): OkHttpClient =
        OkHttpClient(
            okhttp3.OkHttpClient.Builder()
                .connectTimeout(timeout.connect())
                .readTimeout(timeout.read())
                .writeTimeout(timeout.write())
                .callTimeout(timeout.request())
                .proxy(proxy)
                .proxyAuthenticator(proxyAuthenticator ?: okhttp3.Authenticator.NONE)
                .build(),
            checkRequired("baseUrl", baseUrl),
        )
}

```

### Step 3: Configure client with proxy authentication

Construct `BraintrustClientImpl` with your customized HTTP client, setting both proxy and authenticator.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
BraintrustClient client =
    BraintrustOkHttpClient.builder()
        .baseUrl(apiUrl)
        .apiKey(apiKey)
        .proxy(
            new Proxy(
                Proxy.Type.HTTP,
                new InetSocketAddress(proxyHost, proxyPort)))
        .proxyAuthenticator(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                    proxyUsername, proxyPassword.toCharArray());
            }
        })
        .build();

```

## Notes

Java's `Authenticator.setDefault()` does not work with OkHttp, which requires explicit `proxyAuthenticator` configuration on the builder.
