JavaScript SDK
The GPTfake JavaScript SDK is the official client for the GPTfake API, for Node.js and TypeScript. It handles authentication, retries, and pagination so you can pull live censorship and bias data — refusal rates, bias scores, history, and datasets — with a clean async API.
Install
npm install @gptfake/sdkRequires Node 18+. Ships with TypeScript types.
Authenticate
Pass an API key to the client. Keep the key on the server — never ship it in browser code:
import { GPTfakeClient } from '@gptfake/sdk';
const client = new GPTfakeClient(process.env.GPTFAKE_API_KEY);API keys are server-side secrets. Do not embed them in client-side bundles. For browser apps acting on behalf of users, use OAuth 2.0 and keep the secret on your backend.
Fetch current metrics
const metrics = await client.getMetrics('chatgpt');
console.log(`Overall refusal rate: ${metrics.overallRefusalRate}%`);
console.log(`Political refusal rate: ${metrics.politicalRefusalRate}%`);
console.log(`Bias score: ${metrics.biasScore}`);Valid model ids: chatgpt, claude, gemini, mistral, qwen — see Models.
Historical trends
const history = await client.getHistory('chatgpt', {
period: '30d',
category: 'political',
});
for (const point of history.series) {
console.log(point.date, point.refusalRate);
}period accepts 7d, 30d, 90d, 1y; category accepts political, safety, social, all. See the Metrics endpoint.
Compare models
const comparison = await client.compare(['chatgpt', 'claude', 'gemini']);
for (const model of comparison.models) {
console.log(model.id, model.overallRefusalRate);
}Export research data
const datasets = await client.listDatasets();
const csv = await client.downloadDataset('ds_q4_2024', { format: 'csv' });See the Data export reference.
Error handling
import { GPTfakeError, RateLimitError } from '@gptfake/sdk';
try {
const metrics = await client.getMetrics('chatgpt');
} catch (err) {
if (err instanceof RateLimitError) {
console.log(`Rate limited, retry after ${err.retryAfter}s`);
} else if (err instanceof GPTfakeError) {
console.log(`API error: ${err.code} — ${err.message}`);
}
}Next steps
- Python SDK
- Monitoring API reference
- Back to the API overview