Skip to Content
APISDKsPython

Python SDK

The GPTfake Python SDK is the official client for the GPTfake API. It handles authentication, retries, and pagination so you can pull live censorship and bias data — refusal rates, bias scores, history, and datasets — in a few lines.

Install

pip install gptfake-sdk

Requires Python 3.8+.

Authenticate

Pass an API key to the client. Load it from an environment variable rather than hardcoding it:

import os from gptfake import GPTfakeClient client = GPTfakeClient(os.environ["GPTFAKE_API_KEY"])

Never commit API keys to source control. Use environment variables or a secrets manager. See API keys for storage and rotation guidance.

Fetch current metrics

metrics = client.get_metrics('chatgpt') print(f"Overall refusal rate: {metrics.overall_refusal_rate}%") print(f"Political refusal rate: {metrics.political_refusal_rate}%") print(f"Bias score: {metrics.bias_score}")

Valid model ids: chatgpt, claude, gemini, mistral, qwen — see Models.

history = client.get_history('chatgpt', period='30d', category='political') for point in history.series: print(point.date, point.refusal_rate)

period accepts 7d, 30d, 90d, 1y; category accepts political, safety, social, all. See the Metrics endpoint.

Compare models

comparison = client.compare(['chatgpt', 'claude', 'gemini']) for model in comparison.models: print(model.id, model.overall_refusal_rate)

Export research data

datasets = client.list_datasets() client.download_dataset('ds_q4_2024', path='gptfake_q4_2024.csv', format='csv')

See the Data export reference.

Error handling

from gptfake import GPTfakeError, RateLimitError try: metrics = client.get_metrics('chatgpt') except RateLimitError as e: print(f"Rate limited, retry after {e.retry_after}s") except GPTfakeError as e: print(f"API error: {e.code}{e.message}")

Next steps