1010import io .qdrant .client .grpc .QdrantGrpc .QdrantFutureStub ;
1111import io .qdrant .client .grpc .SnapshotsGrpc .SnapshotsFutureStub ;
1212import java .time .Duration ;
13+ import java .util .Map ;
1314import java .util .concurrent .TimeUnit ;
1415import javax .annotation .Nullable ;
1516import org .slf4j .Logger ;
@@ -193,8 +194,10 @@ public static class Builder {
193194 private final ManagedChannel channel ;
194195 private final boolean shutdownChannelOnClose ;
195196 private final boolean checkCompatibility ;
197+ @ Nullable private String apiKey ;
196198 @ Nullable private CallCredentials callCredentials ;
197199 @ Nullable private Duration timeout ;
200+ @ Nullable private Map <String , String > headers ;
198201
199202 Builder (ManagedChannel channel , boolean shutdownChannelOnClose , boolean checkCompatibility ) {
200203 this .channel = channel ;
@@ -218,7 +221,7 @@ public static class Builder {
218221 * @return this
219222 */
220223 public Builder withApiKey (String apiKey ) {
221- this .callCredentials = new ApiKeyCredentials ( apiKey ) ;
224+ this .apiKey = apiKey ;
222225 return this ;
223226 }
224227
@@ -237,6 +240,9 @@ public Builder withTimeout(@Nullable Duration timeout) {
237240 * Sets the credential data that will be propagated to the server via request metadata for each
238241 * RPC.
239242 *
243+ * <p>Note: If both {@link #withApiKey(String)} / {@link #withHeaders(Map)} and this method are
244+ * used, this method takes precedence and the API key and headers will be ignored.
245+ *
240246 * @param callCredentials The call credentials to use.
241247 * @return this
242248 */
@@ -245,6 +251,17 @@ public Builder withCallCredentials(@Nullable CallCredentials callCredentials) {
245251 return this ;
246252 }
247253
254+ /**
255+ * Sets custom headers to send with every gRPC request.
256+ *
257+ * @param headers The headers to send.
258+ * @return this
259+ */
260+ public Builder withHeaders (Map <String , String > headers ) {
261+ this .headers = headers ;
262+ return this ;
263+ }
264+
248265 /**
249266 * Builds a new instance of {@link QdrantGrpcClient}
250267 *
@@ -255,7 +272,13 @@ public QdrantGrpcClient build() {
255272 String clientVersion = Builder .class .getPackage ().getImplementationVersion ();
256273 checkVersionsCompatibility (clientVersion );
257274 }
258- return new QdrantGrpcClient (channel , shutdownChannelOnClose , callCredentials , timeout );
275+
276+ CallCredentials credentials = this .callCredentials ;
277+ if (credentials == null && (apiKey != null || headers != null )) {
278+ credentials = new MetadataCredentials (apiKey , headers );
279+ }
280+
281+ return new QdrantGrpcClient (channel , shutdownChannelOnClose , credentials , timeout );
259282 }
260283
261284 private static ManagedChannel createChannel (
0 commit comments