New APINew API
User GuideInstallationAPI ReferenceAI ApplicationsSkillsHelp & SupportBusiness Cooperation
User Guide

Using API and Playground

Use the playground to test and experience AI models online, and call New API via OpenAI-compatible interfaces.

Playground

  • The playground is used for simple online testing and experiencing AI models. Users can input questions or instructions, interact with the model, and view the generated results. ​
  1. Select Group and Model: In the bottom right of the input box, select the available model group and specific model to confirm the model used for this conversation.
  2. Set Request Parameters: Click the parameter settings button to enable and adjust generation parameters such as Temperature, Top P, Frequency Penalty, Presence Penalty, and Max Tokens as needed.
  3. Fill in Conversation Content: Enter questions, instructions, or prompts in the bottom input box; search, upload files, upload photos, screenshot, and photo-taking functions are not yet implemented.
  4. Send Request: After confirming the model, parameters, and input content, click the "Send" button to submit the request.
  5. View Response Results: After the model finishes generating, you can view the returned content in the conversation area and continue to input new questions for multi-turn conversations.

Playground Page

API Address and Authentication

The OpenAI-compatible address for the gateway is typically:

https://your-host/v1

Use your API key as a Bearer Token:

Authorization: Bearer sk-your-api-key

For example, with chat completions:

curl https://your-host/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"你好"}]}'

SDK Examples

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxxxxxx",
    base_url="https://your-host/v1",
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)

Claude Native Format

curl https://your-platform.com/v1/messages \
  -H "x-api-key: sk-xxxxxxxx" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-3-5-sonnet-20241022", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'

Gemini Native Format

curl "https://your-platform.com/v1beta/models/gemini-1.5-pro:generateContent?key=sk-xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"parts": [{"text": "Hello"}]}]}'

Supported API Endpoints

InterfacePathDescription
Chat CompletionsPOST /v1/chat/completionsOpenAI Chat Completions compatible interface, requires model and messages, supports streaming or regular responses.
Playground ChatPOST /pg/chat/completionsWeb playground specific interface, uses login session to select group and model, and reuses unified traffic splitting, protocol conversion, billing, and retry mechanisms.
Text CompletionsPOST /v1/completionsTraditional text completions interface, requires prompt and model.
Vector EmbeddingsPOST /v1/embeddingsConverts text or arrays of text into vectors, requires input, converted to upstream format by channel adapter.
Gemini Embeddings Compatible InterfacePOST /v1/engines/{model}/embeddingsCompatible with older Gemini-style embedding paths, processes embedding requests based on the model name in the URL.
Image GenerationPOST /v1/images/generationsGenerates images based on prompts; specific model, size, quality, and quantity depend on request parameters and configured channels.
Image EditingPOST /v1/images/editsEdits images based on input image and prompt, supports JSON and multipart/form-data requests.
Legacy Edit InterfacePOST /v1/editsReserved compatible path, code enters image Relay processing; new clients are advised to prioritize using /v1/images/edits.
Speech to TextPOST /v1/audio/transcriptionsConverts audio to text, forwards to corresponding speech recognition channel according to OpenAI audio interface format.
Audio TranslationPOST /v1/audio/translationsRecognizes audio content and outputs translated text.
Text to SpeechPOST /v1/audio/speechConverts input text to audio.
RerankPOST /v1/rerankReranks candidate documents based on query for relevance, requires non-empty query content and document list.
Content ModerationPOST /v1/moderationsPerforms content moderation on text or other inputs; if no model is provided, a default moderation model candidate will be used.
Responses APIPOST /v1/responsesOpenAI Responses format interface, supports capabilities such as input, tools, and response events.
Responses CompressionPOST /v1/responses/compactPerforms compression processing on Responses request context.
Codex Web SearchPOST /v1/alpha/searchCodex independent web search format interface, currently only allows processing by Sub2API, New API, Codex, and advanced custom channels that support this capability.
Claude MessagesPOST /v1/messagesAnthropic Claude Messages compatible interface, requires model and message content, converted to upstream protocol by New API when necessary.
Realtime ConversationGET /v1/realtime (WebSocket)OpenAI Realtime style bidirectional real-time communication interface, models are usually passed via query parameters, and API keys can be passed via Bearer Token or WebSocket subprotocol.
Gemini Native Model InvocationPOST /v1beta/models/{model}:{action}Gemini native format interface, supports model operation paths, such as generateContent, streamGenerateContent, and embedding-related operations.
Gemini Compatible Model InvocationPOST /v1/models/{model}:{action}Accepts Gemini-style model operation requests with the /v1 prefix, parsed and converted by Gemini Relay.
Model ListGET /v1/modelsReturns OpenAI format model list by default; returns Claude format when using Anthropic request headers, and Gemini format when using x-goog-api-key or key query parameters.
Model DetailsGET /v1/models/{model}Queries single model information; returns model_not_found error object if the model does not exist.
Gemini Model ListGET /v1beta/modelsReturns a list of available models in Gemini format, response fields include models and nextPageToken.
OpenAI Format Model ListGET /v1beta/openai/modelsReturns a model list in OpenAI format under the Gemini compatible namespace.

How is this guide?

Last updated on