| 264 | * @category Layers |
| 265 | */ |
| 266 | export const layerConfig = (options: { |
| 267 | readonly apiKey?: Config.Config<Redacted.Redacted> | undefined |
| 268 | readonly apiUrl?: Config.Config<string> | undefined |
| 269 | /** |
| 270 | * Optional URL of your site for rankings on `openrouter.ai`. |
| 271 | */ |
| 272 | readonly referrer?: Config.Config<string> | undefined |
| 273 | /** |
| 274 | * Optional title of your site for rankings on `openrouter.ai`. |
| 275 | */ |
| 276 | readonly title?: Config.Config<string> | undefined |
| 277 | /** |
| 278 | * A function to transform the underlying HTTP client before it's used to send |
| 279 | * API requests. |
| 280 | * |
| 281 | * This transformation function receives the configured HTTP client and returns |
| 282 | * a modified version. It's applied after all standard client configuration |
| 283 | * (authentication, base URL, headers) but before any requests are made. |
| 284 | * |
| 285 | * Use this for: |
| 286 | * - Adding custom middleware (logging, metrics, caching) |
| 287 | * - Modifying request/response processing behavior |
| 288 | * - Adding custom retry logic or error handling |
| 289 | * - Integrating with monitoring or debugging tools |
| 290 | * - Applying organization-specific HTTP client policies |
| 291 | * |
| 292 | * The transformation is applied once during client initialization and affects |
| 293 | * all subsequent API requests made through this client instance. |
| 294 | * |
| 295 | * Leave absent or set to `undefined` if no custom HTTP client behavior is |
| 296 | * needed. |
| 297 | */ |
| 298 | readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined |
| 299 | }): Layer.Layer<OpenRouterClient, ConfigError, HttpClient.HttpClient> => { |
| 300 | const { transformClient, ...configs } = options |
| 301 | return Config.all(configs).pipe( |
| 302 | Effect.flatMap((configs) => make({ ...configs, transformClient })), |
| 303 | Layer.effect(OpenRouterClient) |
| 304 | ) |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * @since 1.0.0 |