TypeScript SDK
Official TypeScript/JavaScript SDK for FirstHandAPI.
Installation
npm install @firsthand/sdkQuick Start
import { FirstHandClient } from '@firsthand/sdk';
const client = new FirstHandClient({ apiKey: 'fh_live_...' });
// Post a job
const job = await client.createJob({
type: 'data_collection',
description: 'Take a clear photo of any coffee cup from above. Must show the full cup.',
files_needed: 50,
accepted_formats: ['image/jpeg', 'image/png'],
price_per_file_cents: 75,
});
// Get approved files
const files = await client.getJobFiles(job.id);Configuration
const client = new FirstHandClient({
apiKey: 'fh_live_...',
baseUrl: 'https://api.firsthandapi.com', // default
timeout: 30_000, // 30s default
maxRetries: 3, // default
});Features
- Auto-retry — Exponential backoff with jitter on 429 and 5xx errors
- Idempotency — Automatic UUID generation for all POST requests
- Webhook verification —
verifyWebhookSignature()with timing-safe comparison
Methods
Jobs
createJob(body)— Post a content collection jobgetJob(jobId)— Get job by IDlistJobs(params?)— List jobs with filterscancelJob(jobId)— Cancel an open jobgetJobFiles(jobId, params?)— Get approved files for a jobgetJobSubmissions(jobId, params?)— List all submissions for a job
Submissions
listSubmissions(params?)— List submissions across all jobsgetSubmission(submissionId)— Get submission by IDgetSubmissionSummary(params?)— Aggregate submission metrics
API Keys
createApiKey(body)— Create a new API keylistApiKeys()— List API keysrotateApiKey(keyId)— Rotate with 24h overlaprevokeApiKey(keyId)— Revoke immediately
Webhooks
createWebhookEndpoint(body)— Create endpointlistWebhookEndpoints()— List endpointsgetWebhookEndpoint(id)— Get endpointupdateWebhookEndpoint(id, body)— Update endpointdeleteWebhookEndpoint(id)— Delete endpointrotateWebhookSecret(id)— Rotate signing secret
Webhook Events
listWebhookEvents()— List eventsreplayWebhookEvent(id)— Replay an event
Billing
getCreditBalance()— Current credit balancelistTransactions()— Transaction historypurchaseCredits(body)— Initiate Stripe Checkout
Organization
getSettings()— Get org settingsupdateSettings(body)— Update org settings