Skip to main content

API Client

File: src/api/client.ts (637 lines)

The API client is a typed HTTP wrapper that handles all communication between the client and the GetThatQuick server. All requests go through the /api base URL, which is proxied to localhost:3000 during development.


Error Handling

ApiClientError

A custom error class extending Error:

class ApiClientError extends Error {
status: number; // HTTP status code (0 for network errors)
isNetworkError: boolean; // true if the request never reached the server
}

The client catches and wraps:

  • Network errors — server unreachable, DNS failures
  • JSON parse failures — malformed response bodies
  • Timeouts — request exceeded time limit
  • Abort signals — user-cancelled requests

Endpoint Groups

Sessions

MethodEndpointDescription
getSessions()GET /api/sessionsList all sessions
getSession(id)GET /api/sessions/:idGet a single session
createSession(data)POST /api/sessionsCreate a new session
updateSession(id, data)PUT /api/sessions/:idUpdate session metadata
deleteSession(id)DELETE /api/sessions/:idDelete a session

Templates

MethodEndpointDescription
getTemplates()GET /api/templatesList all templates
getTemplate(id)GET /api/templates/:idGet a single template
createTemplate(data)POST /api/templatesCreate a new template
updateTemplate(id, data)PUT /api/templates/:idUpdate a template
deleteTemplate(id)DELETE /api/templates/:idDelete a template
syncCommunity()POST /api/templates/syncSync community templates
getCategories()GET /api/templates/categoriesList template categories

Settings

MethodEndpointDescription
getSettings()GET /api/settingsGet current settings
updateSettings(data)PUT /api/settingsUpdate settings
testProvider(provider, config)POST /api/settings/testTest LLM provider connectivity

Models

MethodEndpointDescription
getModels()GET /api/modelsList available models
downloadModel(name)POST /api/models/downloadDownload a model (SSE streaming)
activateModel(name)POST /api/models/activateSet the active model
deleteModel(name)DELETE /api/models/:nameDelete a downloaded model
cancelDownload(name)POST /api/models/cancelCancel an in-progress download

Generate

MethodEndpointDescription
generateStream(sessionId, messages, options)POST /api/generate/streamStream LLM response (SSE)
generate(sessionId, messages, options)POST /api/generateSingle-shot LLM response

Cloud STT

MethodEndpointDescription
transcribeAudio(blob)POST /api/stt/transcribeUpload a recorded audio Blob (webm/ogg/wav) and receive the transcript string

GitHub Copilot Auth

MethodEndpointDescription
startCopilotAuth()POST /api/auth/copilot/startStart the OAuth device flow; returns { deviceCode, userCode, verificationUri, interval, expiresIn }
pollCopilotAuth(deviceCode, providerName?)POST /api/auth/copilot/pollPoll for authorization; returns raw response to handle pending: true without throwing
getCopilotStatus()GET /api/auth/copilot/statusCheck if a Copilot provider is connected
disconnectCopilot()POST /api/auth/copilot/disconnectRemove the stored Copilot token and provider

Health

MethodEndpointDescription
health()GET /api/healthServer health check

Streaming APIs

generateStream

Returns an AsyncGenerator<string> that yields Server-Sent Event (SSE) chunks as they arrive from the LLM.

async function* generateStream(
sessionId: string,
messages: Message[],
options?: GenerateOptions
): AsyncGenerator<string>

Usage:

for await (const chunk of api.generateStream(sessionId, messages)) {
// Each chunk is a text fragment of the response
appendToMessage(chunk);
}

The generator supports abort via AbortSignal passed in options.

downloadModel

Also uses SSE streaming, but yields structured progress events:

interface DownloadProgress {
speed: string; // e.g. "12.5 MB/s"
eta: string; // e.g. "2m 30s"
progress: number; // 0-100
status: string; // "downloading" | "complete" | "error"
}

This allows the UI to display a real-time download progress bar with speed and estimated time remaining.