const API_BASE = 'http://localhost:8000'; export async function fetchApi(endpoint: string, options?: RequestInit): Promise { const url = endpoint.startsWith('http') ? endpoint : `${API_BASE}${endpoint}`; const res = await fetch(url, { ...options, headers: { 'Content-Type': 'application/json', ...(options?.headers || {}), }, }); if (!res.ok) { const errData = await res.json().catch(() => ({ detail: res.statusText })); throw new Error(errData.detail || `Request failed with status ${res.status}`); } return res.json(); }