Documentation
Start sending requests
DigitSpace speaks the OpenAI API. If your code already calls OpenAI, you only change the base URL and the key.
Quickstart
- Create an account and open your project.
- Create an API key under API Keys.
- Send a request to
https://api.digitspace.cn/v1:
curl https://api.digitspace.cn/v1/chat/completions \
-H "Authorization: Bearer $DIGITSPACE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"messages": [{ "role": "user", "content": "Say hello in three languages." }]
}'Authentication
Every request needs your key in the Authorization header as a bearer token. Keep keys on your server; never ship them in a browser or mobile app. You can revoke a key at any time from the dashboard, and requests made with it stop immediately.
Using an SDK
Any OpenAI-compatible client works. Point it at DigitSpace:
JavaScript / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DIGITSPACE_API_KEY,
baseURL: "https://api.digitspace.cn/v1",
});
const reply = await client.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "Write a haiku about routing." }],
});
console.log(reply.choices[0].message.content);Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["DIGITSPACE_API_KEY"],
base_url="https://api.digitspace.cn/v1",
)
reply = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Write a haiku about routing."}],
)
print(reply.choices[0].message.content)Choosing a model
Pass any model ID from the models page to use that model, for example gpt-4o. DigitSpace sends it to a healthy provider that serves it and falls back to another one if the first fails.
Pass auto to let DigitSpace choose: it looks at what the request needs (context length, tools, images, reasoning) and picks the lowest-priced model that can handle it. You can list every available model with GET https://api.digitspace.cn/v1/models.
Streaming
Set stream: true to receive the reply as server-sent events while it is generated, exactly as with OpenAI. SDKs handle this for you:
const stream = await client.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "Count to five." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Billing modes
- Credits: top up your balance and pay provider rates per request, plus a flat fee on each top-up.
- Your own keys: add your provider keys in the dashboard and pay providers directly. Routing and usage tracking are free.
Every request appears under Activity with its model, provider, tokens, latency and cost. See pricing.
Errors
Errors use the OpenAI error format, with a message that explains what went wrong. The most common status codes:
| 400 | The request is invalid, or the model cannot do what was asked. |
| 401 | The API key is missing, wrong or revoked. |
| 402 | Your credit balance is too low. Top up or use your own keys. |
| 403 | Your account or project is not allowed to make this request. |
| 429 | You hit a rate limit. Wait and retry. |
| 5xx | No provider could serve the request. Retry shortly. |
Getting help
Questions or problems? Contact us or email support@digitspace.cn.