> ## Documentation Index
> Fetch the complete documentation index at: https://portkey-docs-add-third-party-integration-issues-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode

> centralised cost monitoring for opencode

[OpenCode](https://opencode.ai) is a claude code alternative that has quickly gained in popularity and is recommended by many of the top thought leaders in the AI space

Using Portkey to track costs for OpenCode is simple and one step setup because Portkey is openAI compatible.

# Setup

We use the [custom provider](https://opencode.ai/docs/providers/#custom-provider) option from opencode to integrate with Portkey.

1. In your OpenCode settings (usually located at `~/.config/opencode/opencode.json` in macos, check [https://opencode.ai/docs/config/#locations](https://opencode.ai/docs/config/#locations)) configure the following:

```json theme={null}
 {
   "$schema": "https://opencode.ai/config.json",
   "provider": {
     "portkey": {
       "npm": "@ai-sdk/openai-compatible",
       "name": "Portkey",
       "options": {
         "baseURL": "https://api.portkey.ai/v1",
         "headers": {
             "x-portkey-api-key": "YOUR_PORTKEY_API_KEY"
         }
       },
       "models": {
         "@your-integration-name/your-model-name": {
           "name": "gemini 2.5 flash enterprise team"
         }
       }
     }
   }
 }
```

here `your-integration-name` is the name of the integration you have configured in Portkey and `your-model-name` is the name of the model you are using.

2. Start opencode and execute the `/connect` command and select Portkey as the provider (if you are prompted for api key you can enter a dummy string)

3. You're all set. You can now track costs in your Portkey dashboard and monitor your usage in real time.
   <img src="https://mintcdn.com/portkey-docs-add-third-party-integration-issues-fixes/iw8u5vDH8VX-5kWU/images/libraries/opencode.png?fit=max&auto=format&n=iw8u5vDH8VX-5kWU&q=85&s=428dd3668a2bb07567f6b3b216c295df" alt="portkey dashboard opencode integration" width="2940" height="1598" data-path="images/libraries/opencode.png" />
