Skip to content

This documentation site is deprecated. Please visit our new documentation site at lancedb.com/docs for the latest information.

@lancedb/lancedb β€’ Docs


@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.