Download client/src/lib/api.ts from tayyabimam/My-Free-LLM-API: direct link, hf CLI and curl.
- Browser
- Download file 485 Bytes
-
https://huggingface.co/spaces/tayyabimam/My-Free-LLM-API/resolve/main/client/src/lib/api.ts
- Command line
-
hf download hf://spaces/tayyabimam/My-Free-LLM-API/client/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/tayyabimam/My-Free-LLM-API/resolve/main/client/src/lib/api.ts
485 Bytes
| const BASE = import.meta.env.BASE_URL.replace(/\/$/, ''); | |
| export async function apiFetch<T>(path: string, options?: RequestInit): Promise<T> { | |
| const res = await fetch(`${BASE}${path}`, { | |
| headers: { 'Content-Type': 'application/json', ...options?.headers }, | |
| ...options, | |
| }); | |
| if (!res.ok) { | |
| const body = await res.json().catch(() => ({ error: { message: res.statusText } })); | |
| throw new Error(body.error?.message ?? `HTTP ${res.status}`); | |
| } | |
| return res.json(); | |
| } | |