Integrate APIs using AI via CLI
Tags: tooling, ai, api, programming
Published: 2023-06-05 07:54:35

Imagine a workflow that allows developers to focus on building great applications, rather than getting bogged down in the details of integrating with third-party services. What if something else could read and understand the documentation for them?

That workflow is coming. We’re excited to share the first technology preview of the new Superface CLI.

The CLI (which we fondly refer to as EDGAR) is a powerful tool that allows developers to integrate with third-party APIs directly from the command line. Designed to help developers save time and effort by providing them with a powerful AI analysis that allows them to generate working integration code for their applications using the documentation of the provider they want to integrate with.

You can see more about how it works in the technology preview video below.

{% embed https://youtu.be/SOg5eMC_Qyc %}

## How the Superface CLI works

Superface harnesses the power of AI to analyze API documentation.

Currently, APIs defined with an Open API Specification (OAS) document, or hosted by Readme.io, can be ingested but we’re soon going to allow you to provide any documentation you want, in any text based format you have.

Below we ingest the OAS for the [Resend.com](https://resend.com/) email API directly from a GitHub repo.

```shell
npm run ingest https://raw.githubusercontent.com/resendlabs/resend-openapi/main/resend.yaml
```

Once ingested into the system, you can create working integration code for your desired API by stating the use case you want to achieve. For example, _“send an email”_, _“return geolocation from an IP address”_ or _“translate from English to Czech”_.

```shell
npm run profile resend "send an email"
```

With this use case, Superface will analyze the documentation and create a plan for how the API should be used in order to achieve it. The map command starts this process.

```shell
npm run map
```

This plan can then be turned into working integration code that runs via the Superface OneSDK. It’s important to highlight that this isn’t chatbot-to-code, as you have full code-like control over the files that are generated and can edit them to tune the output should you need to.

Additionally, we’ve included a specific command that allows you to run what the CLI generated against the third party API you want to work with, to check that it works and show you a real success or failure response.

```shell
npm run execute ./email-communication/email-sending/email-communication.email-sending.resend.map.js
```

This will run the code the CLI generated for you directly against the API, with no middleman or proxy, and output the response.

Overall, creating the integration you want breaks down to just 4 steps:

1. Ingest the API documentation into the system.
2. State the desired use case (e.g. _"send an email"_).
3. Superface will analyze the documentation and generate a plan for how to call the API to achieve the use case.
4. The plan is turned into working integration code that runs via the [Superface OneSDK](https://github.com/superfaceai/one-sdk).

At this time, all of these steps can be completed using the CLI, using AI to give you full, fast, control over your API integration workflow.

## Register for early access

Superface CLI will soon be available for early access users. If you'd like to try it, go to **[superface.ai/cli](https://superface.ai/cli?utm_source=dev.to&utm_campaign=cli-ai&utm_medium=syndication)** and let us know. We're excited to hear what you think.

{% cta https://superface.ai/cli?utm_source=dev.to&utm_campaign=cli-ai-cta&utm_medium=syndication %} Subscribe to get early access {% endcta %}