# OpenAI-compatible examples

> Configure the OpenAI SDK for ScaleMax Chat Completions and Responses without exposing API keys in browser code.

ScaleMax works with the standard OpenAI SDK pattern. Set `SCALEMAX_BASE_URL` to `https://api.scalemax.pro/v1` for API credit or `https://api.scalemax.pro/token/v1` for an API-token key. Choose an exact model ID returned by that key's authenticated catalog.

**macOS / Linux**

```bash
# API-credit key:
export SCALEMAX_BASE_URL="https://api.scalemax.pro/v1"
# API-token key:
# export SCALEMAX_BASE_URL="https://api.scalemax.pro/token/v1"
```

**Windows PowerShell**

```powershell
# API-credit key:
$env:SCALEMAX_BASE_URL = "https://api.scalemax.pro/v1"
# API-token key:
# $env:SCALEMAX_BASE_URL = "https://api.scalemax.pro/token/v1"
```

## SDK examples

**Node SDK**

**macOS / Linux**

```bash
npm install openai
```

**Windows PowerShell**

```powershell
npm.cmd install openai
```

Windows PowerShell blocks npm’s .ps1 launchers by default (“running scripts is disabled on this system”), so these commands use the .cmd launcher: npx.cmd, npm.cmd, scalemax.cmd. In Command Prompt you can leave out .cmd.

client.ts:

```ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.SCALEMAX_API_KEY,
  baseURL: process.env.SCALEMAX_BASE_URL,
});

const completion = await client.chat.completions.create({
  model: "YOUR_AUTHENTICATED_MODEL_ID",
  messages: [{ role: "user", content: "Say hello from ScaleMax." }],
});

console.log(completion.choices[0]?.message?.content);
```

**Python SDK**

```bash
pip install openai
```

client.py:

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SCALEMAX_API_KEY"],
    base_url=os.environ["SCALEMAX_BASE_URL"],
)

completion = client.chat.completions.create(
    model="YOUR_AUTHENTICATED_MODEL_ID",
    messages=[{"role": "user", "content": "Say hello from ScaleMax."}],
)

print(completion.choices[0].message.content)
```

**cURL**

**macOS / Linux**

request.sh:

```bash
export SCALEMAX_AUTH_HEADER="Authorization: Bearer $SCALEMAX_API_KEY"

curl "$SCALEMAX_BASE_URL/chat/completions" \
  -H "$SCALEMAX_AUTH_HEADER" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_AUTHENTICATED_MODEL_ID",
    "messages": [{"role": "user", "content": "Say hello from ScaleMax."}]
  }'
```

**Windows PowerShell**

request.ps1:

```powershell
$env:SCALEMAX_AUTH_HEADER = "Authorization: Bearer $env:SCALEMAX_API_KEY"

@'
{
  "model": "YOUR_AUTHENTICATED_MODEL_ID",
  "messages": [{"role": "user", "content": "Say hello from ScaleMax."}]
}
'@ | Set-Content -Path body.json

curl.exe "$env:SCALEMAX_BASE_URL/chat/completions" `
  -H "$env:SCALEMAX_AUTH_HEADER" `
  -H "Content-Type: application/json" `
  --data-binary "@body.json"
```

PowerShell changes quotes inside a JSON argument, so the request body goes into body.json first and curl.exe sends that file. Type curl.exe, not curl: in Windows PowerShell 5.1, curl is a different command.

## Client setup examples

For supported coding clients, the recommended setup is the globally installed `scalemax` CLI. The snippets below document the manual fallback shape.

**Codex**

**macOS / Linux**

```bash
# Recommended
npm install -g scalemax
scalemax

# Manual Codex provider config is documented at:
# https://docs.scalemax.pro/docs/manual-configuration/codex
```

**Windows PowerShell**

```powershell
# Recommended
npm.cmd install -g scalemax
scalemax.cmd

# Manual Codex provider config is documented at:
# https://docs.scalemax.pro/docs/manual-configuration/codex
```

Windows PowerShell blocks npm’s .ps1 launchers by default (“running scripts is disabled on this system”), so these commands use the .cmd launcher: npx.cmd, npm.cmd, scalemax.cmd. In Command Prompt you can leave out .cmd.

**Cursor**

settings.json:

```json
{
  "openai.baseURL": "YOUR_SCALEMAX_BASE_URL",
  "openai.apiKey": "your-scale-max-key"
}
```

**OpenCode**

config.json:

```json
{
  "client": "OpenCode",
  "provider": "openai-compatible",
  "baseURL": "YOUR_SCALEMAX_BASE_URL",
  "apiKey": "your-scale-max-key"
}
```

Full per-client walkthroughs live in the [manual configuration guides](https://docs.scalemax.pro/docs/manual-configuration). For language-specific pages, see [Python](https://docs.scalemax.pro/docs/examples/python), [JavaScript](https://docs.scalemax.pro/docs/examples/javascript), and [cURL](https://docs.scalemax.pro/docs/examples/curl); for the field-by-field contract, see [OpenAI compatibility](https://docs.scalemax.pro/docs/openai-compatibility).
