Integrating generative models in Visual Studio Code
You can facilitate software development in Visual Studio CodeQwen3-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 AI Studio and the SourceCraft Code Assistant
Note
The Roo Code extension is only available in Visual Studio Code.
To use models as an assistant in the code editor:
- Set up the infrastructure.
- Create an API key for the service account.
- Connect to the model.
- Test the model.
The infrastructure support fee for connecting to the model from the code editor includes a text generation fee (see the Yandex AI Studio pricing).
Set up the infrastructure
Create a folder
- In the management console
, select a cloud and click Create folder. - Name your folder, e.g.,
aistudio. - Click Create.
Create a service account
You will need this service account to get an API key.
- Navigate to
aistudio. - In the list of services, select Identity and Access Management.
- Click Create service account.
- Enter a name for the service account, e.g.,
ai-model-user. - Click Add role and assign the
ai.languageModels.userrole to the service account. - Click Create.
Create an API key for the service account
To enable the code editor to access the model, create an API key.
- In the management console
, navigate toaistudio. - In the list of services, select Identity and Access Management.
- In the left-hand panel, select
Service accounts. - In the list that opens, select
ai-model-user. - In the top panel, click
Create new key and select Create API key. - In the Scope field, select
yc.ai.languageModels.execute. - Click Create.
- Save the ID and secret key.
Connect to the model
-
Install the SourceCraft Code Assistant
or Roo Code extension. -
Configure the extension:
SourceCraft Code Assistant
-
Click SourceCraft Code Assistant in the program's left-hand panel.
-
Click
Select API configuration at the bottom of the chat window and click Yandex Cloud AI Studio. -
In the settings window that opens, make sure the
OpenAI Compatibleoption is selected in the API provider field and the Base URL field is set tohttps://llm.api.cloud.yandex.net/v1, and close the settings window. -
Click
Select API configuration at the bottom of the chat window and click Add model. -
In the window that opens, enter a name for the profile and click Create profile.
-
In the settings window that opens, select
OpenAI Compatiblein the API provider field. -
In the Base URL field, specify
https://llm.api.cloud.yandex.net/v1. -
In the OpenAI API-key field, paste the secret key value you got in the previous step.
-
In the Model field, specify the model URI in
gpt://<folder_ID>/<model_ID>/latestformat, where:<folder_ID>:aistudiofolder ID.<model_ID>: Model ID. For example:qwen3-235b-a22b-fp8orgpt-oss-120b.
Note
The selected model will be used only for the assistant. The SourceCraft Code Assistant autocompletion feature will continue using the default model.
Roo Code
-
Click Roo Code in VSC left-hand panel.
-
In the window that opens, select OpenAI Compatible in the API Provider field.
-
In the Base URL field, specify
https://llm.api.cloud.yandex.net/v1. -
In the API-key field, paste the secret key value you got in the previous step.
-
In the Model field, specify the model URI in
gpt://<folder_ID>/<model_ID>/latestformat, where: -
Click Go!.
-
Test the model
As an example, let's ask Qwen to generate a script to access an AI model via the OpenAI SDK.
SourceCraft Code Assistant
-
In the left-hand panel, click SourceCraft Code Assistant.
-
At the bottom of the screen in the assistant chat window, enter your prompt and click
Send Message: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://llm.api.cloud.yandex.net/v1` as the endpointResult:
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://llm.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()
Roo Code
-
Click Roo Code on the left-hand panel.
-
In the window that opens, enter your prompt in the input field below and click Send message:
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://llm.api.cloud.yandex.net/v1` as the endpointResult:
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://llm.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()