---
title: "Pick my best Fantacalcio lineup for the open matchweek"
method: POST
path: "/v1/fantasy/fantacalcio/me/optimize"
tags: ["fantasy"]
---

# Pick my best Fantacalcio lineup for the open matchweek

`POST /v1/fantasy/fantacalcio/me/optimize`

## Request

- Base URL: `https://api.predixsport.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.predixsport.com/v1/fantasy/fantacalcio/me/optimize`
- Auth: none declared

Runs the exact Classic lineup optimiser over your saved squad and the open matchweek, and appends one immutable recommendation. The answer is a whole LINEUP, not a ranking: it chooses the formation, the eleven and the order of the bench together, because the substitution rule scores the bench in the order you leave it and a formation that fits your best players is worth more than any single pick. `module` pins one formation instead. `forced_in` treats a player as a sure starter and `forced_out` leaves him out. Both take player codes from your own squad, and a code you do not own is refused rather than quietly ignored. The optimiser maximises the lineup's expected score UNDER YOUR LEAGUE'S SUBSTITUTION RULE (`selection_total`): a starter who does not play is replaced from the bench the way your league's `substitution_mode` says (same role only, or a module change when no same-role reserve has a vote), up to your league's limit, so a better player with a real chance of starting can start over a surer one when the bench covers him. It never starts a player less likely than not to start unless you force him. `expected_substitutions` and `hole_probability` say what that risk costs: the latter is the probability of not fielding eleven voted players after every substitution your league's mode allows, and the answer echoes the `substitution_mode` it was priced under. Present the lineup with `projected_points`, which is what it is worth if everybody plays, and keep `expected_defence` as its own line. `what_if` says what would change if a doubtful bench player were confirmed, and `ballottaggi` names the closest call in each role. This is advice: it writes a snapshot on Predixsport and nothing else. It never signs in to any fantasy platform and never submits your lineup. Requires mcp:read and fantasy:fantacalcio:write. The Fantacalcio workspace is in a private beta: this endpoint answers 403 for an account outside it.

## Headers

- `authorization` string, nullable

## Request body

- FantacalcioOptimizeRequest
  - `season` string, nullable: Omitted uses the latest season you saved.
  - `team` integer, nullable
  - `module` string, nullable: Pin one formation, e.g. '4-4-2'. Omitted lets the optimiser choose among the formations your league allows.
  - `forced_in` string[]: Players to treat as sure starters, as codes from your own squad. A code you do not own is refused rather than ignored.
  - `forced_out` string[]: Players to leave out, as codes from your own squad.

## Response `200`

Successful Response

- FantacalcioRecommendation
  - `snapshot_id` integer, required
  - `season` string, required
  - `team` integer, required
  - `giornata` integer, required
  - `created_at` string, date-time, required
  - `applied_at` string, date-time, nullable
  - `stale` boolean: True when the squad or the board moved after this advice was computed. Run the optimiser again rather than acting on it.
  - `policy_version` string, required
  - `module` string, required
  - `starters` string[], required
  - `bench_order` string[], required
  - `selection_total` number, required: The optimiser's own objective. Since policy_version fantacalcio-lineup-v3 it is the expected score of this eleven AND its bench under your league's substitution rule: a starter who does not play is replaced from the bench the way the league's substitution_mode says (same role only, or a module change when no same-role reserve has a vote), while your league's substitution limit lasts, plus the defence modifier weighted by the chance it is paid. Older snapshots (v2 and earlier) carry the plain sum of selection scores, which ignored substitutions.
  - `expected_substitutions` number: How many substitutions the league's rule is expected to make for this lineup. 0 on snapshots older than fantacalcio-lineup-v3.
  - `hole_probability` number: Probability of NOT fielding eleven voted players: at least one slot stays without a vote after every substitution the league's substitution_mode allows, because no eligible reserve is left on the bench or the substitution limit is spent. Since fantacalcio-lineup-v4 it follows the league's mode (a module change can fill a slot the same-role rule could not). 0 on snapshots older than fantacalcio-lineup-v3.
  - `substitution_mode` 'traditional' | 'hybrid' | 'dynamic': The substitution rule this advice was priced under, echoed from the league rules at the time. Snapshots older than fantacalcio-lineup-v4 report 'traditional', the same-role walk they were computed with.
  - `projected_points` number, required: What this eleven is worth if everybody in it plays: the starters' projected fantavoti plus the expected defence modifier. This is the number to show a reader.
  - `expected_defence` number, required: The defence modifier in points. Always shown separately.
  - `players` object, required
  - `ballottaggi` FantacalcioBallottaggio[]
    - `role` 'P' | 'D' | 'C' | 'A', required
    - `last_in` string, required
    - `first_out` string, required
    - `gap` number, required
  - `what_if` FantacalcioWhatIf[]
    - `player_code` string, required
    - `replaces` string[], required
    - `gain` number, required
  - `modules` FantacalcioModuleOption[]
    - `module` string, required
    - `expected_points` number, required
    - `expected_defence` number, required
  - `player_count` integer, required
  - `omitted_player_count` integer

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/predixsport/apis/predixsport-api.md) · [All operations](https://skmtc.dev/predixsport/apis/predixsport-api/llms.txt) · [OpenAPI document](https://skmtc.dev/predixsport/apis/predixsport-api/revisions/02014aee733d?raw)
