# cURL examples

> Copy secure cURL examples for ScaleMax model discovery, chat completions, and API-credit or token endpoints.

Direct HTTP calls are useful for debugging. For production applications, prefer an SDK — see [Python](https://docs.scalemax.pro/docs/examples/python), [JavaScript](https://docs.scalemax.pro/docs/examples/javascript), or the [OpenAI SDK](https://docs.scalemax.pro/docs/examples/openai-sdk) examples — and store the key in `SCALEMAX_API_KEY`.

This page uses the OpenAI-compatible route: API credit uses `https://api.scalemax.pro/v1`, while API-token keys use `https://api.scalemax.pro/token/v1`. A Claude token key must use a Claude model from its catalog. For native Anthropic Messages requests, use the origin-only route in the [Claude Code](https://docs.scalemax.pro/docs/manual-configuration/claude-code) or [Claude Desktop](https://docs.scalemax.pro/docs/manual-configuration/claude-desktop) guide.

Every example has a macOS/Linux and a Windows PowerShell version. Pick yours once; the page remembers it.

## Set your key

**macOS / Linux**

```bash
export SCALEMAX_API_KEY="your-scale-max-key"

# API-credit key:
export SCALEMAX_BASE_URL="https://api.scalemax.pro/v1"
# API-token key used through this OpenAI-compatible example:
# export SCALEMAX_BASE_URL="https://api.scalemax.pro/token/v1"

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

**Windows PowerShell**

```powershell
$env:SCALEMAX_API_KEY = "your-scale-max-key"

# API-credit key:
$env:SCALEMAX_BASE_URL = "https://api.scalemax.pro/v1"
# API-token key used through this OpenAI-compatible example:
# $env:SCALEMAX_BASE_URL = "https://api.scalemax.pro/token/v1"

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

## List models

**macOS / Linux**

models.sh:

```bash
curl "$SCALEMAX_BASE_URL/models" \
  -H "$SCALEMAX_AUTH_HEADER"
```

**Windows PowerShell**

models.ps1:

```powershell
curl.exe "$env:SCALEMAX_BASE_URL/models" `
  -H "$env:SCALEMAX_AUTH_HEADER"
```

## Chat completion

**macOS / Linux**

chat.sh:

```bash
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**

chat.ps1:

```powershell
@'
{
  "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.

## Streaming

**macOS / Linux**

stream.sh:

```bash
curl -N "$SCALEMAX_BASE_URL/chat/completions" \
  -H "$SCALEMAX_AUTH_HEADER" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_AUTHENTICATED_MODEL_ID",
    "stream": true,
    "messages": [{"role": "user", "content": "Stream a short greeting."}]
  }'
```

**Windows PowerShell**

stream.ps1:

```powershell
@'
{
  "model": "YOUR_AUTHENTICATED_MODEL_ID",
  "stream": true,
  "messages": [{"role": "user", "content": "Stream a short greeting."}]
}
'@ | Set-Content -Path body.json

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

## Windows PowerShell

The macOS/Linux commands do not work as typed in PowerShell. The Windows tabs above already account for this:

- Type `curl.exe`, not `curl`. In Windows PowerShell 5.1, `curl` runs a different command (`Invoke-WebRequest`) that rejects these options.
- Put the JSON body in a file and send the file: `curl.exe … --data-binary "@body.json"`. PowerShell strips the double quotes inside a `-d '{…}'` argument, and ScaleMax then answers `400` with “Request body is not valid JSON”. Keep the quotes around `"@body.json"`: a bare `@` means something else in PowerShell.
- Set variables with `$env:NAME = "value"` (this window only) or `setx NAME "value"` (new windows only — open a new terminal after `setx`).
- End a continued line with a backtick (`` ` ``), not a backslash.

Command Prompt (`cmd.exe`) has the same quoting problem; use PowerShell with the commands above.
