This topic describes how to install and use the Alibaba Cloud API Toolkit extension in Visual Studio Code (VS Code).
Install the extension
Prerequisites
You must install VS Code.
You can install the extension using one of the following two methods:
Method 1: Install from the Marketplace
In the Activity Bar on the left side of the VS Code editor, click the
icon.Search for Alibaba Cloud API Toolkit and click Install.

Method 2: Install from a browser
Go to the official Marketplace in a browser and click Install. VS Code automatically opens to the extension page.
On the extension page in VS Code, click Install.

Verify the installation
After the installation is complete, the Alibaba Cloud icon appears in the Activity Bar on the left. This indicates that the installation is successful.
Configure user identity and credentials
You must configure your identity and credentials before you can call an API. This extension currently supports only AccessKey (AK) credentials. Configure your credentials as follows.
Add or modify identity and credential configurations
Install the Alibaba Cloud CLI Tools extension.
Go to Alibaba Cloud CLI Tools in a browser and click Install.
In the dialog box that appears, click Open.
On the extension page in VS Code, click Install.
After the installation is complete, the Alibaba Cloud icon appears in the status bar.
NoteYou can also install the command-line interface (CLI) for Alibaba Cloud directly in VS Code. For more information, see Use the Alibaba Cloud CLI extension for Visual Studio Code.
Configure identity credentials.
In the menu bar at the top of the VS Code editor, choose .
In the terminal, run the
aliyun configurecommand and follow the prompts. You can use an existing AccessKey or create a new one. For more information, see Create an AccessKey. Note: To reduce the risk of an AccessKey leak, the AccessKey secret is displayed only when you create it and cannot be retrieved later. You must store it in a secure location.Press Enter after each line. The message Saving profile[xxx] ...Done. indicates that the profile is saved. If the message !!! Configure Failed please configure again !!! appears, the verification failed because a parameter has an incorrect format or value. However, the profile is still saved locally.
$ aliyun configure Configuring profile 'default' ... Aliyun Access Key ID [None]: <Your AccessKey ID> Aliyun Access Key Secret [None]: <Your AccessKey Secret> Default Region Id [None]: cn-hangzhou Default output format [json]: json Default Language [zh]: zhImportantAn Alibaba Cloud account has all permissions for its resources. If the AccessKey of your Alibaba Cloud account is compromised, your resources are at high risk. We strongly recommend that you use the AccessKey of a RAM user instead.
View and switch user identities
In the status bar in the lower-left corner, click the Alibaba Cloud icon. The configured users are displayed below the search box that appears.
Click a profile name to switch the user identity.

Features
The Alibaba Cloud API Toolkit is a lightweight tool for Alibaba Cloud APIs in VS Code. It lets you quickly look up APIs for Alibaba Cloud products and provides features such as API debugging, and generating and inserting software development kit (SDK) sample code.
Subscribe to Alibaba Cloud products
The extension lets you subscribe to Alibaba Cloud products with a single click. You can select different API versions of a product and receive recommendations for the optimal version. No configuration file is required. You can use the keyboard shortcut Ctrl+Cmd+K (or Ctrl+Win+K for Windows) to search for and subscribe to Alibaba Cloud products.
API search
The extension lets you search for subscribed APIs. You can also use the keyboard shortcut Ctrl+Cmd+L (or Ctrl+Win+L for Windows) to search for subscribed APIs, view their documentation, or insert code snippets.

API documentation preview
Click an API to open its documentation in a new tab. The documentation includes the API description, request parameters, response parameters, and error codes.
API debugging
After your identity credentials are authenticated, you can use the extension to debug APIs.
You can debug Alibaba Cloud APIs by filling out the parameter form and viewing the results.
You can directly open the response in the editor.

Use code examples from the extension
Before you use the code examples from the extension, you must install the SDK for the cloud product.
Install an SDK for a cloud product
Go to SDK Center, select the cloud product for the API that you want to call, set SDK Version to V2.0, and select TypeScript as the language. This example uses Elastic Computing Service (ECS).
npm install --save @alicloud/ecs20140526@4.1.8In the terminal, run the installation command.
Generate code examples
Use code examples from the extension
The extension can generate SDK sample code. You can obtain SDK code examples for different languages by filling out the parameter form. You can also quickly open the SDK code in the editor or save it as a new file.

Use the insert code snippets feature
The extension lets you insert sample code snippets for multiple languages with a single click. Supported languages include Java, Java async, TypeScript, Python, Go, PHP, and C#. This feature helps you quickly generate SDK code examples.
Method 1: In the editor, enter the name of a subscribed API to search for its code segment.
Method 2: Use the keyboard shortcut
Ctrl+Cmd+L(orCtrl+Win+Lfor Windows) to search for an API and insert a code snippet.
Complete and run the code
Complete the code.
Modify the endpoint.
Log in to the OpenAPI Portal, select a cloud product, and view the supported endpoints on the product homepage.
Add request parameters. For information about request parameters, see API documentation preview.
(Optional) Add logs.
Save the changes.
import OpenApi, * as $OpenApi from '@alicloud/openapi-client'; import Ecs20140526, * as $Ecs20140526 from '@alicloud/ecs20140526'; export default class DescribeRegion { static async main(args: string[]): Promise<void> { let config = new $OpenApi.Config({ // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set in the code execution environment. accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'], accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'], // For more information about the endpoint, see https://api.aliyun.com/product/Ecs. endpoint: `ecs.cn-hangzhou.aliyuncs.com`, }); let client = new Ecs20140526(config); let describeRegionsRequest = new $Ecs20140526.DescribeRegionsRequest({}); let response = await client.describeRegions(describeRegionsRequest); console.log(response.body?.regions?.region); } }
Run the code
In the terminal, run the following command to compile the TypeScript file into a JavaScript file.
tsc client.ts # client.ts is the file name.Create a main.js file and copy the following code into the editor.
const { default: Describeregion } = require("./describeregion"); Describeregion.main();In the terminal, run the following command to run the sample code.
node .\main.jsThe following result indicates that the call is successful.

Feedback
If you have any questions, submit an issue in the GitHub repository to help us improve the Alibaba Cloud API Toolkit extension for VS Code.