Skip to main content

Run a full calibration + prediction against the AlphaGen REST API in under 5 minutes, using the bundled tutorial notebook.

API quickstart

This page walks you through the exact steps to run the bundled alphagen-tutorial.ipynb notebook end-to-end: create an API key, install the Python dependencies, point the notebook at the API, run it, and inspect the results in the webapp.

It reproduces your first calibration in Python — same dataset, same parameters, same model: alphagen-3, the default every plan can run. The notebook stays on the standard calibration path; the walkforward mode is an advanced option and is not used here.

Warning — the model field is enforced against your plan's allowed list. alphagen-2 is restricted to AlphaGen administrators and alphagen-1 is retired, so sending either returns 403. Leave the notebook on alphagen-3.

Info — full REST API reference (every endpoint, every payload schema, "Try it out" sandbox): api.alphagen.improm.ai/docs.

Before you start — team scope

Every AlphaGen resource (project, calibration, prediction) now lives inside a team. Your API token is bound to one specific team; every request made with the token acts on behalf of that team, sees only that team's projects, and counts against that team's plan quotas.

  • If you belong to a single team (typical solo signup), the "personal team" auto-created on registration is the default — nothing else to do.
  • If you belong to several teams, you will create one API token per team you want to script against.
  • Seat requirement — writing operations (calibrate, predict, create/delete/edit) require a builder or manager seat inside the team. viewer and guest seats can list and read only.
  • Ejection auto-revokes the token — if an admin removes you from the team the token is bound to, that token immediately returns 401 on every request.

1. Create an API key

  1. In the webapp, open Profile → API tokens (/account/api-tokens).
  2. Click + New token.
  3. Pick a name (e.g. notebook-tutorial), select the team the token should act on behalf of, and set an expiry (30 days is fine for a one-off run).
  4. Copy the token shown on screen immediately — it is displayed only once.

The token is a bearer credential. Treat it like a password: never commit it to git, never paste it into a shared notebook cell.

Tip — you can list every team you belong to (and confirm which team a token is bound to) via GET /account/teams. Sample response:

{
  "current_team_id": "e0b31…",
  "teams": [
    { "id": "e0b31…", "name": "My personal team", "seat": "manager", "is_personal": true },
    { "id": "a7c04…", "name": "Acme Trading",     "seat": "builder", "is_personal": false }
  ]
}

2. Install the Python dependencies

The notebook uses Python ≥ 3.10. From a fresh virtual environment:

pip install python-dotenv pandas requests openpyxl jupyter

openpyxl is required by pandas.read_excel; jupyter is what lets you open and run the .ipynb file.

3. Set up your environment variables

Create a .env file in the same folder as the notebook with the following three variables:

# .env
ALPHAGEN_TOKEN="<paste the token you copied at step 1>"
ALPHAGEN_API_URL="https://api.alphagen.improm.ai/api/v1/"
ALPHAGEN_WEBAPP_URL="https://alphagen.improm.ai"

Trailing slash on ALPHAGEN_API_URL is required — the notebook concatenates endpoint paths directly (f"{URL}model/calibrate").

The notebook loads these with python-dotenv in its first cell:

from dotenv import load_dotenv
load_dotenv(dotenv_path=".env")
TOKEN       = os.getenv("ALPHAGEN_TOKEN")
URL         = os.getenv("ALPHAGEN_API_URL")
WEBAPP_URL  = os.getenv("ALPHAGEN_WEBAPP_URL")

4. Download the notebook and the sample data

Download the tutorial notebookalphagen-tutorial.ipynb

German TTF futures prices — ttf.xlsxttf.xlsx

IFS Germany 1-day-ahead weather forecast — forecast_ifs_allemagne_step_24.xlsxforecast_ifs_allemagne_step_24.xlsx

The notebook reads the two spreadsheets from a data/ sub-folder (pd.read_excel("data/ttf.xlsx")), so the layout must be:

your-folder/
├── .env
├── alphagen-tutorial.ipynb
└── data/
    ├── ttf.xlsx
    └── forecast_ifs_allemagne_step_24.xlsx

Dropping the spreadsheets next to the notebook instead of inside data/ is the most common reason the third cell raises FileNotFoundError.

5. Run the notebook

Start Jupyter and open the notebook:

jupyter notebook alphagen-tutorial.ipynb

Run the cells top-to-bottom. Here is what each one does:

CellAction
Imports / env / projectLoads .env, builds the auth header, defines the _sanitize_payload helper, and POST /project/create?name=DEMO_PROJECT. The project is created inside the team the token is bound to. Re-running returns 409 with { "message": "project … already exists" } — that's expected.
Team checkGET /account/teams — prints the team your token is bound to and the seat you hold in it. Run it before anything else: a viewer or guest seat will fail at the calibration step.
Data loadingReads the two Excel files from data/. Splits the weather data into two virtual datasets (dataset_1 = temperature, dataset_2 = wind speed + precipitation).
To recordsConverts the DataFrames to lists of dictionaries and formats the dates as YYYY-MM-DD.
Calibration payloadBuilds parameters (backtest block + per-variable block) and the request body, with "model": "alphagen-3".
Calibration_sanitize_payload replaces any NaN/Inf with None so the JSON is well-formed, then POST /model/calibrate?project_name=DEMO_PROJECT. The next cell polls GET /model/fetch/calibration?calibration_id=<id> every 5 seconds until done == true and prints the dashboard URL.
Calibration inspectionPulls per-variable intensity series and the aggregated signal into a single DataFrame, plus a yearly-statistics table (sharpe / PnL / VaR ratio).
PredictionReuses the trained model: POST /model/predict?calibration_id=<id> with the same datasets — no model key, it is inherited from the parent calibration. Polls GET /model/fetch/prediction?prediction_id=<id> the same way.
Prediction inspectionSame shape as the calibration inspection, but on the prediction's results.

Note — a failed job also sets done = true (with failed = true), so the polling loops always terminate and print Calibration failed! rather than spinning.

Tip — every cell is independent once authentication has run. You can re-run the inspection cells without resubmitting the calibration.

Team scope on project names — the project_name parameter is resolved within the token's team. If two teams both contain a project called DEMO_PROJECT, each token only ever sees its own team's copy. To act on a different team's project you must use a token bound to that team.

On the demo dataset both jobs finish quickly — the calibration in well under a minute, the prediction faster still since the model is scored, not refitted. Larger datasets can take several minutes; the polling loops have no timeout.

6. View results in the webapp

The two polling cells print a Dashboard URL the moment the job finishes. Open it in the browser to see the same results visually — the intensity charts, the NAV-vs-benchmark backtest, the per-variable breakdown, and the prediction tables.

  • Calibration page: ${ALPHAGEN_WEBAPP_URL}/projects/DEMO_PROJECT/calibrations/<calibration_id>
  • Prediction page: ${ALPHAGEN_WEBAPP_URL}/projects/DEMO_PROJECT/calibrations/<calibration_id>/predictions/<prediction_id>

You can also navigate manually: My projects → DEMO_PROJECT → the row tagged tag-of-the-calibration → the linked prediction tag-of-the-prediction.

If a job fails, the polling cell prints Calibration failed! Check at your email for more information — the webapp's calibration row will show a red "failed" status and the same job page will surface the backend error message.

Troubleshooting

SymptomCause / fix
401 Unauthorized on every requestToken is wrong, expired, or has a stray newline. Re-copy from /account/api-tokens. If you were recently removed from the team the token is bound to, the token has been auto-revoked — create a new one under a team you still belong to.
403 Forbidden on /model/calibrate, /model/predict, /project/createYour seat inside the token's team is viewer or guest. Ask a manager of that team to raise your seat to builder (or use a token from a team where you already have builder rights).
403 on /model/calibrate mentioning a daily/model quotaThe team's plan cap has been hit (calibrations/day, allowed models, dataset size). Contact your team's manager or an AlphaGen admin.
400 with {"error": "invalid_payload", "details": []}The project was not resolved — project_name does not exist in the token's team. The empty details array is expected: the backend raises this one as a bare validation error, so the reason is not echoed back. Create the project first, from the same token.
404 on /model/calibrate (bare, HTML body)ALPHAGEN_API_URL is missing the trailing slash (e.g. https://…/api/v1 instead of https://…/api/v1/), so the path concatenation produces a URL that matches no route.
Polling loop never exitsThe backend job is still running — calibrations on bigger datasets can take a few minutes. Let it run; the loop has no timeout. A failed job still sets done = true, so this never means "the job crashed".
FileNotFoundError: data/ttf.xlsxThe two Excel files must sit in a data/ sub-folder next to the notebook — see the layout in step 4.
KeyError: 'payload' after model/calibrateThe backend returned an error wrapper (usually 401/403). Print res.text to inspect and match against the rows above.