JUYUAN / MODEL SERVICES
Docs
Text generation API, error codes, and agent setup
On this page

API

Text generation API

Text generation exposes three inbound protocols: Chat Completions, Anthropic Messages, and OpenAI Responses, plus Messages count_tokens. A channel can advertise multiple protocols; when a model has a native channel for the inbound protocol the gateway passes it through, otherwise Messages/Responses are converted to an OpenAI Chat channel. In every case model is a model ID from the catalog.

APIMethod and pathStatus
Chat CompletionsPOST https://www.jytoken.net/v1/chat/completionsAvailable
MessagesPOST https://www.jytoken.net/v1/messagesAvailable
Messages count_tokensPOST https://www.jytoken.net/v1/messages/count_tokensAvailable
ResponsesPOST https://www.jytoken.net/v1/responsesAvailable

Native protocol channels provide the highest fidelity. On an OpenAI Chat conversion channel, capabilities Chat cannot represent (Anthropic thinking, hosted/built-in tools, document/audio/video blocks) return 400 instead of being dropped silently.

There is no separate Gemini-native API and no Interactions API. gemini-3.8-flash in the Model Plaza uses Chat Completions like every other model; set model to the model ID from the catalog.

How to use

Create a key on the Platform Keys page first. The API base URL is /v1 on the current site; Chat Completions and Responses use Authorization: Bearer, while Messages accepts both x-api-key and Bearer.

ItemValue
API KeyPlatform key; Bearer or x-api-key
API_URLhttps://www.jytoken.net/v1
Chat Completionshttps://www.jytoken.net/v1/chat/completions
Messageshttps://www.jytoken.net/v1/messages
Messages count_tokenshttps://www.jytoken.net/v1/messages/count_tokens
Responseshttps://www.jytoken.net/v1/responses
Model listGET https://www.jytoken.net/v1/models
Key informationGET https://www.jytoken.net/v1/key

Vendor parameters

Vendor parameters follow the model catalog; do not infer them from the model name. Current text models have empty capabilities and reasoning_efforts, and both input and output modalities are text. Do not switch to enable_thinking, thinking.type, or thinking_config when calling. Video models are documented under Video generation.

The platform rewrites only two things: it replaces model with the upstream model name for that model, and when stream is true and the request has no stream_options, it adds {"include_usage": true}. All other fields are forwarded unchanged. Pass reasoning_effort only when the model's reasoning_efforts is non-empty, and the value must be one of the listed entries. Currently all are empty; do not send this field.

Model IDVendorInputOutput
deepseek-V4.1-flash-1017deepseektexttext
gemini-3.8-flashopenaitexttext
gpt-6-astraopenaitexttext
gpt-6-lunaopenaitexttext
gpt-6.1-solopenaitexttext
gpt-6.1-terraopenaitexttext

Set model to a model ID from the table above. The latest list comes from GET /v1/models, which returns model IDs available to the current key and backed by an enabled channel.

Chat Completions request parameters

Endpoint: POST https://www.jytoken.net/v1/chat/completions

ParameterDescriptionRequiredType
modelModel ID, see the previous sectionYesstring
messagesConversation messages, see the next sectionYesarray
max_tokensMaximum tokens for this reply. If omitted, the upstream decidesNointeger
temperatureForwarded unchanged. The catalog does not specify a rangeNonumber
top_pForwarded unchanged. The catalog does not specify a rangeNonumber
streamtrue for SSE streaming, false for a single JSON response. Defaults to falseNoboolean
stream_optionsStreaming usage control. When omitted with stream true, the platform adds include_usage=trueNoobject
stopStop sequence, string or string array, forwarded unchangedNostring or array
nNumber of completions, forwarded unchangedNointeger
userEnd-user identifier, forwarded unchangedNostring

tools, tool_choice, and any other JSON fields not listed here are also forwarded unchanged. The platform does not rename fields based on the vendor.

Messages parameters

Each message is an object, and role is system, user, or assistant. Input modalities for the current catalog models are all text, so content is a string.

RoleFieldsDescription
systemrole, contentSystem prompt. role is system and content is a string
userrole, contentUser input. role is user and content is a string
assistantrole, contentUsed when writing history. role is assistant and content is a string

Request examples

Non-streaming
curl https://www.jytoken.net/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [{"role": "user", "content": "Say hello in three sentences"}]
  }'
Streaming
curl https://www.jytoken.net/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "stream": true,
    "messages": [{"role": "user", "content": "Say hello in three sentences"}]
  }'

Response parameters

A non-streaming response is the upstream JSON. Billing only reads usage.prompt_tokens and usage.completion_tokens; if either is missing, the call returns 502 instead of being treated as successful.

ParameterDescriptionType
idCompletion IDstring
objectAlways chat.completionstring
createdUnix timestamp in secondsinteger
modelModel name in the responsestring
choicesReply list, see the next tablearray
usage.prompt_tokensInput token countinteger
usage.completion_tokensOutput token countinteger
usage.total_tokensInput plus outputinteger
usage.prompt_tokens_details.cached_tokensCached input tokens. This field may be absent when the upstream does not return itinteger
choices fieldDescription
indexStarts at 0
finish_reasonstop means a normal finish, length means the length limit was reached. Other values come from the upstream unchanged
message.roleassistant
message.contentReply text
Non-streaming response
{
  "id": "e007a136b54e49aaa0e3c2b9aa3dc27e",
  "object": "chat.completion",
  "created": 1793604508,
  "model": "YOUR_MODEL_ID",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {"role": "assistant", "content": "Hi, how are you?"}
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 9,
    "total_tokens": 21,
    "prompt_tokens_details": {"cached_tokens": 0},
    "completion_tokens_details": {"reasoning_tokens": 0}
  }
}

A streaming response uses SSE. Each data: line carries one JSON object, and data: [DONE] marks the end. Incremental text is in choices[0].delta.content.

Streaming response
data: {"id":"chatcmpl-example","object":"chat.completion.chunk","created":1793604511,"model":"YOUR_MODEL_ID","choices":[{"index":0,"delta":{"content":"Hi"}}]}

data: [DONE]

If the stream breaks, the upstream omits complete usage, or settlement fails, you receive a data: {"error": ...} line. When the balance is insufficient, error.type is insufficient_quota and error.code is insufficient_balance or insufficient_budget.

Messages API

Endpoint: POST https://www.jytoken.net/v1/messages. Authentication accepts x-api-key and Authorization: Bearer; send anthropic-version: 2023-06-01 as well. max_tokens is required.

system, messages, content blocks, tools, and tool_choice are accepted in Anthropic Messages form. Routing is native-first: a model with an Anthropic channel passes through unchanged; otherwise the gateway converts to an OpenAI Chat channel.

On the conversion path, thinking.type=enabled, document/audio/video blocks, MCP/container, and images/documents inside tool_result return 400 unsupported_by_provider. Historical assistant thinking blocks are dropped without blocking the main flow.

Non-streaming
curl https://www.jytoken.net/v1/messages \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Say hello in three sentences"}]
  }'
Non-streaming response
{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "YOUR_MODEL_ID",
  "content": [{"type": "text", "text": "Hi, how are you?"}],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 12,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 9
  }
}

The streaming event order is message_start → content_block_start → content_block_delta* → content_block_stop → message_delta → message_stop, with no data: [DONE]. Tool arguments arrive through input_json_delta.

Streaming response
event: message_start
data: {"type":"message_start","message":{"id":"msg_example","type":"message","role":"assistant","model":"YOUR_MODEL_ID","content":[],"usage":{"input_tokens":12,"output_tokens":0}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":9}}

event: message_stop
data: {"type":"message_stop"}

For context budgeting, call POST https://www.jytoken.net/v1/messages/count_tokens. With an Anthropic channel it is proxied upstream; on the conversion path it returns a local estimate and is not billed or written to usage logs.

count_tokens
curl https://www.jytoken.net/v1/messages/count_tokens \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [{"role": "user", "content": "Say hello in three sentences"}]
  }'

Responses API

Endpoint: POST https://www.jytoken.net/v1/responses. Authentication uses Authorization: Bearer. input is required and may be a string or a Responses item array; max_output_tokens, instructions, tools, and tool_choice are accepted in Responses form.

Routing is native-first: a model with a Responses channel passes through unchanged; otherwise the gateway converts to an OpenAI Chat channel. The conversion path supports text, images, function tools, and the custom/namespace tool bridge used by Codex. Hosted tools (web_search/tool_search), local_shell_call, previous_response_id, conversation, background, and store=true return 400.

Non-streaming
curl https://www.jytoken.net/v1/responses \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "input": "Say hello in three sentences"
  }'
Non-streaming response
{
  "id": "resp_example",
  "object": "response",
  "created_at": 1793604508,
  "status": "completed",
  "model": "YOUR_MODEL_ID",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [{"type": "output_text", "text": "Hi, how are you?"}]
    }
  ],
  "usage": {
    "input_tokens": 12,
    "output_tokens": 9,
    "total_tokens": 21,
    "input_tokens_details": {"cached_tokens": 0},
    "output_tokens_details": {"reasoning_tokens": 0}
  }
}

Streaming events include response.created, response.output_item.added, response.output_text.delta, response.output_item.done, and response.completed; tool calls use response.function_call_arguments.delta. There is no data: [DONE].

Streaming response
event: response.created
data: {"type":"response.created","sequence_number":0,"response":{"id":"resp_example","object":"response","status":"in_progress","model":"YOUR_MODEL_ID","output":[]}}

event: response.output_text.delta
data: {"type":"response.output_text.delta","sequence_number":1,"delta":"Hi"}

event: response.completed
data: {"type":"response.completed","sequence_number":2,"response":{"id":"resp_example","object":"response","status":"completed","model":"YOUR_MODEL_ID","output":[{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Hi"}]}],"usage":{"input_tokens":12,"output_tokens":9,"total_tokens":21}}}

Error codes

The error body is {"error": {"message", "type", "code"}}, where type and code are the same. Messages uses the Anthropic envelope {"type":"error","error":{"type","message"}}; Responses and Chat use the OpenAI envelope above.

HTTPtypeDescription
400invalid_request_errorThe request body is not valid JSON
401invalid_api_keyThe key is missing, malformed, invalid, revoked, or expired
402insufficient_balanceThe account balance is insufficient
402insufficient_budgetThis key's budget limit has been exhausted
403model_not_allowedThe key's model scope does not include this model
403model_not_activatedThe current account has not activated this model
404model_not_foundThe model ID does not exist
429rate_limit_exceededThe per-minute request or token limit for this key was exceeded
502upstream_errorThe upstream failed, or the response lacked complete prompt_tokens and completion_tokens
503no_available_channelNo channel is available for this model
503billing_unavailableBilling is temporarily unavailable

Video generation

Video API

Available paths

Video generation is asynchronous. Submit a task, then query it with the returned id. Authentication is the same as text: Authorization: Bearer <platform key>.

APIMethod and pathDescription
Create taskPOST https://www.jytoken.net/v1/videosCreates a video task and returns its id immediately
Get taskGET https://www.jytoken.net/v1/videos/{id}Reads task status; returns the result URL when complete

Only models whose input_modalities include video can be submitted. Those models currently still record output_modalities as text. The API returns a video task and result URL, not chat text.

Current video models

Catalog

These are the video models currently callable on the test site. The vendor is volcengine_ark. Set model to the model ID.

Model IDVendorCatalog inputCatalog output
doubao-seedance-2-0-260128volcengine_arkvideotext
dreamina-seedance-2-0-260128volcengine_arkvideotext
dreamina-seedance-2-0-fast-260128volcengine_arkvideotext
dreamina-seedance-2-5-260628volcengine_arkvideotext

Create-task parameters

Request fields

Endpoint: POST https://www.jytoken.net/v1/videos. The body is JSON.

ParameterDescriptionRequiredType
modelVideo model ID, see the previous sectionYesstring
promptText prompt. Fill this for text-to-videoNostring
secondsDuration in seconds. Values below 4 become 4; values above 30 become 30Nointeger
resolutionResolution. Billing uses 1080p when omitted. Allowed: 480p, 720p, 1080p, 1440p, 2160p, 4kNostring
first_frame_imageFirst-frame image URL. An empty string means omittedNostring
last_frame_imageLast-frame image URLNostring
reference_imagesList of reference image URLsNoarray

A request with a first frame, last frame, or reference image is billed as media input; otherwise it is billed as text-to-video. Use http or https image URLs. A task is kept for at most 60 minutes. If it is still unfinished, it is marked failed and the hold is released.

Submit example and response

Request example

Create a video task
curl https://www.jytoken.net/v1/videos \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dreamina-seedance-2-0-260128",
    "prompt": "海边日落,镜头缓慢前推",
    "seconds": 5,
    "resolution": "1080p"
  }'

Create response

A successful submit returns immediately, before the video exists. id is the platform task ID and is the value to query. status is queued.

Create response
{
  "id": "01M6VIDEOEXAMPLETASKID",
  "object": "video",
  "model": "dreamina-seedance-2-0-260128",
  "status": "queued",
  "created_at": 1793604508,
  "seconds": 5,
  "resolution": "1080p"
}

Query a task

Query request

GET /v1/videos/{id} returns a task only to the account that created it. Use the id from the create response, not the upstream task id.

Query a video task
curl https://www.jytoken.net/v1/videos/01M6VIDEOEXAMPLETASKID \
  -H "Authorization: Bearer YOUR_API_KEY"

Status

statusDescription
queuedSubmitted and waiting
in_progressGenerating
completedFinished. url is an array of result URLs
failedFailed. error is the code and message is the detail. A failure is not charged

Completed response

Query response
{
  "status": "completed",
  "object": "video",
  "model": "dreamina-seedance-2-0-260128",
  "created_at": 1793604508,
  "seconds": 5,
  "resolution": "1080p",
  "url": ["https://example.com/result.mp4"]
}

Video error codes

Create and query errors

The error body matches the text API: {"error": {"message", "type", "code"}}.

HTTPtypeDescription
400invalid_request_errorThe body is not valid JSON, or the current channel cannot build a video request
400invalidRequestIdThe query has no task id
400body_limit_exceededThe body exceeds the size limit
401invalid_api_keyThe key is missing, invalid, revoked, or expired
402insufficient_balanceThe account balance cannot cover the hold
402insufficient_budgetThis key's budget limit is exhausted
403model_not_allowedThe key's model scope does not include this model
403model_not_activatedThe account has not activated this model
404model_not_foundThe model ID does not exist
404model_not_videoThis model is not a video model
404platform_task_id_invalidThe task id does not exist
404platform_task_not_foundThe task does not belong to the current account
502upstream_errorUpstream submit failed, or no task id was returned. Nothing is charged
503no_available_channelThis model has no available channel
503price_not_configuredThis model has no video price and cannot be submitted
503billing_unavailableBilling is temporarily unavailable

Account balance

Balance and cumulative usage

EndpointMethod and pathDescription
Account limitGET https://www.jytoken.net/v1/dashboard/billing/subscriptionReturns the account total limit, available balance, and cumulative usage
Cumulative usageGET https://www.jytoken.net/v1/dashboard/billing/usageReturns settled usage in cents

The query is account-scoped, not key-scoped. Any active key in the same account sees the same wallet balance. Amounts are always USD.

Subscription response

Query the account limit
curl https://www.jytoken.net/v1/dashboard/billing/subscription \
  -H "Authorization: Bearer YOUR_API_KEY"
Response example
{
  "object": "billing_subscription",
  "has_payment_method": true,
  "soft_limit_usd": 100,
  "hard_limit_usd": 100,
  "system_hard_limit_usd": 100,
  "access_until": 1796198400,
  "balance_usd": 70,
  "held_usd": 5.35,
  "remaining_usd": 64.65,
  "currency": "USD"
}

hard_limit_usd is available balance plus cumulative usage. Legacy clients compute the remaining balance as hard_limit_usd - total_usage / 100, which yields the available balance. remaining_usd, balance_usd, and held_usd are platform extensions you can read directly. access_until is compatibility only; prepaid accounts have no real expiry date.

Usage response

Query cumulative usage
curl https://www.jytoken.net/v1/dashboard/billing/usage \
  -H "Authorization: Bearer YOUR_API_KEY"
Response example
{
  "object": "list",
  "total_usage": 3535.0842,
  "total_usage_usd": "35.350842",
  "currency": "USD"
}

total_usage is in cents and is cumulative settled usage for the account, not usage in the requested date range. start_date and end_date are accepted for compatibility and ignored. For range reporting, use the console usage page or export.

Agent setup

OpenCode

Setup

OpenCode can connect through Chat Completions and is available now. After installation, run /connect and enter juyuan as the provider ID. Paste the key only in this step; do not put it in the config file.

Config file

Place the config in opencode.json in your user directory or at the project root. npm must be @ai-sdk/openai-compatible so requests go to /v1/chat/completions. Set baseURL to /v1 only. Use a model ID from the catalog, for example gpt-6-sol. Save the file, run /models, and select juyuan/gpt-6-sol.

opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "juyuan": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "聚元 TokenHub",
      "options": {
        "baseURL": "https://www.jytoken.net/v1"
      },
      "models": {
        "YOUR_MODEL_ID": { "name": "YOUR_MODEL_ID" }
      }
    }
  }
}

providers format

If your installed version uses providers instead of provider at the top level, the fields differ: put the package name in package, the URL in settings.baseURL, and the key variable name in env. With the wrong version's fields, the config is ignored and requests never reach this site.

opencode.json (providers format)
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "juyuan": {
      "name": "聚元 TokenHub",
      "env": ["JUYUAN_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": {
        "baseURL": "https://www.jytoken.net/v1"
      },
      "models": {
        "YOUR_MODEL_ID": { "name": "YOUR_MODEL_ID" }
      }
    }
  }
}

WorkBuddy

Setup

WorkBuddy custom models use Chat Completions and are available now. Open Models in Settings, or choose Custom at the bottom of the model picker, and select Custom as the provider.

Fields

FieldValue
Endpointhttps://www.jytoken.net/v1
API KeyThe platform key itself, without Bearer
Model nameA model ID from the catalog, for example gpt-6-sol
Custom protocolOff. When off, do not append /chat/completions to the endpoint
Image inputOff. Input modalities for the current catalog models are text
Thinking modeOff. reasoning_efforts for the current catalog is empty
Tool callingOff for now. capabilities is empty and the platform only forwards tools unchanged

After saving, test the connection, then select this model in a new task. If the endpoint already ends with /v1/chat/completions while Custom protocol is off, the path is appended twice and returns 404.

Codex

Codex only uses the Responses protocol; wire_api must be responses, and that is also the default when omitted. It requests /responses after base_url. Write the following to .codex/config.toml in your user directory. On Windows that is %USERPROFILE%\.codex\config.toml. A project-level .codex/config.toml cannot change model_providers and will not take effect. Put the key in the JUYUAN_API_KEY environment variable, not in the file.

Set model to a catalog model ID that has a channel. A native Responses channel passes through unchanged; an OpenAI Chat-only model is converted automatically, which supports text and function tools. Responses-only features such as hosted tools and previous_response_id return 400.

config.toml
model = "YOUR_MODEL_ID"
model_provider = "juyuan"

[model_providers.juyuan]
name = "聚元 TokenHub"
base_url = "https://www.jytoken.net/v1"
env_key = "JUYUAN_API_KEY"
wire_api = "responses"

Claude Code

Claude Code uses Anthropic Messages. ANTHROPIC_BASE_URL points to the site root, and it requests /v1/messages itself. ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer, and ANTHROPIC_API_KEY is sent as x-api-key; both are accepted. Do not commit the key to the project repository. User-level config lives in ~/.claude/settings.json; on Windows that is %USERPROFILE%\.claude\settings.json.

Set ANTHROPIC_MODEL to a catalog model ID that has a channel. A native Anthropic channel passes through unchanged; an OpenAI Chat-only model is converted automatically, which supports text, images, and tool_use/tool_result. thinking, document/audio/video, and MCP return 400. Use /status to verify the actual endpoint and key source.

settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.jytoken.net",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
    "ANTHROPIC_MODEL": "YOUR_MODEL_ID"
  }
}

Other clients

Chat Completions clients

For clients that only call Chat Completions, set Base URL to https://www.jytoken.net/v1, use Authorization: Bearer, and set model to a model ID from the catalog.

Messages / Responses clients

For /v1/messages, set Base URL to https://www.jytoken.net/v1 and use x-api-key or Bearer; for /v1/responses, use Bearer. Both can reuse catalog models: the gateway applies native-first routing and falls back to OpenAI Chat conversion when no native channel exists.