Integration guide
Point base_url at Y-API and leave the rest of your code unchanged. The examples below run as copied, and all 15 models share the same pattern.
Step 1
Basic configuration
Replace these three items in any OpenAI-compatible SDK. Get the api_key from the "API Keys" page in the console; set model to any ID from "Available models".
- base_url
- https://api.y-api.bestvirtualgoods.com/v1
- api_key
- sk-... (create in the console)
- model
- deepseek/deepseek-v4-flash
Writing an agent, or generating a client? The machine-readable OpenAPI 3.1 spec covers the three endpoints that exist here, every request and response field, and which failures the SDKs retry on their own.
The catalog is published as JSON too, and reading it needs no key: every model ID, its vendor, and both the credit price and the cash price. The gateway's own GET /v1/models endpoint does require one — this file is the anonymous equivalent, current as of the last build.
Step 2
Make your first request
All three snippets are equivalent — copy whichever you already use.
curl https://api.y-api.bestvirtualgoods.com/v1/chat/completions \
-H "Authorization: Bearer $YAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4-flash",
"messages": [{"role": "user", "content": "Hello!"}]
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.y-api.bestvirtualgoods.com/v1",
api_key=os.environ["YAPI_KEY"], # key created in the console
)
response = client.chat.completions.create(
model="deepseek/deepseek-v4-flash",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://api.y-api.bestvirtualgoods.com/v1',
apiKey: process.env.YAPI_KEY, // key created in the console
})
const response = await client.chat.completions.create({
model: 'deepseek/deepseek-v4-flash',
messages: [{ role: 'user', content: 'Hello!' }],
})
console.log(response.choices[0].message.content)Advanced
Streaming
Add the stream parameter — chunks come back in the same SSE format as OpenAI, so clients need no special handling.
stream = client.chat.completions.create(
model="deepseek/deepseek-v4-flash",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")Advanced
Switching models
All models share the same base_url and the same key — switching only means changing the model field. The full catalog is on the models page.
# cheap, good for high-frequency and batch tasks
client.chat.completions.create(model="deepseek/deepseek-v4-flash", messages=msgs)
# stronger, good for complex reasoning
client.chat.completions.create(model="deepseek/deepseek-v4-flash", messages=msgs)Troubleshooting
Error handling
Two errors are the most common, and both leave a record in the console request log.
| Status | Meaning | What to do |
|---|---|---|
| 401 | MeaningThe key is invalid or has been revoked. | What to doCheck the key still exists on the "API Keys" page in the console, or create a new one. |
| 403 | MeaningAccount credit is exhausted. Not 429 — and the message comes back in Chinese, which is why searching for it in English finds nothing. | What to doTop up at https://y-api.bestvirtualgoods.com/app/billing — it recovers immediately, keys stay valid, no code changes needed. |
Do not read the cause off the status code: 5 of the 8 codes this gateway returns mean something other than what the number says, and the official SDKs silently retry 2 of those twice before your program ever sees them. The error reference lists every one of them with the message it actually returns.
All error codes, measured one by one →No key yet?
Sign in with Google or GitHub — your account opens automatically with a default key.