# Compatibility

> The earlier request forms the Inola API still accepts next to POST /v1/infer, what each one takes and returns, and the equivalent POST /v1/infer call.

This page lists the request forms the Inola API accepts besides `POST /v1/infer`: the routes of its earlier API and
the forms of other APIs, kept so that existing clients and SDKs work without changes. New code uses
[`POST /v1/infer`](https://inola.ai/docs/reference/api.md#post-v1infer); every example in this documentation does.

## What the routes share

A request to any route below is served exactly as the equivalent `POST /v1/infer` request: the same
[API key](https://inola.ai/docs/reference/glossary.md#api-key) and `inference` permission, the same models, versions, prices, limits and billing,
the same response headers. Only the shape of the request and response body differs.

- **Errors** have the usual form `{"error": {"code", "message"}}` with the codes of [Error codes](https://inola.ai/docs/reference/errors.md). The
  `invalid_request` messages name the fields of the route's own form (`threshold`, not `options.threshold`).
- **Models.** Each route serves only the models listed for it; another model returns
  [`404 model_not_found`](https://inola.ai/docs/reference/errors.md#model_not_found).
- **The `model` field of the response** names the exact version as one string: `cordon-mini-2.2.1`.
- `GET /v1/models` is the same for every client.

| route | form | models |
|---|---|---|
| `POST /v1/detect` | the earlier detection API of Inola | `cordon-mini` |
| `POST /v1/decide` | the System One form of the Jev API | `decider-mini` |
| `POST /v1/systemone` | the same, at the path used by TypeSafe API clients | `decider-mini` |
| `POST /v1/chat/completions` | the OpenAI chat completions form, for a closed question | `decider-mini`, `cordon-mini` |

## POST /v1/detect

The flat detection form: the fields of `input` and `options` sit at the top level of the request, and the fields of
the detector's answer (`output.answers.injection`) at the top level of the response, under their earlier names.

| field of `/v1/detect` | field of `/v1/infer` |
|---|---|
| `model` (name, optionally with version: `cordon-mini-2.2.1`) | `model` (and `version`) |
| `text` | `input.state` (the route sends it as the earlier `input.text`) |
| `threshold` | `options.threshold` |
| `question` (optional, default `ipi`, also when `null`) | `input.questions.injection.instructions`: a [kind of detection](https://inola.ai/docs/reference/api.md#detector-questions); the answer keeps the flat fields below |

```bash
curl -sS "https://api.inola.ai/v1/detect" \
  -H "Authorization: Bearer $INOLA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "cordon-mini", "text": "Meeting notes, 14 October: the vendor contract renews on 1 March.", "threshold": 0.5}'
```

```json
{
  "id": "req_01JBXQ7M3T8K2V9R4N6PZC5HDA",
  "is_injection": false,
  "score": 0.01,
  "threshold": 0.5,
  "verdicts": {"fpr_1e-03": false, "fpr_1e-04": false},
  "n_tokens": 16,
  "model": "cordon-mini-2.2.1",
  "latency_ms": 36
}
```

| field of the response | field of `/v1/infer` |
|---|---|
| `is_injection` | `output.answers.injection.verdict` |
| `score` | `output.answers.injection.noul` |
| `threshold` | `output.answers.injection.threshold` |
| `verdicts` | `output.answers.injection.verdicts` |
| `id` | `id` |
| `model` | `model` and `version`, joined with `-` |
| `n_tokens` | `usage.input_tokens` |
| `latency_ms` | `usage.latency_ms` |

The equivalent call:

```bash
curl -sS "https://api.inola.ai/v1/infer" \
  -H "Authorization: Bearer $INOLA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "cordon-mini", "input": {"state": "Meeting notes, 14 October: the vendor contract renews on 1 March."}, "options": {"threshold": 0.5}}'
```

## POST /v1/decide and POST /v1/systemone

The System One request of the Jev API, so that clients and SDKs built for it work after a change of the base URL.
Both paths take the same body and return the same response. The whole request body becomes `input` of the
`/v1/infer` request: `state`, `questions` and the other fields of the form.

| field of `/v1/decide` | field of `/v1/infer` |
|---|---|
| `model` (`decider-mini`, optionally with version) | `model` (and `version`) |
| `state` | `input.state` |
| `questions` | `input.questions` |
| other fields of the form | the same fields in `input` |

| field of the response | field of `/v1/infer` |
|---|---|
| the result fields of the form (`answers` and the rest) | the same fields in `output` |
| `id` | `id` |
| `model` | `model` and `version`, joined with `-` |
| `usage.input_tokens` | `usage.input_tokens` |
| `usage.output_tokens` | `usage.output_tokens` |
| `latency_ms` | `usage.latency_ms` |

The equivalent call, with the state and questions of the request inside `input`:

```bash
curl -sS "https://api.inola.ai/v1/infer" \
  -H "Authorization: Bearer $INOLA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "decider-mini", "input": {"state": "Order 1042: paid, shipped on 3 March, delivered on 5 March.", "questions": {"delivered": {"type": "noul", "instructions": "Has the order been delivered?", "criteria": {"true": "the order was delivered", "false": "the order was not delivered"}}}}}'
```

## POST /v1/chat/completions

The OpenAI chat completions form, so that a closed step of a pipeline written for an OpenAI client changes only its
base URL, key and model name; [Replacing an OpenAI call](https://inola.ai/docs/guides/replace-an-openai-call.md) has the examples. The
models answer one closed question, they do not write text.

| request | equivalent in `POST /v1/infer` |
|---|---|
| `decider-mini`: the `system` message, or without one the first line of the last `user` message | the question's `instructions` |
| `decider-mini`: the last `user` message | `input.state` |
| `decider-mini`: no `response_format` | a `noul` question |
| `decider-mini`: `response_format.json_schema` with one property — `boolean`, `string` with `enum`, `integer` 0..N (N up to 9), `number` 0..1 | a `noul`, `choice` (the enum values as options) or `score` question (levels 0..N, or 0, 0.25, 0.5, 0.75, 1) under the property's name |
| `cordon-mini`: the last `user` message, or the last message when it is a `tool` message | `input.state`, kind of detection `ipi` |
| every question | asked with "don't know" allowed (`allow_unsure: true`) |

| response | from the `POST /v1/infer` reply |
|---|---|
| `choices[0].message.content` | without `response_format`: `yes` or `no`; with it: `{"<property>": <value>}` — the verdict (`cordon-mini`) or `noul` at 0.5, the choice, or the expected score on the property's scale; `"unsure"` when "don't know" is the most probable answer |
| `inola` | the answer's fields (`noul`, `probabilities`, `score`, `confidence`, `probabilities_with_unsure`; `threshold`, `verdict`, `verdicts` for `cordon-mini`) and `unsure` (boolean) |
| `usage.prompt_tokens`, `usage.completion_tokens`, `usage.total_tokens` | `usage.input_tokens`, `usage.output_tokens` and their sum |
| `model` | `<model>-<version>` |

`stream: true` returns server-sent events: one `chat.completion.chunk` with the answer, one with `usage` and empty
`choices` when `stream_options.include_usage` is `true`, then `data: [DONE]`. `tools`, `n` above 1, `logprobs`, image or audio content, `response_format` of type `json_object`, a
`string` property without `enum` and a schema with more than one property return `400 invalid_request` with the
reason. Sampling and bookkeeping fields (`temperature`, `top_p`, `max_tokens`, `max_completion_tokens`, `seed`,
`stop`, `presence_penalty`, `frequency_penalty`, `user`, `metadata`) are accepted and do not change the answer. Batches
take the `POST /v1/infer` form; chat completion lines in a batch file are not supported.

## Batches

Batch lines are written in the `POST /v1/infer` form ([Batches](https://inola.ai/docs/guides/batches.md#the-input-file)). The earlier
flat form of the lines is still accepted, so files written for it work without changes: `body` holds the fields of
the model's earlier route at its top level, without the `input` and `options` envelope.

| model | fields of a flat `body` | route |
|---|---|---|
| `cordon-mini` | `model`; `text` (a string; an empty one is answered as clean); `threshold` (optional, 0 to 1); `question` (optional, a [detector question](https://inola.ai/docs/reference/api.md#detector-questions) name, default `ipi`) | `/v1/detect` |
| `decider-mini` | `model`, `state`, `questions` and the other fields of the System One form | `/v1/decide` |

```json
{"custom_id": "doc-1", "body": {"model": "cordon-mini", "text": "Meeting notes, 14 October: the vendor contract renews on 1 March.", "threshold": 0.5}}
```

- **One form per file.** A file mixes no forms: a line in the `POST /v1/infer` form after a flat one, or the other
  way round, is rejected at upload with its line number. A line is in the `POST /v1/infer` form when its `url` is
  `/v1/infer` or, without `url`, when `body.input` is an object.
- **`url` and `endpoint`.** Both stay optional. A flat line may carry the route of its model as `url`; `endpoint` of
  `POST /v1/batches` may be `/v1/infer` or that route, whatever the form of the lines. The batch object names the
  route of the file's model from the table above in `endpoint`, whichever form the lines use.
- **Results** of flat lines have the response form of the model's route above: for `cordon-mini` the form of
  [`POST /v1/detect`](#post-v1detect), for `decider-mini` the form of [`POST /v1/decide`](#post-v1decide-and-post-v1systemone).
  `model` names the exact version as one string (`cordon-mini-2.2.1`), and `invalid_request` errors of items name the flat
  fields (`text`, `threshold`).

```json
{"id": "batch_01JBY3M8V0X2Z4B6D8F0H2K4N6:1", "custom_id": "doc-1", "response": {"status_code": 200, "body": {"is_injection": false, "score": 0.01, "threshold": 0.5, "verdicts": {"fpr_1e-03": false, "fpr_1e-04": false}}}, "error": null}
```

## Next steps

- [API reference](https://inola.ai/docs/reference/api.md) — `POST /v1/infer` and every other endpoint.
- [Quickstart](https://inola.ai/docs/quickstart.md) — the first request in the main form.
- [Changelog](https://inola.ai/docs/changelog.md) — when the examples moved to `POST /v1/infer`.
