[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > [Machine learning and artificial intelligence](index.md) > Using Yandex Cloud AI Studio generative models > Integrating generative models into Visual Studio Code as a coding assistant

# Integrating generative models in Visual Studio Code

You can facilitate software development in [Visual Studio Code](https://code.visualstudio.com/) with `Qwen3-235B-A22B`, `GPT-OSS-120b`, and other models. The models can generate code, convert it to other programming languages, help you with debugging and error detection in code, analyze data, write documentation, and more.

In this tutorial, you will integrate the models into your Visual Studio Code with the help of Yandex Cloud AI Studio and the [SourceCraft Code Assistant](https://sourcecraft.dev/portal/code-assistant/) or [Roo Code](https://roocode.com/) extension.

{% note info %}

The Roo Code extension is only available in Visual Studio Code.

{% endnote %}

To use models as an assistant in the code editor:

1. [Set up your infrastructure](#infra).
1. [Create an API key for the service account](#create-key).
1. [Connect to the model](#connection).
1. [Test the model](#test).

The infrastructure support cost for connecting to the model from the code editor includes a text generation fee (see the [Yandex Cloud AI Studio pricing](https://aistudio.yandex.ru/docs/en/ai-studio/pricing)).

## Set up your infrastructure {#infra}

### Create a folder {#create-folder}

{% list tabs group=instructions %}

- Management console {#console}

   1. In the [management console](https://console.yandex.cloud), select a cloud and click ![create](../../_assets/console-icons/plus.svg) **Create folder**.
   1. Name your folder, e.g., `aistudio`.
   1. Click **Create**.

{% endlist %}

### Create a service account {#create-sa}

You will need this [service account](../../iam/concepts/users/service-accounts.md) to get an [API key](../../iam/concepts/authorization/api-key.md).

{% list tabs group=instructions %}

- Management console {#console}

  1. Navigate to `aistudio`.
  1. Navigate to **Identity and Access Management**.
  1. Click **Create service account**.
  1. Enter a name for the service account, e.g., `ai-model-user`.
  1. Click **Add role** and assign the `ai.languageModels.user` [role](https://aistudio.yandex.ru/docs/en/ai-studio/security/index#languageModels-user) to the service account.
  1. Click **Create**.

{% endlist %}

## Create an API key for the service account {#create-key}

To enable the code editor to access the model, create an API key.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), navigate to `aistudio`.
  1. Navigate to **Identity and Access Management**.
  1. In the left-hand panel, select ![FaceRobot](../../_assets/console-icons/face-robot.svg) **Service accounts**.
  1. In the list that opens, select the `ai-model-user` service account.
  1. In the top panel, click ![image](../../_assets/console-icons/plus.svg) **Create new key** and select **Create API key**.
  1. In the **Scope** field, select `yc.ai.languageModels.execute`.
  1. Click **Create**.
  1. Save the ID and the secret key.

{% endlist %}

## Connect to the model {#connection}

{% list tabs group=instructions %}

- Visual Studio Code {#vscode}

  1. Install the [SourceCraft Code Assistant](https://sourcecraft.dev/portal/code-assistant/) or [Roo Code](https://roocode.com/) extension.
  1. Configure the extension:

     {% cut "SourceCraft Code Assistant" %}

     1. Click **SourceCraft Code Assistant** in the program's left-hand panel.
     1. Click ![chevron-up](../../_assets/console-icons/chevron-up.svg) **Select API configuration** at the bottom of the chat window and click **Yandex Cloud AI Studio**.
     1. In the settings window that opens, make sure the `OpenAI Compatible` option is selected in the **API provider** field and the **Base URL** field is set to `https://ai.api.cloud.yandex.net/v1`, and close the settings window.
     1. Click ![chevron-up](../../_assets/console-icons/chevron-up.svg) **Select API configuration** at the bottom of the chat window and click **Add model**.
     1. In the window that opens, enter a name for the profile and click **Create profile**.
     1. In the settings window that opens, select `OpenAI Compatible` in the **API provider** field.
     1. In the **Base URL** field, specify `https://ai.api.cloud.yandex.net/v1`.
     1. In the **OpenAI API-key** field, paste the secret key value you got in the previous [step](#create-key).
     1. In the **Model** field, specify the model URI in `gpt://<folder_ID>/<model_ID>/latest` format, where:

         * `<folder_ID>`: `aistudio` [folder ID](../../resource-manager/operations/folder/get-id.md).
         * `<model_ID>`: [Model ID](https://aistudio.yandex.ru/docs/en/ai-studio/concepts/generation/models), e.g., `qwen3-235b-a22b-fp8` or `gpt-oss-120b`.

         {% note info %}

         The selected model will be used only for the assistant. The SourceCraft Code Assistant autocompletion feature will continue using the default model.

         {% endnote %}

     {% endcut %}

     {% cut "Roo Code" %}

     1. Click **Roo Code** in VSC left-hand panel.
     1. In the window that opens, select **OpenAI Compatible** in the **API Provider** field.
     1. In the **Base URL** field, specify `https://ai.api.cloud.yandex.net/v1`.
     1. In the **API-key** field, paste the secret key value you got in the previous [step](#create-key).
     1. In the **Model** field, specify the model URI in `gpt://<folder_ID>/<model_ID>/latest` format, where:

         * `<folder_ID>`: `aistudio` [folder ID](../../resource-manager/operations/folder/get-id.md).
         * `<model_ID>`: [Model ID](https://aistudio.yandex.ru/docs/en/ai-studio/concepts/generation/models), e.g., `qwen3-235b-a22b-fp8` or `gpt-oss-120b`.
     1. Click **Go!**.

     {% endcut %}

{% endlist %}

## Test the model {#test}

As an example, let's ask Qwen to generate a script to access an AI model via the OpenAI SDK.

{% list tabs group=instructions %}

- Visual Studio Code {#vscode}

    {% cut "SourceCraft Code Assistant" %}

    1. In the left-hand panel, click **SourceCraft Code Assistant**.
    1. At the bottom of the assistant chat window, enter your prompt and click ![arrow-up](../../_assets/console-icons/arrow-up.svg) **Send message**:

        ```text
        Write a script named `test.py` to make a streaming call to generate a poem about Yandex Cloud via the Python OpenAI SDK. Use model token and ID as parameters. Use `https://ai.api.cloud.yandex.net/v1` as the endpoint
        ```

        Result:

        ```py
        import sys
        from openai import OpenAI
        
        def main():
            if len(sys.argv) != 3:
                print("Usage: python test.py <token> <model_id>")
                return
        
            token = sys.argv[1]
            model_id = sys.argv[2]
        
            client = OpenAI(
                base_url="https://ai.api.cloud.yandex.net/v1",
                api_key=token
            )
        
            stream = client.chat.completions.create(
                model=model_id,
                messages=[
                    {"role": "user", "content": "Write a poem about Yandex Cloud"}
                ],
                stream=True
            )
        
            for chunk in stream:
                content = chunk.choices[0].delta.content
                if content:
                    print(content, end="")
        
        if __name__ == "__main__":
            main()
        ```

    {% endcut %}

    {% cut "Roo Code" %}

    1. Click **Roo Code** on the left-hand panel.
    1. In the window that opens, enter your prompt in the input field below and click **Send message**:

        ```text
        Write a script named `test.py` to make a streaming call to generate a poem about Yandex Cloud via the Python OpenAI SDK. Use model token and ID as parameters. Use `https://ai.api.cloud.yandex.net/v1` as the endpoint
        ```

        Result:

        ```py
        import sys
        from openai import OpenAI
        
        def main():
            if len(sys.argv) != 3:
                print("Usage: python test.py <token> <model_id>")
                return
        
            token = sys.argv[1]
            model_id = sys.argv[2]
        
            client = OpenAI(
                base_url="https://ai.api.cloud.yandex.net/v1",
                api_key=token
            )
        
            stream = client.chat.completions.create(
                model=model_id,
                messages=[
                    {"role": "user", "content": "Write a poem about Yandex Cloud"}
                ],
                stream=True
            )
        
            for chunk in stream:
                content = chunk.choices[0].delta.content
                if content:
                    print(content, end="")
        
        if __name__ == "__main__":
            main()
        ```
    
    {% endcut %}    

{% endlist %}