import axios from "axios"; export const apiClient = axios.create({ baseURL: "/api", }); apiClient.interceptors.request.use((config) => { // Only access localStorage in browser environment if (typeof window !== 'undefined') { const keysStr = localStorage.getItem("smartlead_api_keys"); const activeId = localStorage.getItem("smartlead_active_key_id"); if (keysStr && activeId) { try { const keys = JSON.parse(keysStr); const activeKey = keys.find((k: any) => k.id === activeId)?.key; if (activeKey) { config.headers["x-api-key"] = activeKey; } } catch (e) { console.error("Failed to parse API keys", e); } } } return config; });