MarsAI developer guide
Connect OpenCode to MarsAI
Add MarsAI as an OpenAI compatible provider, map a public model ID and test the connection before starting an agent session.
Reviewed . Checked against the current MarsAI /v1 behavior and published catalog.
1. Create an API key
Create a key in the MarsAI dashboard and keep it out of shared configuration files. OpenCode reads it from the environment of its server process.
# macOS or Linux
export MARSAI_API_KEY='sk-mars-YOUR_KEY'
# PowerShell
$env:MARSAI_API_KEY = 'sk-mars-YOUR_KEY'
2. Add the provider
Put this in opencode.json or opencode.jsonc. Replace YOUR_PUBLIC_MODEL_ID with the complete ID from the MarsAI model catalog. The local name your-model is what OpenCode shows in its selector.
{
"$schema": "https://opencode.ai/config.json",
"model": "marsai/your-model",
"providers": {
"marsai": {
"name": "MarsAI",
"env": ["MARSAI_API_KEY"],
"package": "@opencode/ai/providers/openai-compatible",
"settings": {
"baseURL": "https://marsai.click/v1"
},
"models": {
"your-model": {
"name": "MarsAI model",
"modelID": "YOUR_PUBLIC_MODEL_ID"
}
}
}
}
}
The selector is marsai/your-model; modelID is the value sent to the MarsAI API.
3. Check the key and endpoint
Start OpenCode from the same shell that contains MARSAI_API_KEY. Before opening a long session, use the models endpoint to check that the process can reach MarsAI and read the credential.
curl https://marsai.click/v1/models \
-H "Authorization: Bearer $MARSAI_API_KEY"
A valid key returns HTTP 200 and a JSON data array. In PowerShell, use curl.exe if curl resolves to the PowerShell alias.
If it does not connect
- Check that the base URL ends in
/v1. - Copy the complete public model ID; do not send OpenCode's local name as the API model ID.
- Confirm the environment variable exists in the process that starts OpenCode.
- Read the HTTP status and structured error body before changing the configuration.
See the API error guide for the next check. OpenCode's configuration can change between releases, so compare the example with its custom provider documentation if a field is rejected.