Skip to main content

API access

Use WonderAgent models and account credits in OpenAI-compatible clients and scripts.

WonderAgent provides an OpenAI-compatible API. Create a personal API key in API in the sidebar and use it in a compatible client, workflow, or script. API requests use the same account credits as web chats.

Connect a client

  1. 1Create a key. Open API, click Create API Key, and give it a name that describes its purpose. Copy the secret immediately. It is shown only once.
  2. 2Copy the Base URL. Use the exact Base URL shown on your API page, including /api/ai/v1. Paste it and your API key into the client.
  3. 3Select a model. Model IDs match the web app. Request GET /models to see the current list, then use one of those IDs.

A lost secret cannot be recovered. Revoke the key and create another. Revocation takes effect immediately. Each account can have up to 10 active keys.

Endpoints

ItemValue
Base URLCopy from API in WonderAgent
AuthenticationAuthorization: Bearer <API key> request header
ChatPOST /chat/completions, using OpenAI Chat Completions format, including stream: true for streaming
ModelsGET /models, returning currently available models

Use the usual model, messages, temperature, and stream fields. The response text is in choices[0].message.content, and usage contains the token counts.

Examples

Set WONDERAGENT_BASE_URL to the Base URL copied from your API page, WONDERAGENT_API_KEY to your secret, and WONDERAGENT_MODEL to a model ID returned by GET /models.

curl

curl "$WONDERAGENT_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $WONDERAGENT_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"model\": \"$WONDERAGENT_MODEL\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}]}"

Python

Use the openai package:

import os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["WONDERAGENT_BASE_URL"],
    api_key=os.environ["WONDERAGENT_API_KEY"],
)
reply = client.chat.completions.create(
    model=os.environ["WONDERAGENT_MODEL"],
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)

Node.js

Use the openai package:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: process.env.WONDERAGENT_BASE_URL,
  apiKey: process.env.WONDERAGENT_API_KEY,
});
const reply = await client.chat.completions.create({
  model: process.env.WONDERAGENT_MODEL,
  messages: [{ role: "user", content: "Hello" }],
});
console.log(reply.choices[0].message.content);

In a graphical client, choose an OpenAI-compatible provider, enter the Base URL and key, and set the model ID.

Credits and limits

  • API and web requests share daily and weekly credits. Daily credits reset at midnight and weekly credits on Monday at midnight, Beijing time (UTC+8). See Plans and credits.
  • Models and credit rates match the web app. Models above 2.0× require a paid plan. All plans meter actual token usage rather than message counts. Free accounts receive 10 credits per day. See Models and credit usage.
  • An account can have up to 4 requests in flight. Further requests receive 429.
  • API requests do not include custom instructions from the web app's personalization settings. Your client controls its system prompt.

Error responses

Statuserror.typeMeaning
401invalid_api_keyThe key is invalid or revoked
403account_disabledThe account is disabled
400model_not_allowedThe model is unavailable. Check GET /models
403model_requires_membershipThe model requires a paid plan
429quota_exceeded or too_many_requestsCredits are exhausted or too many requests are in flight

Manage keys

Store secrets in environment variables or your client's secret settings. Do not put them in public repositories or browser code.

Use a separate key for each integration so you can revoke one without affecting the others. Revoke keys you no longer use. The API page shows each key's most recent use.