Skip to content

feat: support OkHttp application interceptors - #899

Open
sylvesterkaczmarek wants to merge 3 commits into
openai:mainfrom
sylvesterkaczmarek:feature/custom-http-interceptor-support
Open

feat: support OkHttp application interceptors#899
sylvesterkaczmarek wants to merge 3 commits into
openai:mainfrom
sylvesterkaczmarek:feature/custom-http-interceptor-support

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Add application-interceptor support to the SDK's public OkHttp transport builder so users can customise requests and responses without copying the SDK's HttpClient implementation.

Fixes #339.

Problem

The SDK currently exposes several OkHttp transport settings, but there is no supported way to register an OkHttp Interceptor. The documented workaround is to copy the SDK's OkHttp transport implementation and maintain a local fork just to add interceptors.

That is unnecessarily heavy for common use cases such as request tagging, custom observability, organisation-specific headers, response inspection, and integration with existing OkHttp middleware.

Fix

Add a Java-callable builder method:

OkHttpClient.builder().addInterceptor(interceptor)

Configured interceptors are registered as standard OkHttp application interceptors when the underlying transport is built. Multiple calls preserve registration order, matching OkHttp's normal semantics.

The existing public construction path can then use the customised transport directly through ClientOptions and OpenAIClientImpl, without copying SDK source.

Regression coverage

Extended OkHttpClientTest with a WireMock-backed test that:

  • installs an application interceptor;
  • has the interceptor add a request header;
  • performs a real SDK transport request;
  • verifies WireMock received the interceptor-added header.

Validation

  • branch is based on current upstream main at 81134d727946fb84cc48db98e6c8c53c8a8d22ab;
  • branch is 0 commits behind upstream;
  • production diff is 7 additions in OkHttpClient.kt;
  • existing proxy, timeout, TLS, connection-pool, cancellation, and retry behaviour is unchanged.

Full repository validation is left to GitHub Actions.

Risk

Low. No interceptor is installed by default, so existing clients behave exactly as before. The new behaviour is entirely opt-in and delegates interceptor semantics to OkHttp.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 18, 2026 23:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f687cddfc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support interceptors

1 participant