## Overview

You can use ModelStack directly with cURL or any HTTP client. No SDK required — just make standard HTTP requests.

## Chat Completion

```bash
curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is ModelStack?"}
    ]
  }'
```

## With Parameters

```bash
curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "user", "content": "Explain quantum computing in 3 sentences."}
    ],
    "temperature": 0.5,
    "max_tokens": 200
  }'
```

## Streaming

Add `"stream": true` to get Server-Sent Events:

```bash
curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -N \
  -d '{
    "model": "claude-sonnet-4-5",
    "messages": [
      {"role": "user", "content": "Write a haiku about programming."}
    ],
    "stream": true
  }'
```

<Note>
  The `-N` flag disables cURL's output buffering, allowing you to see streamed
  tokens in real time.
</Note>

## List Models

```bash
curl https://api.modelstack.cc/v1/models \
  -H "Authorization: Bearer your_api_key"
```

## Using Different Models

Simply change the `model` field to switch providers:

```bash
# Anthropic Claude
curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-5", "messages": [{"role": "user", "content": "Hello!"}]}'

# OpenAI GPT-4o
curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello!"}]}'

# Google Gemini
curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini-2.5-pro", "messages": [{"role": "user", "content": "Hello!"}]}'
```

## Using Environment Variables

Set your API key as an environment variable to avoid repeating it:

```bash
export MODELSTACK_API_KEY="your_api_key"

curl https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer $MODELSTACK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

## Pretty-Printing JSON

Pipe the output through `jq` for formatted JSON:

```bash
curl -s https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "messages": [{"role": "user", "content": "Hello!"}]
  }' | jq .
```

## Extracting Just the Response Text

```bash
curl -s https://api.modelstack.cc/v1/chat/completions \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "messages": [{"role": "user", "content": "Hello!"}]
  }' | jq -r '.choices[0].message.content'
```
