# REST API (https://docs.cochl.ai/docs/pro/rest-api)



Cochl.Sense Pro is a REST API over HTTPS. The [Python library](https://docs.cochl.ai/docs/pro/getting-started&#x29; is a thin wrapper around it, so anything that can send an HTTP request can use Pro directly — Node.js, Go, Java, a shell script, or a coding agent. This page covers the calls you need. Every endpoint, field and status code is also listed in the &#x2A;*[API reference](https://integration.cochl.ai/redoc)**.

The base URL is `https://integration.cochl.ai/api/v1`.

## 1. Authentication [#1-authentication]

Send your project key in the `X-Api-Key` header on every request. Find it on your project’s home on the [Dashboard](https://dashboard.cochl.ai/) under **Call it from your app** ([Getting Started → Get your project key](https://docs.cochl.ai/docs/pro/getting-started#2-get-your-project-key)). Keep it server-side.

Speaker registration uses a different key, the organization key, in `X-Org-Key` — see [Custom speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile).

## 2. Endpoints [#2-endpoints]

| Method | Path                        | What it does                                                                               |
| ------ | --------------------------- | ------------------------------------------------------------------------------------------ |
| `POST` | `/analyze_file`             | Start a job from an uploaded audio or video file (multipart).                              |
| `POST` | `/analyze`                  | Start a job from raw audio sent as base64 float32 PCM (JSON).                              |
| `GET`  | `/jobs/{job_id}/stream`     | Follow a job as Server-Sent Events until it finishes.                                      |
| `GET`  | `/jobs/{job_id}`            | Read a job’s status, and its result once it’s done.                                        |
| `GET`  | `/jobs/{job_id}/result_url` | A download link for the stored result JSON, valid for one hour.                            |
| `GET`  | `/jobs`                     | Your project’s jobs, newest first (`page`, `page_size`, `status`, `from_date`, `to_date`). |
| `GET`  | `/tags`                     | The sound tags your project’s model returns, with each tag’s default threshold.            |

## 3. Send audio [#3-send-audio]

### Upload a file [#upload-a-file]

`POST /analyze_file` takes `multipart/form-data` with two fields: `audio` (the file) and `options` (a JSON string, optional).

```bash
curl -s https://integration.cochl.ai/api/v1/analyze_file \
  -H "X-Api-Key: $COCHL_KEY" \
  -F audio=@sample.wav \
  -F 'options={"sound_event_detection": true, "speech_analysis": true, "audio_insights": true}'
# {"job_id": "550e8400-e29b-41d4-a716-446655440000", "status": "accepted", "created_at": "..."}
```

The server reads WAV, FLAC and OGG directly and converts other formats with FFmpeg (MP3, M4A, MP4 and anything else FFmpeg can decode; for a video, the audio track). Multichannel audio is mixed down to mono.

### Send samples you already have in memory [#send-samples-you-already-have-in-memory]

`POST /analyze` takes JSON: `audio_data` is the audio as **float32 PCM, base64-encoded**, `samplerate` its sample rate, and `options` the same object as above.

```json
{
  "audio_data": "<base64 of float32 PCM>",
  "samplerate": 16000,
  "options": { "sound_event_detection": true, "speech_analysis": false, "audio_insights": false }
}
```

Both calls answer right away with a `job_id`; the analysis runs in the background.

## 4. Get the result [#4-get-the-result]

### Stream it (recommended) [#stream-it-recommended]

`GET /jobs/{job_id}/stream` with `Accept: text/event-stream` sends events until the job finishes, for up to 10 minutes:

| Event            | When                                                                           | Data                                                                             |
| ---------------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
| `metadata`       | First                                                                          | The input audio and any `warnings`                                               |
| `progress`       | Each time a service finishes                                                   | `{"completed_services": [...], "pending_services": [...]}`                       |
| `partial_result` | Right after each `progress`                                                    | The result block of the service that just finished (only services you turned on) |
| `completed`      | At the end                                                                     | The full result                                                                  |
| `error`          | The job failed, or 10 minutes passed (`Stream timeout`; the job keeps running) | `{"error": "..."}`                                                               |

Audio insights arrives only in `completed`; if you turn on audio insights alone, no `progress` events are sent and you get `metadata` and then `completed`. A long file can take more than 10 minutes — when the stream ends with `Stream timeout`, poll `GET /jobs/{job_id}` for the result. A project can keep up to **20** streams open at once.

### Or poll [#or-poll]

`GET /jobs/{job_id}` returns `status` (`accepted`, `processing`, `completing`, `completed` or `failed`) with `metadata`, and the `result` once the job is `completed`. Keep polling until it is `completed` or `failed`. Polling every few seconds is the simpler choice when you follow many jobs at once.

Results are kept for **24 hours** in the job response; after that the response carries a summary, and `GET /jobs/{job_id}/result_url` gives a one-hour download link to the stored result.

### Node.js example [#nodejs-example]

No SDK is needed in Node 18 and later; `fetch`, `FormData` and streams are built in. Save the code as `call.mjs` (it uses `import` and top-level `await`, which need an ES module) and run `node call.mjs`.

```js
import { readFile } from "node:fs/promises";

const KEY = process.env.COCHL_KEY;
const HOST = "https://integration.cochl.ai/api/v1";

const form = new FormData();
form.set("audio", new Blob([await readFile("sample.wav")]), "sample.wav");
form.set("options", JSON.stringify({ sound_event_detection: true, speech_analysis: true, audio_insights: true }));

const { job_id } = await fetch(`${HOST}/analyze_file`, {
  method: "POST", headers: { "X-Api-Key": KEY }, body: form,
}).then((r) => r.json());

const res = await fetch(`${HOST}/jobs/${job_id}/stream`, {
  headers: { "X-Api-Key": KEY, Accept: "text/event-stream" },
});
let buf = "", done = false;
for await (const chunk of res.body.pipeThrough(new TextDecoderStream())) {
  buf += chunk;
  const lines = buf.split("\n"); buf = lines.pop();
  for (const line of lines) {
    if (line.startsWith("event: ")) done = line.slice(7).trim() === "completed";
    else if (done && line.startsWith("data: ")) console.log(JSON.parse(line.slice(6)));
  }
}
```

Your project’s Overview on the Dashboard shows this request in **cURL**, **Python** and **Node.js** with your key filled in, and an **Agent prompt** that briefs a coding agent on the same API. Its **Get started** button opens the same steps with code that downloads a Cochl sample first, so it runs as pasted.

## 5. Options [#5-options]

| Option                   | Default        | What it does                                                                                                                             |
| ------------------------ | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `sound_event_detection`  | `true`         | [Sound event detection](https://docs.cochl.ai/docs/pro/sound-event-detection)                                                                                 |
| `speech_analysis`        | `false`        | [Speech analysis](https://docs.cochl.ai/docs/pro/speech-analysis): transcript with speakers                                                                   |
| `audio_insights`         | `false`        | [Audio insights](https://docs.cochl.ai/docs/pro/audio-insights); works on its own                                                                             |
| `speech_lang`            | `"multi"`      | Not applied: the spoken language is detected automatically. A value other than `multi` adds a warning to `metadata.warnings`             |
| `speaker_profile`        | `true`         | Name registered speakers ([Custom speaker profile](https://docs.cochl.ai/docs/pro/speech-analysis/custom-speaker-profile)); off when `speech_analysis` is off |
| `sound_event_tags`       | all tags       | Return only these tags ([details](https://docs.cochl.ai/docs/pro/sound-event-detection#keep-only-some-tags))                                                  |
| `sound_event_thresholds` | model defaults | Detection threshold per tag, 0 to 1 ([details](https://docs.cochl.ai/docs/pro/sound-event-detection#adjust-detection-thresholds))                             |

Only sound event detection is on by default; turn on speech analysis and audio insights when you need them. Any combination works as long as at least one service is on — turning all three off returns `400` ([No services selected](https://docs.cochl.ai/docs/pro/error-codes#no-services-selected)). Only sound event detection is billed; speech analysis and audio insights are free for now ([Usage & pricing](https://docs.cochl.ai/docs/pro/getting-started#5-usage--pricing)). The Python library (`cochl` 2.0.3) always sends all three flags and defaults each to `true`, so its defaults differ from these — see [Valid service combinations](https://docs.cochl.ai/docs/pro/getting-started#4-valid-service-combinations). An option the API doesn’t know returns `422`.

## 6. Limits [#6-limits]

| Limit                             | Value                            | Past it                                                                  |
| --------------------------------- | -------------------------------- | ------------------------------------------------------------------------ |
| Audio length                      | 59 minutes per request           | `400` [audio too long](https://docs.cochl.ai/docs/pro/error-codes#audio-too-long)             |
| Request body                      | 1 GiB                            | `413`                                                                    |
| Jobs in progress per organization | 1 on the trial, 10 on paid plans | `429` — wait for a job to finish                                         |
| Open result streams per project   | 20                               | `429` — close one, or poll instead                                       |
| Trial allowance                   | 20 minutes in total              | `402` [usage limit exceeded](https://docs.cochl.ai/docs/pro/error-codes#usage-limit-exceeded) |

All responses and error messages are listed in [Error codes](https://docs.cochl.ai/docs/pro/error-codes).
