# Use it from your tools

# Use it from your tools

Anything that speaks the OpenAI API works with Porten. The recipe is always the same: set the **base URL** to `https://porten.ai/v1` and the **API key** to your `sk-porten-…` key.

## OpenCode

[OpenCode](https://opencode.ai) is a terminal coding agent. Add Porten as a provider in `~/.config/opencode/opencode.jsonc`:

```jsonc
{
  "provider": {
    "porten": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Porten",
      "options": {
        "baseURL": "https://porten.ai/v1",
        "apiKey": "{env:PORTEN_API_KEY}"
      },
      "models": {
        "qwen3-coder-next": { "name": "Qwen3-Coder-Next" },
        "qwen2.5-coder-32b": { "name": "Qwen2.5 Coder 32B" }
      }
    }
  }
}
```

Then select a `porten/…` model in OpenCode. Because models load on demand, the first turn against a cold model takes longer while the fleet provisions it — the request simply waits rather than failing.

## Cursor

In **Settings → Models**, enable *Override OpenAI Base URL*, set it to `https://porten.ai/v1`, and paste your key. Add the model id (e.g. `qwen2.5-coder-32b`) under custom models. Cursor will route chat through Porten.

## Continue (VS Code / JetBrains)

In `~/.continue/config.json`:

```json
{
  "models": [
    {
      "title": "Porten — Qwen Coder",
      "provider": "openai",
      "model": "qwen2.5-coder-32b",
      "apiBase": "https://porten.ai/v1",
      "apiKey": "sk-porten-…"
    }
  ]
}
```

## LangChain (Python)

```python
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="qwen2.5-coder-32b",
    base_url="https://porten.ai/v1",
    api_key="sk-porten-…",
)
print(llm.invoke("Summarize the CAP theorem in two sentences.").content)
```

## LlamaIndex (Python)

```python
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="qwen2.5-coder-32b",
    api_base="https://porten.ai/v1",
    api_key="sk-porten-…",
    is_chat_model=True,
)
```

## Anything else

If your tool has an "OpenAI-compatible" or "custom OpenAI endpoint" option, use it. Set:

- **Base URL / API base:** `https://porten.ai/v1`
- **API key:** `sk-porten-…`
- **Model:** any id from [`GET /v1/models`](/docs/api-reference#get-v1models)

> **Tip:** if a tool sends a model id the catalog doesn't recognize, you'll get a `404 model_not_found`. List the models first and copy the exact canonical id.
