# SPDX License Detector API

> Identify a licence from its text (SPDX ID + similarity), parse and fix SPDX expressions, check dependency licences for your project, generate NOTICES.

- Endpoint: `GET | POST https://apibox.io.vn/v1/spdx-license`
- Category: Developer utilities
- HTML docs: https://apibox.io.vn/docs/spdx-license/ (Vietnamese: https://apibox.io.vn/vi/docs/spdx-license/)
- Online tool: https://apibox.io.vn/tools/spdx-license/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

`op=detect` (or just `text`): paste a LICENSE / COPYING file or a file header. The text is normalised like the SPDX matching guidelines (case, punctuation, bullets, copyright lines, British / American spellings) and compared with every licence of the SPDX License List (~700 texts) by word 3-gram Dice similarity: you get the `best` match with a confidence (exact ≥ 0.95, high, medium, low), the top `candidates` with how much of the text and of the licence is covered, `multiple_licences` when a file holds several (e.g. MIT + Apache-2.0), `SPDX-License-Identifier` tags and standard notices such as the Apache-2.0 or GPL "or any later version" headers.

`op=parse` with `expression`: "MIT OR (Apache-2.0 AND BSD-3-Clause)" becomes a tree with each licence’s category, OSI / deprecated flags and exceptions (`WITH Classpath-exception-2.0`); wrong names are corrected ("Apache 2" → Apache-2.0, "GPLv3" → GPL-3.0-or-later). `op=check` takes `dependencies` (`[{name, license}]` or `{name: expression}`), your `project_license` (an SPDX ID or `proprietary`), `distribution` (`binary`, `source`, `saas`, `internal`) and an optional `policy` (`allow`, `deny`, `deny_categories`): each dependency gets `ok`, `conditions` (attribution, NOTICE, file-level copyleft), `warning`, `conflict`, `denied` or `unknown` with reasons — e.g. GPL in a proprietary binary, AGPL in SaaS, Apache-2.0 under GPL-2.0-only; for OR the most permissive option is chosen.

`op=notice` turns `packages` (`[{name, version, license, copyright, url}]`) into a THIRD-PARTY-NOTICES text with each licence text once (`format=text` downloads it). `op=info` with `id` returns a licence (and its text with `include_text=true`); without `id` it lists the SPDX licences (`q`, `category`). Compatibility results are a reference, not legal advice.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `op` | body|query | string | no |  | `detect`, `parse`, `check`, `notice` or `info` (guessed from the other fields when omitted). |
| `text` | body | string | no |  | detect: licence text or file header (max 500 000 characters; also a text/plain body). |
| `top` | body|query | number | no | `5` | detect: number of candidates (1-20). |
| `expression` | body|query | string | no |  | parse: SPDX licence expression. |
| `dependencies` | body | array | no |  | check: [{name, license}] or {name: expression} (max 2000). |
| `project_license` | body | string | no |  | check: your licence (SPDX ID) or `proprietary` (default). |
| `distribution` | body | string | no | `binary` | check: `binary`, `source`, `saas` or `internal`. |
| `policy` | body | object | no |  | check: {allow: [ids], deny: [ids], deny_categories: ["strong-copyleft", "network-copyleft", …]}. |
| `packages` | body | array | no |  | notice: [{name, version, license, copyright, url, text}] (max 2000). |
| `id` | body|query | string | no |  | info: SPDX licence ID (case-insensitive); add include_text=true for the text. |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/spdx-license" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"op":"check","project_license":"proprietary","distribution":"binary","dependencies":[{"name":"react","license":"MIT"},{"name":"readline-sync","license":"GPL-3.0-only"},{"name":"sharp","license":"Apache-2.0"},{"name":"dual-lib","license":"GPL-2.0-only OR MIT"}]}'
```

## Example response

```json
{
  "project_license": "proprietary",
  "distribution": "binary",
  "overall": "conflict",
  "summary": {
    "conditions": 3,
    "conflict": 1
  },
  "results": [
    {
      "name": "react",
      "license": "MIT",
      "status": "conditions",
      "chosen": "MIT",
      "category": "permissive",
      "reasons": [
        "Keep the copyright notice and licence text (attribution)"
      ]
    },
    {
      "name": "readline-sync",
      "license": "GPL-3.0-only",
      "status": "conflict",
      "chosen": "GPL-3.0-only",
      "category": "strong-copyleft",
      "reasons": [
        "GPL-3.0-only: distributing a combined work requires releasing it under the GPL — incompatible with a proprietary project"
      ]
    },
    {
      "name": "sharp",
      "license": "Apache-2.0",
      "status": "conditions",
      "chosen": "Apache-2.0",
      "category": "permissive",
      "reasons": [
        "Keep the copyright notice and licence text (attribution)",
        "Apache-2.0: also keep its NOTICE file and mark modified files"
      ]
    },
    {
      "name": "dual-lib",
      "license": "GPL-2.0-only OR MIT",
      "status": "conditions",
      "chosen": "MIT",
      "reasons": [
        "Keep the copyright notice and licence text (attribution)"
      ]
    }
  ],
  "disclaimer": "Reference only, not legal advice; licence compatibility depends on how the code is used and distributed. Check the licence texts or ask a lawyer.",
  "spdx_list_version": "3.29.0"
}
```

## Use cases

- Identify the licence of a vendored library or a repository without a package manifest
- Fail a CI build when a dependency licence conflicts with your distribution model
- Produce the open-source licence report and NOTICE file a customer asks for
- Normalise messy licence fields ("Apache 2", "GPLv2+") to SPDX IDs

## FAQ

### Why are GPL-3.0-only and GPL-3.0-or-later both 100 % similar?

They share the same text: the "only" or "or later" choice is in the file headers. Look at standard_notices or the SPDX-License-Identifier.

### Is the compatibility check legal advice?

No. It applies common interpretations (e.g. FSF compatibility lists) and flags cases to review; ask a lawyer for important decisions.

### Which licence list version is used?

The latest SPDX License List release, refreshed weekly; spdx_list_version is in every response.
