genkitx-aws-bedrock
    Preparing search index...

    Function requireApiKey

    • Creates a context provider that requires an API key in a specific header.

      Parameters

      • headerName: string
      • expectedValueOrValidator: string | ((apiKey: string) => void | Promise<void>)

      Returns ContextProvider<ApiKeyContext>

      // Require API key to match a specific value
      export const handler = onCallGenkit(
      { contextProvider: requireApiKey('X-API-Key', process.env.API_KEY!) },
      myFlow
      );

      // Or with a custom validation function
      export const handler = onCallGenkit(
      {
      contextProvider: requireApiKey('X-API-Key', async (key) => {
      const valid = await validateApiKey(key);
      if (!valid) {
      throw new UserFacingError('PERMISSION_DENIED', 'Invalid API key');
      }
      })
      },
      myFlow
      );