Integrating Generative APIs with OpenCode
OpenCode is a coding agent for your terminal and IDE. This guide shows you how to integrate Generative APIs models with OpenCode so you can use models such as Qwen3.5 for AI-powered code assistance and generation.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged in to the console (External link)
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A valid API key for API authentication
- Installed OpenCode (External link) on your local machine
Configure OpenCode using the CLI
-
Start OpenCode:
opencodeIf this command returns
command not found, ensure you have properly installed OpenCode (External link) and registered the tool in your terminal configuration. After installation, you can launch a new terminal or reload your current terminal configuration with:source ~/.bashrc # Or source ~/.zshrc if you use zsh -
Press
Ctrl + Pto display commands. -
Type
providerto search for commands. SelectConnect provider, then pressEnter. -
Type
scalewayto search for providers. SelectScaleway, then pressEnter. -
Enter your
SCW_SECRET_KEYas API key. PressEnter. -
Select a model in the list, for instance
Qwen3.5 397B A17B. -
Type any prompt asking OpenCode to create or update code files. For example:
"Write a fibonacci function in Python that computes the first 10 fibonacci numbers"
Configure OpenCode using configuration files
You can configure OpenCode with Scaleway via configuration files. This allows you to reuse a configuration with different credentials.
-
Create a
~/.config/opencode/opencode.jsonconfiguration file with the following content:This configuration requires you to have set
SCW_SECRET_KEYandSCW_PROJECT_IDas environment variables in your local terminal or configuration file, such as.zshrc. You can check that both these values are configured with the following command in your terminal:echo $SCW_SECRET_KEY echo $SCW_PROJECT_IDThis command should return the configured values.
-
Start OpenCode:
opencodeThe OpenCode terminal appears.
If the command returns
command not found, ensure you have properly installed OpenCode (External link) and registered the tool in your terminal configuration. After installation, you can launch a new terminal or reload your current terminal configuration with:source ~/.bashrc # Or source ~/.zshrc if you use zsh -
Press
Ctrl + Pto display commands. -
Select
Switch model. -
Under
Scaleway, select any model in the list, for instanceQwen3.5 397B A17B. -
Type any prompt asking OpenCode to create or update code files. For example:
"Write a fibonacci function in Python that computes the first 10 fibonacci numbers"
For more details about configuration files, see OpenCode documentation about configuration options when using a JSON configuration file (External link).
Going further
- You can explore additional OpenCode features in the OpenCode documentation (External link).
- By default, OpenCode sends requests to
https://api.scaleway.ai/v1and runs them on your Scaleway default Project. If you want to run requests on a specific Project (for instance, to track specific billing), edit the OpenCode JSON configuration file and add the Project identifier to the URLhttps://api.scaleway.ai/###PROJECT_ID###/v1.