Code analysis with the code detection API

The world runs on code. Almost every single aspect of our life is in some way, shape or form managed by code. It may be hidden and work behind the scenes, but it is always present in our daily activities. Wake up in the morning thanks to our alarm clock or phone app, consume news and multimedia content on a smart device or TV, order food for dinner, take away or at home, or even simply navigate through traffic to get from point A to one point Code B is the driving force behind it all.

As such, the code that runs the world has grown exponentially and continues to do so every day as more apps and services aim to permeate our lives. Most of this code does not exist on a single person’s computer. It is written, shared and discussed by teams of people, and the tools used to share and discuss that code just can’t keep up.

But it is not just a problem of “teams”. Have you ever encountered code snippets on websites that aren’t labeled or rated? Sure you have. We all have!

Developers need tools to detect, label, format, and enrich their code, and the Code Discovery API was built just for this purpose.

What is the Code Detection API?

Code Detection API is a code processor created as a joint effort by Runtime and APILayer. The goal of Runtime is to pave the way for the discovery, processing, labeling, enrichment and transformation of code, also known as technical language processing. They are responsible for the Pieces application which can instantly save code snippets, extract code from screenshots, and boost automatic code completion from those snippets. APILayer not only builds scalable and performing RESTful APIs, but has also built the nearly always-on infrastructure on which these APIs run.

The Code Detection API is simple to use and can determine whether a supplied string is a natural language or a technical language (e.g. code). If it detects the code, it identifies the language with a high level of accuracy. The best part is the speed of the code detection API; it only takes about 250 ms to parse and identify the input provided. Not only is it extremely fast, but it minimizes processing resources on the device.

So no matter what software you’re building, whether it’s a documentation site, forum, online code editor, or developer-centric tool, you need the code detection API.

Why use the code detection API?

The Code Detection API is an easy to use API that detects, processes, labels, enriches and transforms your code and you won’t find any other service or solution that can provide all of these features:

Fast code detection

The Code Detection API determines whether a supplied text string includes a code snippet using the Runtime machine learning templates.

Accurate classification

There are many technical languages, and the Code Detection API accurately detects 30 languages, including JavaScript, PHP, C #, Ruby, Go, HTML, Markdown, C, and C ++.

Enrich and transform snippets

The code detection API can generate highlighted and truncated versions of the code from the syntax.

Improve SEO

Use the code detection API to classify your site’s code snippets and use the generated metadata to improve indexing, which will improve your site’s visibility.

Highly scalable

The Code Discovery API runs on APILayer’s cloud infrastructure and can meet your smallest and largest needs.

Unmatched speed

The Runtime Technical Language Processor analyzes the code in milliseconds and APILayer provides the answer via its ultra-fast infrastructure.

Uptime close to 100%.

While nothing is 100%, the uptime for APILayer’s services is as close as possible.

How does it work

Getting started with the Code Detection API is easy. First, you need to create a account. After verifying your email address and logging in, you will enter the Runtime Developer Console.

Runtime developer consoleRuntime developer consoleRuntime developer console

An API key is required to use the Code Detection API, and while technically you can retrieve one for free (for a 14-day trial), you must provide a credit card to begin the trial. To get a key, click Discover the products in the Runtime Developer Console, select the desired plan and enter your payment details.

After starting the trial, you will be redirected to the Runtime developer consolewhere you will find your API key (and secret), as well as a sample request using cURL and its response.

find your API key (and secret), plus a sample requestfind your API key (and secret), plus a sample requestfind your API key (and secret), plus a sample request

Quick tutorial

We use the code detection API to evaluate arbitrary text. It is important to note, however, that the Code Detection API does not support CORS as of this writing. Therefore, it is not possible to send requests directly using JavaScript from within the browser. Therefore, the following code examples will use PHP and the HTTP Guzzle library. Note: the Guzzle library is not needed; you can get the same results with the cURL functions.

First, it creates an HTTP Guzzle client object by calling the file Client() manufacturer:

The next step is to send to POST request to the code detection API. The request should include the apiKey URL parameter set to the API key and the request body must be in JSON format, as shown in the following code:

This code uses the client object request() method and passes three arguments. The first argument is the HTTP method, the second is the URL to send the request to, and the third is an array that specifies the body of the request. To send JSON, the body array key must be string jsonand its value is an object or an array that can be serialized into the following structure:

The iterable the property is an input array. Each input is an object that has a value property and its value is the text that the code detection API should evaluate. You must include at least one input with the request.

The API responds with a JSON payload. Here is the truncated answer from the above request:

truncated response from the above request:truncated response from the above request:truncated response from the above request:

Like the request, the response has a called property iterable, and is an array that contains the analysis of the results of the required inputs. As you would expect, the indexes for the answer iterable arrays correspond directly to the indices in the request iterable Vector.

Each result has naturalLanguage And codeClassification properties, each of which is an object that has a result property. The naturalLanguage of the object result the property tells you if the supplied input is natural text. The result for codeClassification provides a variety of information if the supplied input is code.

Speaking of code, let’s get back to it. Of course, you have to decode the JSON response into objects:


The Code Detection API has three subscription plans. Each plan grants you API credits and various features. Of course, higher tier subscriptions grant more API credits and provide extra functionality.

Code Detection API pricing tableCode Detection API pricing tableCode Detection API pricing table

There is no free plan; however, you get a 14-day free trial regardless of the subscription you choose. You must provide a credit card to start the trial. The three floors are:

Floor Description
Basic This plan gets you started with 1,000 API credits and a basic analysis of the required text.
Pro This plan provides 6,000 credits and a more comprehensive analysis of the required text.
Business This plan offers 36,000 API credits and the same analytics as the Pro plan.
Costume Do you need even more? Contact them to create a customized plan based on your needs.


The code that developers are confronted with continues to grow exponentially. If you or your team are writing software that allows developers to view, share and discuss code, you need to integrate the Code Detection API into your apps. Getting started is quick and easy. So get started today!

Source link

By LocalBizWebsiteDesign

Leave a Reply

Your email address will not be published. Required fields are marked *