> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ycloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API 接口

> 使用 API key 进行身份验证，并通过 YCloud API 发送 SMS 消息。

## 获取 API key

YCloud 使用 API key 验证服务端请求。在 [**控制台 > 开发者 > API keys**](https://www.ycloud.com/console/#/app/developers/apikey) 中创建或查看 API key，然后在 `X-API-Key` 请求标头中发送它。

<Warning>
  请将 API key 保存在您的服务器上。切勿将其提交到代码仓库，或暴露在浏览器或移动应用程序代码中。
</Warning>

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST 'https://api.ycloud.com/v2/sms' \
  --header 'X-API-Key: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "to": "+16315551234",
    "text": "Your verification code is 123456."
  }'
```

如果您更倾向于使用 SDK，请参阅 [YCloud 开发者](https://github.com/ycloud-developers) 中的支持语言及安装说明。

## 探索端点

打开 [发送 SMS](/api-reference/sms/send-an-sms) 以获取完整的请求参数、响应结构以及交互式请求构建器。有关端到端集成工作流程和送达注意事项，请参阅 [发送 SMS](/zh/api-reference/guides/messaging/send-sms)。

## 处理响应

`2xx` 响应表示 YCloud 已接受该请求，但这并不一定意味着 SMS 已送达收件人。请保存返回的消息 ID，并将其与查询结果或 Webhook 事件关联以跟踪送达状态。

## 处理错误

错误响应包含三个字段：

* `code` 是稳定的机器可读错误标识符。
* `message` 面向开发者说明错误信息。
* `requestId` 用于协助 YCloud 支持团队排查请求问题。

请在应用程序逻辑中使用稳定的错误标识符，不要匹配面向开发者的说明文本。有关响应格式和重试指引，请参阅 [处理错误](/zh/api-reference/guides/api-fundamentals/handle-errors)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.