# Use the API and webhooks

> Create an API key, call the API from your code and get a webhook when a forecast finishes.

Part of the Prolepsia docs: Share and connect.
Video: [Use the API and webhooks](https://app.prolepsia.com/docs/videos/api.mp4), 2:07, with [captions](https://app.prolepsia.com/docs/videos/api.vtt).
This guide as a web page: https://app.prolepsia.com/docs/api

## Steps

1. Open Settings, choose API and AI clients, then Create new key.
2. Name the key, tick what it may do, choose when it expires and choose Create key.
3. Copy the key straight away. Prolepsia shows it only once.
4. Choose API reference, then Authorize, and paste your key to try calls from the browser.
5. Create a question with a POST to /api/v1/external/questions.
6. Start a forecast with a POST to /api/v1/external/questions/{question_id}/forecasts. It returns a task ID straight away.
7. Read the forecast with a GET to /api/v1/external/forecasts/{task_id} until its status is completed, failed or cancelled.
8. To skip polling, open the Webhooks tab in Settings and choose Add webhook. Prolepsia calls your server when a forecast finishes.

## Good to know

- Send the key in the Authorization header as Bearer, or in the X-Api-Key header.
- Check each webhook call with its signing secret, which Prolepsia shows once when you add the webhook.

## What the video says

To call Prolepsia from your own code, create an API key. In Settings, on API and AI clients, choose Create new key. Name the key, choose what it may do, and choose when it expires. Choose Create key, and copy the key straight away. Prolepsia shows it only once. API reference opens the full documentation. Choose Authorize and paste your key, and you can try every call from the browser. For example, create a question by sending its title, type and resolution criteria. Prolepsia answers with the new question and its ID. Then start a forecast for it. The call returns straight away, with a task ID that you poll for the result. Poll the forecast until its status is completed. The finished forecast carries the probability, the report at all three lengths, and the sources. Instead of polling, you can add a webhook. Prolepsia then calls your server when a forecast finishes, with a signature you can check. Set one up on the Webhooks tab in Settings, or through the API.

## Links

- [Read the API guide](https://app.prolepsia.com/docs/developers/api)
- [Read the webhooks guide](https://app.prolepsia.com/docs/developers/webhooks)
- [Open the API reference](https://app.prolepsia.com/api/external/docs/)
- [Open Webhooks](https://app.prolepsia.com/settings?tab=webhooks)

Every Prolepsia guide is listed at https://app.prolepsia.com/llms.txt.
