<div class="section-label"><span class="num">02</span> MaxFit</div>
<div class="section-title">Solve for the strongest <em>fit</em>.</div>
`POST /maxfit` searches thresholds for the strongest fit on a fixed attribute set. Prefer a [[API/Clients/Introduction|language client]] unless you are writing HTTP yourself. For primary analysis, use [[API/Endpoints/Grid|Grid]]. What MaxFit means: [[Functions/MaxFit|MaxFit]].
**Call:** `POST /maxfit`
**Auth:** `x-api-key` header + `access_id` in the body
**Returns:** a receipt, then poll [[API/Endpoints/Results|Results]]
## Signature
```http
POST https://api.csanalytics.io/v3/rbp-engine/maxfit
```
Required JSON body:
```text
{
access_id,
y, # outcomes, N numbers
X # attributes, N rows of K numbers
}
```
Optional: `theta` and `options` ([[Settings/Options#MaxFitOptions|MaxFitOptions]]).
## Example
```python
import os, time, requests
base = "https://api.csanalytics.io/v3/rbp-engine"
headers = {
"x-api-key": os.environ["CSA_API_KEY"],
"Content-Type": "application/json",
}
payload = {
"access_id": os.environ["CSA_ACCESS_ID"],
"y": [0.1, 0.2, 0.3],
"X": [[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]],
}
receipt = requests.post(f"{base}/maxfit", headers=headers, json=payload).json()
job_id, job_code = receipt["job_id"], receipt["job_code"]
while True:
r = requests.get(f"{base}/results/{job_id}/{job_code}", headers=headers)
if r.status_code == 202:
time.sleep(2)
continue
r.raise_for_status()
print(r.json()["results"]["yhat"])
break
```
A successful POST returns a receipt: <span class="mono">job_id</span> and <span class="mono">job_code</span>. Client that wraps this loop: [[API/Clients/Python|Python]]. Example: [post_maxfit.py](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/python/examples/post_maxfit.py).
## Options
Put settings on `options`. Names match [[Settings/Options#MaxFitOptions|MaxFitOptions]]: shared Predict fields plus `objective` and `inner_parallel`. For logistic outcomes, set `prediction_scale` to `logistic`.
## Results
[[API/Endpoints/Results|Results]] include the winning forecast and fit. [[Results/Overview|Results]]
Full HTTP contract: [rbp-engine-api.json](https://github.com/CambridgeSportsAnalytics/rbp-engine-api-client/blob/main/openapi/rbp-engine-api.json).
## Related
- [[API/Introduction|API]] · [[API/Clients/Introduction|Clients]]
- [[API/Endpoints/Grid|Grid]] · [[API/Endpoints/PSR|PSR]]
- [[Functions/MaxFit|MaxFit]]
<div class="btn-row center">
<a class="btn-primary" href="/API/Clients/Python">Python client</a>
<a class="btn-ghost" href="/API/Endpoints/Grid">Grid</a>
</div>