v1API 参考

Ergo API 文档

通过 OpenAI 兼容 API 调用 ergo-1.0 所需的一切:base URL、身份验证、请求参数、流式传输、工具调用、错误和计费。

  • POST/v1/chat/completions
  • GET/v1/models

Ergo API 以 OpenAI Chat Completions 格式暴露 Ergo 1.0。任何允许修改 base URL 的客户端,除 URL、模型 id 和密钥外都无需改动代码。

Base URL
https://ergollmapi.com/v1
模型 id
ergo-1.0
格式
OpenAI Chat Completions(JSON 和 server-sent events)

在 Authorization 请求头中以 Bearer token 发送你的 API key。登录后可在 API Keys 页面创建和吊销密钥。

HTTP 请求头
Authorization: Bearer $ERGO_API_KEY

请将密钥保存在你的服务器上,通过 ERGO_API_KEY 之类的环境变量加载,切勿放进浏览器代码。

打开 API Keys

POSThttps://ergollmapi.com/v1/chat/completions

POST https://ergollmapi.com/v1/chat/completions 为一段对话创建模型响应。流式传输默认关闭:如果不传 stream,你会得到单个 JSON 响应。下面的示例将 stream 设为 true。

curl https://ergollmapi.com/v1/chat/completions \
  -H "Authorization: Bearer $ERGO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ergo-1.0",
    "stream": true,
    "messages": [
      {"role": "user", "content": "Write a Python function that merges two sorted lists."}
    ]
  }'

请求参数

  • modelstring必填

    Must be "ergo-1.0". Any other value returns 400.

  • messagesarray必填

    Non-empty array of messages with role system, developer, user, assistant or tool. content is a string or an array of text parts. Images and files are not supported.

  • streamboolean可选

    Default false. When omitted or false the response is a single JSON object; set true to receive server-sent events.

  • stream_optionsobject可选

    Passed through to the model, as in the OpenAI API.

  • max_tokensinteger可选

    Positive integer upper bound on generated tokens. Values above 131072 are clamped to 131072 rather than rejected.

  • temperaturenumber可选

    Sampling temperature. Recommended: 1.0.

  • top_pnumber可选

    Nucleus sampling. Recommended: 0.99 (1.0 also works).

  • toolsarray可选

    Function tool definitions in OpenAI format.

  • tool_choicestring | object可选

    Forwarded in OpenAI format: "auto", "none", "required", or {"type": "function", "function": {"name": "..."}} to force one function.

  • parallel_tool_callsboolean可选

    Allow the model to return several tool calls in one turn.

  • response_formatobject可选

    Structured output request, for example {"type": "json_object"}.

  • reasoning_effortstring可选

    Accepted for compatibility. Ergo reasoning effort is fixed, so this value may be ignored.

Amazon 建议 Ergo 1.0 使用 temperature 1.0 和 top_p 0.99。Ergo 在回答前总会进行推理且推理强度固定,因此 reasoning_effort 可能会被忽略。超过 131072 的 max_tokens 会被截断为 131072。表中未列出的字段会被以 400 错误拒绝。

将 stream 设为 true 即可接收 server-sent events;当 stream 缺省或为 false 时,API 返回单个 JSON 对象。推理内容以 reasoning_content 增量到达,回答以 content 增量到达。data: [DONE] 之前的最后一个分块携带 usage 和 credits_consumed。

SSE
data: {"choices":[{"delta":{"reasoning_content":"The user wants a merge function..."}}]}

data: {"choices":[{"delta":{"content":"def merge(a, b):"}}]}

data: {"choices":[],"usage":{"prompt_tokens":24,"completion_tokens":212,"total_tokens":236},"credits_consumed":0.2}

data: [DONE]

在 tools 中传入函数定义,从 message.tool_calls 读取调用。tool_choice 接受 "auto"、"none"、"required" 或指定函数名以强制调用某个函数;parallel_tool_calls 允许在一轮中进行多次调用。以 tool 角色消息把结果发回。

Python
import json, os
from openai import OpenAI

client = OpenAI(base_url="https://ergollmapi.com/v1", api_key=os.environ["ERGO_API_KEY"])

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

response = client.chat.completions.create(
    model="ergo-1.0",
    messages=[{"role": "user", "content": "What is the weather in Oslo?"}],
    tools=tools,
)

call = response.choices[0].message.tool_calls[0]
print(call.function.name, json.loads(call.function.arguments))

GEThttps://ergollmapi.com/v1/models

GET https://ergollmapi.com/v1/models 返回你的密钥可用的模型,列表中包含 ergo-1.0。

curl
curl https://ergollmapi.com/v1/models \
  -H "Authorization: Bearer $ERGO_API_KEY"

错误返回一个 HTTP 状态码和一个 JSON 响应体,其中 error 对象包含 message、type 和 code。

JSON
{
  "error": {
    "message": "Insufficient credits.",
    "type": "insufficient_quota",
    "code": "insufficient_credits"
  }
}
  • 400invalid_request_errorinvalid_request

    含义: The request is invalid: a missing or wrong-typed field, an unsupported field, a model other than ergo-1.0, or non-text content.

  • 401authentication_errorinvalid_api_key

    含义: The API key is missing or invalid.

  • 402insufficient_quotainsufficient_credits

    含义: Your credit balance is too low for this request. Top up on the pricing page.

  • 429rate_limit_errorrate_limit_exceeded

    含义: Too many requests. Retry with exponential backoff.

  • 502upstream_errorupstream_error

    含义: The upstream provider returned an error.

  • 503service_unavailableservice_unavailable

    含义: The upstream provider is busy or timed out. Retry shortly.

对 429、502 和 503 响应用指数退避重试。在修复请求、密钥或余额之前,不要重试 400、401 或 402。

  • 仅支持文本输入,不支持图片和文件。
  • 上下文窗口:1,048,576 token。
  • 单次请求最大输出:131,072 token(max_tokens 最大 131072)。
  • 请求可能被限流;429 响应表示需要带退避重试。

用量按 token 以积分计费。积分包和订阅方案见定价页面。

模型输入每 1M token输出每 1M token
ergo-1.0输入每 1M token300 积分输出每 1M token900 积分

每次请求至少收取 0.05 积分。

查看定价