---
title: "Calling with curl"
description: "Without installing any SDK, use curl to call 1折AI's /v1/messages and /v1/chat/completions, list models, test caching, and view streaming output."
headingIds: {"Anthropic native: /v1/messages":"section-1","OpenAI compatible: /v1/chat/completions":"section-2","Model list: /v1/models":"section-3","Streaming output":"section-4","Testing caching":"section-5","Add -i when troubleshooting":"section-6"}
---

<aside className="docs-publication" data-pagefind-ignore>

Documentation maintained by [1ZheAI](https://1zheai.com/en/editorial/#publisher). [Sources and corrections](https://1zheai.com/en/editorial/).

Found an error? [Contact support](mailto:support@1zheai.com) with the page address and a description. Do not send API keys or account credentials.

</aside>
curl is the fastest way to confirm whether the API key and endpoint actually work. Every command below can be copied directly. First, put your API key into an environment variable:

```bash
export ONEZHE_API_KEY="sk-你的Key"
```

Windows users are advised to run these commands in WSL or Git Bash; for PowerShell syntax, see [Quick Start](/en/docs/quickstart/).

## Anthropic native: /v1/messages

```bash
curl https://1zheai.com/v1/messages \
  -H "x-api-key: $ONEZHE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 128,
    "messages": [{"role": "user", "content": "ping"}]
  }'
```

## OpenAI compatible: /v1/chat/completions

```bash
curl https://1zheai.com/v1/chat/completions \
  -H "Authorization: Bearer $ONEZHE_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "messages": [{"role": "user", "content": "ping"}]
  }'
```

## Model list: /v1/models

```bash
curl https://1zheai.com/v1/models \
  -H "Authorization: Bearer $ONEZHE_API_KEY"
```

## Streaming output

Add `"stream": true` and use `-N` to turn off curl's buffering so you can see the response arrive chunk by chunk:

```bash
curl -N https://1zheai.com/v1/messages \
  -H "x-api-key: $ONEZHE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 128,
    "stream": true,
    "messages": [{"role": "user", "content": "从一数到五"}]
  }'
```

For the event format, see [Streaming Output](/en/docs/streaming/).

## Testing caching

Send the same request twice in a row; if the `usage.cache_read_input_tokens` in the second response is greater than 0, it means the cache was hit. The text in `system` needs to reach the model's minimum cacheable length. For the full script, see [Verify Models and Usage](/en/docs/verify-model/), and for the underlying mechanism, see [Prompt Caching](/en/docs/prompt-caching/).

```bash
curl https://1zheai.com/v1/messages \
  -H "x-api-key: $ONEZHE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "max_tokens": 32,
    "system": [{
      "type": "text",
      "text": "把一段至少 512 token、每次都一样的长文本放在这里",
      "cache_control": {"type": "ephemeral"}
    }],
    "messages": [{"role": "user", "content": "ping"}]
  }'
```

## Add -i when troubleshooting

```bash
curl -i https://1zheai.com/v1/models -H "Authorization: Bearer $ONEZHE_API_KEY"
```

`-i` will print the status code and response headers. For the meaning of status codes, see [Error Codes and Troubleshooting](/en/docs/troubleshooting/).
