How to run Open Code with Ozeki AI Gateway
This comprehensive guide demonstrates how to install and configure Open Code to work with Ozeki AI Gateway on Windows systems. By connecting Open Code to Ozeki AI Gateway, you can route requests through your local gateway and use alternative AI models. This tutorial covers the complete setup process, from installing Open Code using npm to configuring environment variables and the JSON configuration file.
What is Open Code?
Open Code is a command-line interface tool that enables developers to interact with AI directly from their terminal. It provides an agentic coding experience where you can delegate programming tasks, file operations, and code generation without leaving your command-line environment.
Steps to follow
- Install Open Code via npm
- Configure PATH environment variable
- Initialize Open Code configuration folder
- Create config.json file
- Configure Ozeki AI Gateway settings
- Launch Open Code
- Send test prompt
- Verify task completion
Configuration Files Overview
npm install command:
npm install -g opencode-ai
Environment variable:
C:\Users\{Username}\AppData\Roaming\npm
Config file C:\Users\{Username}\.config\opencode\config.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ozekiaigateway": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ozeki AI Gateway",
"options": {
"baseURL": "http://localhost/v1",
"apiKey": "ozkey-12345..."
},
"models": {
"gpt-oss-120b": {
"id": "openai/gpt-oss-120b",
"tools": true
}
}
}
}
}
How to run Open Code with Ozeki AI Gateway video
The following video shows how to install and configure Open Code to work with Ozeki AI Gateway step-by-step. The video covers the npm installation, environment variable configuration, config.json file setup, and testing the integration with a sample coding task.
Step 1 - Install Open Code via npm
Open Command Prompt on your Windows system by searching for "cmd" in the Start menu. You'll use the terminal to run the Open Code installation command (Figure 1).
Execute the npm command to install Open Code globally on your system. This command downloads and installs Open Code and all its dependencies (Figure 2).
npm install -g opencode-ai
Step 2 - Configure PATH environment variable
Open the Windows Environment Variables panel by searching for "environment variables" in the Start menu and selecting "Edit the system environment variables". This opens the System Properties dialog where you can configure system and user environment variables (Figure 3).
In the System Properties dialog, click the "Environment Variables" button at the bottom of the Advanced tab (Figure 4).
In the Environment Variables window, locate the "Path" variable in the User variables section. Select "Path" and click the "Edit" button. This allows you to add the npm installation directory to your system path so you can run Open Code from any directory (Figure 5).
In the Edit Environment Variable window, click "New" to add a new path entry. Add the npm global installation path: C:\Users\{Username}\AppData\Roaming\npm (replace {Username} with your Windows username). This adds the Open Code executable directory to your system path (Figure 6).
C:\Users\{Username}\AppData\Roaming\npm
Click "OK" to save the path changes, then click "OK" again on each open dialog to close the Environment Variables windows. The path changes will take effect for new terminal sessions. You may need to restart any open Command Prompt or PowerShell windows to use the updated path (Figure 7).
Step 3 - Initialize Open Code configuration folder
Open a new Command Prompt. It's important to open a new terminal window after modifying the environment variables to ensure the updated PATH is loaded (Figure 8).
Type "opencode" in the terminal to start Open Code for the first time. This initial startup creates the configuration directory at C:\Users\{Username}\.config\opencode\ where you'll place the config.json file in the next steps (Figure 9).
opencode
Open Code displays its welcome page in the terminal window. The configuration folder has now been created. You can proceed to exit Open Code so you can configure it to work with Ozeki AI Gateway (Figure 10).
Exit Open Code by typing the /exit command or closing the interface (Figure 11).
/exit
Step 4 - Create config.json file
Navigate to the Open Code configuration directory at C:\Users\{Username}\.config\opencode\. This is where you'll create the config.json file to configure Open Code to work with Ozeki AI Gateway (Figure 12).
In the config folder, right-click and select "New" then "Text Document" to create a new text file (Figure 13).
Rename the text document to "config.json". Make sure to remove the .txt extension completely so the file is named config.json. Windows may ask you to confirm changing the file extension (Figure 14).
config.json
Step 5 - Configure Ozeki AI Gateway settings
Open the config.json file with Notepad or any text editor and add the Ozeki AI Gateway configuration. Update the baseURL to point to your Ozeki AI Gateway endpoint, and set the apiKey to your gateway API key. Configure the model names to match the AI models available in your Ozeki AI Gateway installation. Save the file after making these changes (Figure 15).
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ozekiaigateway": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ozeki AI Gateway",
"options": {
"baseURL": "http://localhost/v1",
"apiKey": "ozkey-12345..."
},
"models": {
"gpt-oss-120b": {
"id": "openai/gpt-oss-120b",
"tools": true
}
}
}
}
}
Step 6 - Launch Open Code
Open a terminal window, navigate to the directory where you want to work, and type "opencode" to start Open Code (Figure 16).
opencode
Step 7 - Send test prompt
Test your Open Code installation by entering a simple prompt. For example, ask Open Code to create a basic HTML file or write a simple script. This verifies that Open Code is properly connected to Ozeki AI Gateway and can execute coding tasks (Figure 17).
Step 8 - Verify task completion
Open Code completes the requested task and displays the results. You can see the created files in your directory and verify that the integration with Ozeki AI Gateway is working correctly (Figure 18).
Troubleshooting
Open Code command not found
If you receive a "command not found" error when trying to run Open Code, ensure you've added the npm installation path to your PATH environment variable and opened a new terminal window after making the changes.
Connection errors
If Open Code cannot connect to Ozeki AI Gateway, verify that:
- Ozeki AI Gateway is running and accessible at the configured URL
- The baseURL in config.json is correct
- The apiKey matches your gateway API key
- The configured AI models are available in your Ozeki AI Gateway installation
Configuration file issues
If Open Code doesn't recognize your configuration, ensure that:
- The config.json file is in the correct location: C:\Users\{Username}\.config\opencode\
- The JSON syntax is valid (no missing commas, brackets, or quotes)
Final thoughts
You have successfully installed and configured Open Code to work with Ozeki AI Gateway. You can now use Open Code from the command line to delegate coding tasks, automate file operations, and leverage AI assistance in your development workflow. All requests will be routed through your Ozeki AI Gateway, allowing you to use alternative AI models and maintain control over your API infrastructure.