> For the complete documentation index, see [llms.txt](https://docs.apismart.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apismart.ai/sdks-and-migration/curl.md).

# cURL

Use cURL to send ApiSmart API requests directly from a terminal or command line.

It is useful for testing authentication, validating a Model ID, and checking request formats before integrating the API into an application.

For general API rules, see [**API Basics**](/api-guides/api-basics.md).

***

### Before You Begin

Make sure you have:

* An active **API Token**
* Sufficient **Current Balance**
* A valid **Model ID**
* cURL installed on your system

Set your API Token as an environment variable:

```bash
export APISMART_API_KEY="YOUR_API_KEY"
```

***

### Chat Completions

Send a request to a supported language model:

```bash
curl https://gw.apismart.ai/v1/chat/completions \
  -H "Authorization: Bearer $APISMART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'
```

Replace `YOUR_MODEL_ID` with the exact Model ID shown in the selected model’s **Code Example**.

***

### Image Generation

Send a basic image generation request:

```bash
curl https://gw.apismart.ai/v1/images/generations \
  -H "Authorization: Bearer $APISMART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "prompt": "A futuristic city at sunset"
  }'
```

Image request fields may vary by model.

***

### Video Generation

Video generation uses an asynchronous task workflow.

For a model that accepts `prompt` and `duration`, a request may look like:

```bash
curl https://gw.apismart.ai/v1/video/tasks \
  -H "Authorization: Bearer $APISMART_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "prompt": "A cinematic view of waves at sunset",
    "duration": 5
  }'
```

Then use the returned task ID to check its status:

```bash
curl https://gw.apismart.ai/v1/video/tasks/{task_id} \
  -H "Authorization: Bearer $APISMART_API_KEY"
```

> ⚠️ **Important:** Always use the exact Model ID, endpoint, request fields, and supported values shown in the selected model’s **Code Example**.

***

### Common Options

Useful cURL options include:

| Option | Purpose                                             |
| ------ | --------------------------------------------------- |
| `-H`   | Add a request header                                |
| `-d`   | Send a request body                                 |
| `-i`   | Include response headers                            |
| `-v`   | Display detailed request and connection information |

Use `-v` when troubleshooting connection or HTTP request issues, but avoid sharing output that contains your full API Token.

***

### 🛠️ Common Problems

| Problem                        | What to Check                                     |
| ------------------------------ | ------------------------------------------------- |
| **401 / authentication error** | API Token and Bearer header                       |
| **Model not found**            | Exact Model ID and capitalization                 |
| **Invalid request**            | Endpoint, JSON syntax, and model-specific fields  |
| **Insufficient balance**       | Current Balance and API Token remaining allowance |

For failed requests, review the related record in [**Usage Logs and Costs**](/api-usage/usage-logs-and-costs.md).

> 🔐 Never provide your full API Token to support.

***

### 🚀 Next Steps

Continue with:

* [Python](/sdks-and-migration/python.md)
* [JavaScript and TypeScript](/sdks-and-migration/javascript-and-typescript.md)
* [API Basics](/api-guides/api-basics.md)
* [Choose a Model and Find Its Model ID](/models-and-pricing/models-and-model-ids.md)
* [Chat Completions API](/api-guides/chat-completions-api.md)
