modul-e / src /lib /apiClient.ts
sitcod3's picture
Upload src/lib/apiClient.ts with huggingface_hub
3840483 verified
Raw History Blame
664 Bytes
import axios from "axios";
export const apiClient = axios.create({
baseURL: "/api",
});
apiClient.interceptors.request.use((config) => {
// Read keys from localStorage to inject into request
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;
});