How to Integrate ChatGPT in VS Code

ai extension for vs code

As technology advances, the field of artificial intelligence (AI) continues to shape the way we interact with computers and software. 

One of the fascinating applications of AI is ChatGPT, a powerful language model developed by OpenAI. ChatGPT is capable of generating human-like text responses, making it an ideal tool for various tasks, including coding assistance. 

In this blog post, we’ll look at how we can use AI extension for VS Code. We will explore how to integrate ChatGPT into Visual Studio Code, one of the most popular code editors among developers, and uncover the advantages it brings to the coding experience.

Installation Requirements for the ChatGPT Extension in VS Code

To install the ChatGPT extension in Visual Studio Code, you will need the following requirements:

Visual Studio Code

Make sure you have Visual Studio Code installed on your system. Visual Studio Code is a free and widely used source code editor available for Windows, macOS, and Linux.

Internet Connection

A stable internet connection is required to download and install the extension, as well as to connect to the ChatGPT API and retrieve responses.

OpenAI API Key

You will need an API key from OpenAI to access the ChatGPT API. The API key allows you to make requests to the language model and receive responses. You can obtain an API key by signing up on the OpenAI website and following their API documentation.

ChatGPT Extension

Once you have the prerequisites ready, you can search for the ChatGPT extension in the Visual Studio Code marketplace. Install the extension by following the provided instructions.

Installing ChatGPT – AI Extension for VS Code

  • To access the Extensions view in Visual Studio Code, simply click on the Extension icon located in the sidebar. From there, search for the “ChatGPT: Write and Improve Code using AI” extension and proceed to install it.

Install the ChatGPT Extension in VS Code

  • Navigate to File > Preferences > Settings in the Visual Studio Code menu. Look for the ChatGPT settings and click on the provided URL. This link will take you to the ChatGPT REST API page, where you can generate a secret key.

Install the ChatGPT Extension for VS Code - step 2

Install the ChatGPT Extension in VS Code - Step 3

  • On the ChatGPT REST API page, click the “Create New Secret Key” button to generate a new key. Copy the generated key.

Install the ChatGPT Extension for VS Code - step 4

  • Return to Visual Studio Code and paste the API key in the “ChatGPT API Key” text box within the extension’s settings.
  • Feel free to customize the ordering of the extension’s prompts based on your preferences.

Installing the SQL Server (mssql) Extension

To work with T-SQL code, we will install the SQL Server (mssql) extension in Visual Studio Code.

Access Extensions

To access the Extensions view in Visual Studio Code, simply open the Extension panel.

Install the SQL Server (mssql) Extension

Search for the “SQL Server (mssql)” extension created by Microsoft and install it.

Install the SQL Server (mssql) Extension for VS Code

Configure the SQL Server Extension

After the installation, click the SQL Server icon. Click the “+” symbol to add a new connection.

Configure the SQL Server Extension for VS Code

Provide Connection Details

Enter the SQL Server instance name and the desired database name, such as “test” for this example. Select the authentication type based on your requirements.

How to use ChatGPT in VS Code

Here’s an example to illustrate how to work with ChatGPT in Visual Studio Code using T-SQL code:

Open a T-SQL File

Create a new file in Visual Studio Code and save it with a .sql extension. This will be our T-SQL file where we’ll interact with ChatGPT.

Enable ChatGPT Assistance

Start by typing a T-SQL query in the editor. For example, let’s consider a simple query to retrieve employee information from a table:loper.

					SELECT EmployeeID, FirstName, LastName
FROM Employees
WHERE Department = 'IT';

Code Suggestions

As you type the query, ChatGPT will analyze your code and provide relevant suggestions. For instance, while typing the table name “Employees,” ChatGPT might suggest completing the table name or provide relevant column names to choose from.

Contextual Assistance

To seek assistance from ChatGPT, select a portion of your code that you want help with. For example, select the condition Department = ‘IT’ in the WHERE clause. Then, invoke the appropriate command provided by the ChatGPT extension. This could be a keyboard shortcut or a command from the extension menu.

Fixing Code Issues

Let’s say ChatGPT suggests changing the equality operator in the WHERE clause to = for consistency. You can review the suggestion and decide whether to apply it to your code.

Query Refinement

You can also use ChatGPT to refine and optimize your query. For example, you may have a large dataset and want to improve the performance. Select the entire query and ask ChatGPT for suggestions on optimizing the query or alternative approaches to achieve the same result.

Iterate and Refine

As you receive suggestions from ChatGPT, iterate on your code by incorporating the recommendations. Review the suggestions, apply the ones that align with your requirements, and refine your code accordingly. This interactive process helps you improve the quality and efficiency of your T-SQL code.

Test Different Scenarios

Feel free to experiment with various T-SQL scenarios. You can try different queries, join conditions, aggregations, or explore more advanced features of T-SQL. ChatGPT will assist you by providing suggestions, explaining complex concepts, or offering alternative ways to achieve your desired outcome.

Advantages of Programming with chatGPT

Here are the advantages of programming with ChatGPT summarized in short points:

Assistance and Suggestions

ChatGPT provides helpful suggestions and assistance in coding tasks.

Problem-solving and Debugging

It helps identify errors and offers troubleshooting tips.

Access to Knowledge and Documentation

ChatGPT has extensive programming knowledge and can provide quick answers and references.

Code Refactoring and Best Practices

It suggests improvements for code readability, maintainability, and performance.

Exploration of Different Approaches

ChatGPT offers alternative solutions and encourages creative thinking.

Increased Productivity

It saves time and automates repetitive tasks.


ChatGPT facilitates communication within development teams.

Future of coding

Here are the key points about the future of coding in relation to integrating ChatGPT in VS Code:

Enhanced Developer Productivity

AI integration boosts productivity by offering instant suggestions and efficient debugging support.

Intelligent Code Completion

Context-aware code snippets reduce coding time and effort.

Natural Language Programming

Conversational interaction makes coding accessible and fosters collaboration.

Automated Code Generation

AI can generate code based on natural language descriptions, accelerating development.

Improved Code Quality

Continuous feedback enforces best practices and coding standards.

Continual Learning and Adaptation

AI models stay updated with the latest coding trends and libraries.

Collaborative Coding

AI assists in code reviews, bridging the gap between technical and non-technical team members.

Github copilot

Github Copilot, an AI-powered code completion tool developed by GitHub and OpenAI, revolutionizes coding by suggesting code snippets based on natural language input. 

It surpasses ChatGPT as a specialized solution tailored specifically for coding tasks. Although not directly integrated into VS Code, it can be seamlessly incorporated through a plugin. 

With its ability to accelerate coding workflows, Github Copilot has garnered considerable attention in the programming community. 

However, discussions persist about its potential impact on employment in the programming industry, prompting important conversations about the balance between automation and human expertise.


In conclusion, integrating ChatGPT into Visual Studio Code opens up a world of possibilities for developers. 

With its AI-powered assistance, suggestions, and code optimizations, ChatGPT enhances productivity and problem-solving in coding tasks. 

The future of coding looks promising with advancements like natural language programming and collaborative coding on the horizon. 

Embrace the power of ChatGPT in VS Code and embark on a coding journey that is efficient, creative, and collaborative. Get ready to redefine the way you code and unlock your full potential as a developer.

Written by

The Test Tribe

Leave a Reply

Your email address will not be published.

Related Posts

Testing Courses at Thrive EdSchool

Advertisement (Know More)

Get Top Community News

    Top Event and other The Test Tribe updates to your Inbox.