# 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:

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

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.

## Coding agents

### Aider

[Aider](https://aider.chat) pairs with you in the terminal. Point it at Porten with environment variables and an `openai/`-prefixed model:

```bash
export OPENAI_API_BASE=https://porten.ai/v1
export OPENAI_API_KEY=sk-porten-…
aider --model openai/qwen2.5-coder-32b
```

### Cline (VS Code)

In Cline's settings, set **API Provider** to *OpenAI Compatible*, then:

- **Base URL:** `https://porten.ai/v1`
- **API Key:** `sk-porten-…`
- **Model ID:** `qwen2.5-coder-32b`

### 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-…"
    }
  ]
}
```

### 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.

### 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": {
        "qwen2.5-coder-32b": { "name": "Qwen2.5 Coder 32B" }
      }
    }
  }
}
```

Then select a `porten/…` model in OpenCode.

## Chat UIs

### Open WebUI

In **Admin Settings → Connections**, add an *OpenAI API* connection:

- **API Base URL:** `https://porten.ai/v1`
- **API Key:** `sk-porten-…`

Open WebUI lists Porten's models automatically (from `/v1/models`); pick one and chat.

## SDKs & frameworks

### OpenAI SDK (Python / JavaScript)

Only the base URL and key change.

```python
from openai import OpenAI

client = OpenAI(base_url="https://porten.ai/v1", api_key="sk-porten-…")
resp = client.chat.completions.create(
    model="qwen2.5-coder-32b",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
```

```javascript
import OpenAI from 'openai'

const client = new OpenAI({ baseURL: 'https://porten.ai/v1', apiKey: process.env.PORTEN_API_KEY })
const resp = await client.chat.completions.create({
  model: 'qwen2.5-coder-32b',
  messages: [{ role: 'user', content: 'Hello!' }],
})
console.log(resp.choices[0].message.content)
```

### Vercel AI SDK

```typescript
import { createOpenAI } from '@ai-sdk/openai'
import { generateText } from 'ai'

const porten = createOpenAI({
  baseURL: 'https://porten.ai/v1',
  apiKey: process.env.PORTEN_API_KEY,
})

const { text } = await generateText({
  model: porten('qwen2.5-coder-32b'),
  prompt: 'Summarize the CAP theorem in two sentences.',
})
```

### LiteLLM

As a Python SDK call — note the `openai/` prefix so LiteLLM uses the OpenAI-compatible path against your `api_base`:

```python
from litellm import completion

resp = completion(
    model="openai/qwen2.5-coder-32b",
    api_base="https://porten.ai/v1",
    api_key="sk-porten-…",
    messages=[{"role": "user", "content": "Hello!"}],
)
```

Or as a proxy in `config.yaml`:

```yaml
model_list:
  - model_name: qwen2.5-coder-32b
    litellm_params:
      model: openai/qwen2.5-coder-32b
      api_base: https://porten.ai/v1
      api_key: os.environ/PORTEN_API_KEY
```

### 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.
