# Lovable (/docs/integrations/lovable) Pull social media data into Lovable without writing a server. You can build an app in Lovable that shows SocialCrawl data. The key stays in a Lovable secret and a server function makes the call, so the browser never sees it. Setup takes three steps: add the secret, send the prompt, test the app. ## Before you start Create an API key in the dashboard under API Keys. Lovable stores secrets encrypted and injects them into your edge functions, so they never reach the browser. Add the key as a secret named `SOCIALCRAWL_API_KEY`, and never paste it into a prompt or a file. Prove the key with a call that costs nothing: ```bash title="Check the key (0 credits)" curl "https://www.socialcrawl.dev/v1/credits/balance" \ -H "x-api-key: sc_your_key_here" ``` A reply with `"success": true` and your balance in `data.balance` means the key works. ## Connect Paste a prompt that names the endpoint and the rule about the key: ```text title="Prompt" Add a page that shows the 10 latest videos of a TikTok account. Call https://www.socialcrawl.dev/v1/tiktok/profile/videos?handle=mrbeast with the query parameter handle (default: mrbeast) from a server function. Send the key in the x-api-key header, read from the secret SOCIALCRAWL_API_KEY. Never call SocialCrawl from the browser and never put the key in frontend code. Show the rows in data.items. If the response has success set to false, show error.message in a toast. ``` Change the endpoint and the field list to build another view. Browse the [platform directory](/platforms) to find endpoints. ## Read the answer Every response has the same shape. Branch on `success`. A list puts its rows in `data.items`, and `pagination.next_cursor` is the token for the next page. ```json title="Response (trimmed)" { "success": true, "data": { "items": [{ "id": "7654638524729216287" }] }, "pagination": { "next_cursor": "sc.eyJ2Ijoy…", "has_more": true }, "credits_used": 1, "credits_remaining": 99 } ``` Ask Lovable for a Load more button that sends `next_cursor` back as `cursor`, and hides itself when `has_more` is `false`. See [Pagination](/docs/pagination.md). ## When it stops The server function should pass a refused call to the browser so the app can show it. Your prompt already asks for a toast with `error.message`. When credits run out, the answer is a 402 with `error.type` set to `INSUFFICIENT_CREDITS`. Ask for the toast to include `error.details.checkout_url`, the link that opens checkout. When the link is absent, `error.details.top_up_url` opens the billing page. A 401 means the secret is missing or wrong, which is a different message. Never retry a 402, because it fails until credits are added. Retry a 429 after the seconds in the `Retry-After` header, and a 502, 503 or 504 after a short backoff. See [Errors](/docs/errors.md). ## What a run costs It depends on the endpoint, and some endpoints are priced by what they return. [Endpoint pricing](/docs/endpoint-pricing.md) lists each one, and [Credits](/docs/credits.md) explains cache hits and refunds. Every visitor who opens the page triggers a call on your account unless you cache it. `GET /v1/utility/estimate` quotes a call for 0 credits. ## Keep the key off the page Secrets in frontend code are visible to every visitor. Three rules keep yours safe: - The key lives only in the secret and is read in server code. - The browser calls your function, never `socialcrawl.dev`. - The prompt never contains the key. - [Errors](/docs/errors.md): Every error code, with the fix and whether to retry. - [Authentication](/docs/authentication.md): Where the key goes and where it must never go. - [Endpoint pricing](/docs/endpoint-pricing.md): What each endpoint costs before visitors trigger it.