Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ public class HttpTransportConfig {
/** Default connect timeout: 30 seconds. */
public static final Duration DEFAULT_CONNECT_TIMEOUT = Duration.ofSeconds(30);

/** Default read timeout: 5 minutes (for long-running model calls). */
/** Default read timeout: 5 minutes. */
public static final Duration DEFAULT_READ_TIMEOUT = Duration.ofMinutes(5);

/**
* Default streaming response timeout: 5 minutes (request start to first emitted streaming
* chunk).
*/
public static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofMinutes(5);

/** Default streaming idle timeout: 5 minutes (maximum wait between data chunks). */
public static final Duration DEFAULT_STREAM_IDLE_TIMEOUT = DEFAULT_READ_TIMEOUT;

/** Default write timeout: 30 seconds. */
public static final Duration DEFAULT_WRITE_TIMEOUT = Duration.ofSeconds(30);

private final Duration connectTimeout;
private final Duration responseTimeout;
private final Duration streamIdleTimeout;
private final Duration readTimeout;
private final Duration writeTimeout;
private final int maxIdleConnections;
Expand All @@ -45,6 +56,8 @@ public class HttpTransportConfig {

private HttpTransportConfig(Builder builder) {
this.connectTimeout = builder.connectTimeout;
this.responseTimeout = builder.responseTimeout;
this.streamIdleTimeout = builder.streamIdleTimeout;
this.readTimeout = builder.readTimeout;
this.writeTimeout = builder.writeTimeout;
this.maxIdleConnections = builder.maxIdleConnections;
Expand All @@ -63,9 +76,40 @@ public Duration getConnectTimeout() {
return connectTimeout;
}

/**
* Get the response timeout for streaming requests.
*
* <p>For {@link JdkHttpTransport} streaming requests, this bounds the time from request start
* until the first emitted SSE/NDJSON chunk. {@link OkHttpTransport} does not consume this
* option; it relies on OkHttp's {@link #getReadTimeout()} for stream reads.
*
* @return the response timeout duration
*/
public Duration getResponseTimeout() {
return responseTimeout;
}

/**
* Get the stream idle timeout.
*
* <p>For {@link JdkHttpTransport} streaming requests, this bounds the maximum wait between two
* consecutive emitted SSE/NDJSON chunks. {@link OkHttpTransport} does not consume this option;
* it relies on OkHttp's {@link #getReadTimeout()} for stream reads.
*
* @return the stream idle timeout duration
*/
public Duration getStreamIdleTimeout() {
return streamIdleTimeout;
}

/**
* Get the read timeout.
*
* <p>{@link OkHttpTransport} applies this as OkHttp's read timeout for both standard and
* streaming requests. {@link JdkHttpTransport} applies this to non-streaming requests only; JDK
* streaming requests use {@link #getResponseTimeout()} and {@link #getStreamIdleTimeout()}
* instead.
*
* @return the read timeout duration
*/
public Duration getReadTimeout() {
Expand Down Expand Up @@ -153,6 +197,8 @@ public static HttpTransportConfig defaults() {
*/
public static class Builder {
private Duration connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private Duration responseTimeout = DEFAULT_RESPONSE_TIMEOUT;
private Duration streamIdleTimeout = DEFAULT_STREAM_IDLE_TIMEOUT;
private Duration readTimeout = DEFAULT_READ_TIMEOUT;
private Duration writeTimeout = DEFAULT_WRITE_TIMEOUT;
private int maxIdleConnections = 5;
Expand All @@ -172,9 +218,44 @@ public Builder connectTimeout(Duration connectTimeout) {
return this;
}

/**
* Set the response timeout for streaming requests.
*
* <p>For {@link JdkHttpTransport} streaming requests, this bounds the time from request
* start until the first emitted SSE/NDJSON chunk. {@link OkHttpTransport} does not consume
* this option; it relies on OkHttp's {@link #getReadTimeout()} for stream reads.
*
* @param responseTimeout the response timeout duration
* @return this builder
*/
public Builder responseTimeout(Duration responseTimeout) {
this.responseTimeout = responseTimeout;
return this;
Comment thread
jujn marked this conversation as resolved.
}

/**
* Set the stream idle timeout.
*
* <p>For {@link JdkHttpTransport} streaming requests, this bounds the maximum wait between
* two consecutive emitted SSE/NDJSON chunks. {@link OkHttpTransport} does not consume this
* option; it relies on OkHttp's {@link #getReadTimeout()} for stream reads.
*
* @param streamIdleTimeout the stream idle timeout duration
* @return this builder
*/
public Builder streamIdleTimeout(Duration streamIdleTimeout) {
this.streamIdleTimeout = streamIdleTimeout;
return this;
}

/**
* Set the read timeout.
*
* <p>{@link OkHttpTransport} applies this as OkHttp's read timeout for both standard and
* streaming requests. {@link JdkHttpTransport} applies this to non-streaming requests only;
* JDK streaming requests use {@link #getResponseTimeout()} and
* {@link #getStreamIdleTimeout()} instead.
*
* @param readTimeout the read timeout duration
* @return this builder
*/
Expand Down
Loading
Loading