# Code Detector API

> Code Detector identifies the programming language of any submitted code snippet. It returns the canonical language name, readable title, and standard file extension for the detected code.

**Endpoint:** `POST https://api.apiverve.com/v1/codedetector`  
**Category:** AI/Computer Vision  
**Cost:** 20 credits per call  
**Canonical page:** https://apiverve.com/marketplace/codedetector

## Overview

A code detector API for working out which programming language a snippet is written in. POST the raw code and get back the language identifier, a readable name such as "Python Code", and the usual file extension, so you can label pasted snippets, pick a syntax highlighter or name a file without asking the user.

Typical uses are code-sharing sites, chat and support tools that receive pasted code, documentation platforms that need the right highlighting, and pipelines that sort unlabelled files. Detection is done by an AI model reading the code, so it handles short or unusual snippets that a file extension or keyword list would miss.

The Free plan returns the language identifier, readable name and extension. Paid plans add detection confidence scores, the language family in upper case, programming paradigms (object-oriented, functional, procedural and similar) and execution classification, a flag for whether the language is normally compiled.

## Authentication

Every call carries your key in an `x-api-key` header. The same key works across the whole
APIVerve catalog — there are no per-API subscriptions. Responses always use the same three
top-level keys: `status`, `error`, and `data`.

## Example request

```bash
curl -X POST "https://api.apiverve.com/v1/codedetector" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code":"a = 5\nb = 6\nc = 7\n\n# calculate the semi-perimeter\ns = (a + b + c) / 2\n\n# calculate the area\narea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\nprint('\''The area of the triangle is %0.2f'\'' %area)"}'
```

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string | Yes | The code snippet you want to detect the programming language of. length 0-50000 |

## Response fields

- `likelihood` — number · Confidence score for code language detection (0.0 to 1.0) · (premium)
- `family` — string · Detected language name in upper case (same value as current)
- `current` — string · Detected programming language in lowercase format
- `readable` — string · Human-readable name of the detected programming language
- `extension` — string · Standard file extension for the detected language
- `paradigm` — string · Programming paradigm: object-oriented, functional, procedural, multi-paradigm · (premium)
- `isCompiled` — boolean · Whether the language is compiled or interpreted · (premium)

## Sample response

```json
{
  "status": "ok",
  "error": null,
  "data": {
    "likelihood": 0.99,
    "family": "PYTHON",
    "current": "python",
    "readable": "Python Code",
    "extension": ".py",
    "paradigm": "multi-paradigm",
    "isCompiled": false
  }
}
```

## Use cases

- **Syntax Highlighting Setup** — Developer forums inspect unformatted user pastes to pick the right code fence tag before rendering highlighted code blocks.
- **File Download Naming** — When users export generated snippets from a web interface, editors apply the returned extension to name and save files accurately.
- **Documentation Snippet Tagging** — Knowledge base platforms assign language labels to community-submitted examples without forcing authors to pick options from a manual dropdown.
- **Support Ticket Routing** — To triage incoming developer issues containing raw scripts or stack traces, ticketing systems route requests based on the detected language.

## SDKs

- **npm** — `npm install @apiverve/codedetector` (https://www.npmjs.com/package/@apiverve/codedetector)
- **PyPI** — `pip install apiverve-codedetector` (https://pypi.org/project/apiverve-codedetector/)
- **NuGet** — `dotnet add package APIVerve.API.CodeDetector` (https://www.nuget.org/packages/APIVerve.API.CodeDetector)
- **Source** — https://github.com/apiverve/codedetector-api

## More

- Full reference: https://docs.apiverve.com/ref/codedetector
- Get an API key: https://dashboard.apiverve.com
- Full catalog: https://apiverve.com/marketplace
