Files
lancedb/docs/src/js/classes/HeaderProvider.md
Jack Ye 8da74dcb37 feat: support per-request header override (#2631)
## Summary

This PR introduces a `HeaderProvider` which is called for all remote
HTTP calls to get the latest headers to inject. This is useful for
features like adding the latest auth tokens where the header provider
can auto-refresh tokens internally and each request always set the
refreshed token.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-10 13:44:00 -07:00

1.8 KiB

@lancedb/lancedbDocs


@lancedb/lancedb / HeaderProvider

Class: abstract HeaderProvider

Abstract base class for providing custom headers for each request.

Users can implement this interface to provide dynamic headers for various purposes such as authentication (OAuth tokens, API keys), request tracking (correlation IDs), custom metadata, or any other header-based requirements. The provider is called before each request to ensure fresh header values are always used.

Examples

Simple JWT token provider:

class JWTProvider extends HeaderProvider {
  constructor(private token: string) {
    super();
  }

  getHeaders(): Record<string, string> {
    return { authorization: `Bearer ${this.token}` };
  }
}

Provider with request tracking:

class RequestTrackingProvider extends HeaderProvider {
  constructor(private sessionId: string) {
    super();
  }

  getHeaders(): Record<string, string> {
    return {
      "X-Session-Id": this.sessionId,
      "X-Request-Id": `req-${Date.now()}`
    };
  }
}

Extended by

Constructors

new HeaderProvider()

new HeaderProvider(): HeaderProvider

Returns

HeaderProvider

Methods

getHeaders()

abstract getHeaders(): Record<string, string>

Get the latest headers to be added to requests.

This method is called before each request to the remote LanceDB server. Implementations should return headers that will be merged with existing headers.

Returns

Record<string, string>

Dictionary of header names to values to add to the request.

Throws

If unable to fetch headers, the exception will be propagated and the request will fail.