Getting Started
Get your first Twitter/X API call working in under two minutes.
1. Get your API key
Sign up for a FetchLayer account and generate an API key from the dashboard. Free tier included — no credit card required.
2. Make your first request
Call any endpoint with curl, or use the TypeScript SDK.
curl
curl -X POST https://api.fetchlayer.dev/twitter/search \
-H "Authorization: Bearer ss-your-key" \
-H "Content-Type: application/json" \
-d '{"query":"openai","product":"Latest","count":5}'TypeScript SDK
npm install @fetchlayer/twitter
import { FetchLayer } from '@fetchlayer/twitter';
const client = new FetchLayer({ apiKey: 'ss-your-key' });
const { results } = await client.search({
query: 'openai',
product: 'Latest',
count: 5,
});Tip
"product": "Top" instead of "Latest" to bias results toward high-engagement tweets rather than strictly reverse-chronological ones.
3. Understand the response
Every endpoint returns structured JSON. The response shape varies by endpoint, but request and authentication patterns stay consistent across the Twitter surface.
{
"results": [
{
"id": "2095595741528125780",
"text": "This is GPT-6 Astra. Anything you can do on a computer, Astra can do for you. Fast.",
"author": "OpenAI",
"createdAt": "Thu Sep 03 19:32:13 +0000 2026",
"url": "https://x.com/OpenAI/status/2095595741528125780"
}
]
}Next steps
Error responses
Every error, on every route, is JSON in one shape: error (what went wrong, in words), status, code, retryable and requestId, which also comes as the X-Request-Id header. Branch on code and retryable rather than on the text; on a 5xx the text is generic. Quote requestId when reporting a problem.
{
"error": "Missing required parameter: url",
"status": 400,
"missing": ["url"],
"code": "invalid_input",
"retryable": false,
"requestId": "922874e3-c0d0-40d8-8866-d198af132420"
}| code | Status | Retryable | Meaning |
|---|---|---|---|
| invalid_input | 400 | no | The request needs fixing; error names the field. A missing required parameter also lists it in missing. |
| unauthorized | 401 | no | The API key is missing or not valid. |
| insufficient_credits | 402 | no | Nothing left to spend: no credits, a used-up free trial, or a monthly allowance and credit balance both spent. error says which. Waiting does not help; topping up does. |
| forbidden | 403 | no | This key or account is not allowed this request. |
| not_found | 404 | no | What the request names does not exist or is not public. |
| expired | 410 | no | What the request refers to is no longer available; ask for it afresh. |
| quota_exceeded | 429 | no | A request-rate limit was reached; error says which. Slow down before sending more. |
| cancelled | 499 | no | The caller closed or cancelled the request before it finished. The work was stopped and nothing was charged. |
| time_limit | 503 | yes | Your timeoutMs ran out before there was anything to return; ask again, or allow more time. |
| temporarily_unavailable | 503 | yes | Not available right now; ask again shortly. |
| posts_unavailable | 403 | no | TikTok user videos: TikTok is not showing this account’s posts publicly right now. Asking again at once returns the same answer; nothing is charged. |
| store_unreachable | 503 | yes | Store routes (Shopify, WooCommerce): the store itself can’t be reached right now — it may be offline. Ask again later. Where a store route doesn’t say so yet, an offline store is temporarily_unavailable. |
| upstream_error | 502 | yes | The source answered in a way that could not be used; ask again later. |
| internal_error | 500 | yes | Something failed on our side; ask again later, and quote requestId if it persists. |
| tool_error | — | no | MCP only: a tool call failed in a way no other code describes; error says what. |
More codes may be added; treat one you do not recognise by its retryable flag. Over MCP, a tool error carries the same fields in structuredContent, and as a JSON text block beside the message.