跳转到内容

快速开始

本指南带你从新账户走到第一次生成。你将创建账户和 API 密钥,充值,发送一个对话请求,并查看余额。基础 URL 为 https://api.sakuranbo.ai/v1。

在控制台中注册,并按注册界面的提示完成各步骤。

打开控制台的 API 密钥页面,创建一个密钥。为密钥起一个名称。你也可以设置支出上限和到期日。详见余额与 API 密钥限额。

控制台只会在密钥创建后显示一次完整的密钥,请当时就复制。密钥以 cherry_ 开头。请把它保存在环境变量 SAKURANBO_API_KEY 中,本文档的所有示例都从这个变量读取密钥:

终端窗口
export SAKURANBO_API_KEY="paste-your-key-here"

切勿把密钥放进客户端代码或公开仓库。详见认证。

打开控制台的充值页面,使用银行卡或加密货币充值。页面会显示你可以使用的支付方式。默认的最低充值额为 $10.00。详情请参阅定价与计费。

使用你的 API 密钥向 POST /v1/chat/completions 发送请求。示例使用模型 sakuranbo/cherrytext-1.0-flash。

终端窗口
curl -X POST "https://api.sakuranbo.ai/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $SAKURANBO_API_KEY" \
-d '{
"model": "sakuranbo/cherrytext-1.0-flash",
"messages": [
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Summarize the benefits of prepaid API credits in two lines."
}
],
"max_tokens": 2048
}'

你也可以使用 OpenAI SDK 发送同样的请求。把 SDK 的基础 URL 设为 https://api.sakuranbo.ai/v1,把 API 密钥设为你的 Sakuranbo AI 密钥。

OpenAI SDK(TypeScript):

import OpenAI from "openai";
const apiKey = process.env.SAKURANBO_API_KEY;
if (!apiKey) throw new Error("Set the SAKURANBO_API_KEY environment variable.");
const client = new OpenAI({
baseURL: "https://api.sakuranbo.ai/v1",
apiKey,
});
const completion = await client.chat.completions.create({
model: "sakuranbo/cherrytext-1.0-flash",
messages: [
{
role: "system",
content: "You are a concise assistant."
},
{
role: "user",
content: "Summarize the benefits of prepaid API credits in two lines."
}
],
max_tokens: 2048
});
console.log(completion.choices[0]?.message.content);

OpenAI SDK(Python):

import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.sakuranbo.ai/v1",
api_key=os.environ["SAKURANBO_API_KEY"],
)
completion = client.chat.completions.create(
model="sakuranbo/cherrytext-1.0-flash",
messages=[
{
"role": "system",
"content": "You are a concise assistant.",
},
{
"role": "user",
"content": "Summarize the benefits of prepaid API credits in two lines.",
},
],
max_tokens=2048,
)
print(completion.choices[0].message.content)

响应是一个对话补全(chat completion)。生成的文本在 choices[0].message.content 中。usage 包含 token 数量和 usage.cost,后者是该请求的费用。usage.cost 以 amount_micro_usd 给出 micro USD 金额,并以 amount_usd 给出十进制字符串形式的金额。

使用 GET /v1/balance 读取你的余额。

终端窗口
curl "https://api.sakuranbo.ai/v1/balance" \
-H "Authorization: Bearer $SAKURANBO_API_KEY"

available_usd 是新请求可以使用的金额。held_usd 是运行中的请求已预留的金额。你刚才发送的请求已经结束,因此它的预留已经释放,费用也已经从 available_usd 中扣除。

  • 对话:流式输出、兼容 Anthropic 的端点和官方 SDK。
  • 图像和视频:生成图像和视频。
  • 费用预估 API:在运行请求之前计算它的价格。无需 API 密钥。
  • 模型 API:列出模型,并读取它们的输入参数和价格。
  • MCP 服务器:将编码代理连接到 Sakuranbo AI。