Skip to main content

OpenCode

OpenCode can connect to MuskAI through OpenAI compatible configuration. The location of the configuration file may be different in different versions, but the core fields are API Key, Base URL and model name.

Prepare information​

Copy on the official website User Center - [API Key] page:

  • API Key
  • Base URL

The model name uses the model available in the console.

Environment variable method​

Suitable for temporary testing or command line startup:

export OPENAI_API_KEY="your MuskAI API Key"
export OPENAI_BASE_URL="copy the Base URL from User Center > API Keys"
opencode

If your version of OpenCode uses other variable names, please refer to the tool's current documentation or configuration prompts. The key principle is that the Base URL only fills in the service root address and does not splice the complete interface path.

Configuration file method​

For long-term use, it is recommended to write the OpenCode configuration file and give MuskAI a separate name:

{
"providers": {
"muskai": {
"type": "openai",
"apiKey": "your MuskAI API Key",
"baseURL": "copy the Base URL from User Center > API Keys"
}
},
"model": "a model name available in the console"
}

The field name will change with the OpenCode version, and the actual configuration format of the current version shall prevail. When migrating, only three items need to be kept consistent: the service type is OpenAI compatible, the key is the key of this site, and the base URL is the user center display address.

verify​

After restarting OpenCode, send a simple task:

Inspect the current directory structure and describe this project's main technology stack.

If the tool can respond normally and use the model you configured, the access is complete. You can then configure the default model, context length, or tool permissions.

FAQ​

  • Environment variables do not take effect: Make sure you start OpenCode in the same terminal session.
  • The configuration file does not take effect: Check the configuration path and configuration priority actually read by OpenCode.
  • 401/403: Check API Key, quota and model permissions.
  • 404 or model not available: check the model name, do not write the full path of the interface into the Base URL.