Download README.md from yanng404/laya-api: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/spaces/yanng404/laya-api/resolve/main/README.md
- Command line
-
hf download hf://spaces/yanng404/laya-api/README.md
-
curl -L -o README.md https://huggingface.co/spaces/yanng404/laya-api/resolve/main/README.md
title: Laya API backend
emoji: 🧭
colorFrom: red
colorTo: gray
sdk: docker
app_port: 7860
pinned: false
license: apache-2.0
Laya API backend (for api.laya-ai.com)
Runs the upstream laya-serve HTTP server
(Jev-compatible POST /v1/systemone and /v1/systemone/batch) with all three
checkpoints preloaded. Only the hosted API gateway (platform/api-platform) calls
it; the laya-ai.com playground keeps using the upstream demo Space.
One-time setup
- Create a new Space: Docker SDK, CPU Upgrade hardware (8 vCPU, 32 GB, about $22/month). Visibility can stay public: every request needs the key below.
- Upload
Dockerfileand thisREADME.mdto the Space repository. - In Settings → Variables and secrets, add a secret
LAYA_API_KEYwith a long random value (openssl rand -base64 32).laya-servethen requiresAuthorization: Bearer <key>on every request. - Wait for the build. The first one downloads PyTorch and about 2.3 GB of weights; startup then preloads the checkpoints (about 10 seconds).
Check it
SPACE=https://<user>-<space-name>.hf.space
curl -s $SPACE/health
curl -s $SPACE/v1/systemone \
-H "authorization: Bearer $LAYA_API_KEY" -H 'content-type: application/json' \
-d '{"state":"I was charged twice","questions":{"refund":{"type":"noul","instructions":"Refund requested?"}}}'
The response must contain usage.input_tokens: the gateway bills on it.
Measure it
cd platform/api-platform
UPSTREAM_URL=$SPACE UPSTREAM_TOKEN=$LAYA_API_KEY node scripts/bench-upstream.mjs
Run it with LAYA_THREADS at 4 and at 8 (Space variable, then restart) and keep
the faster one. Then set the gateway's upstream limit (limits.rate.upstream in
src/server/config/apps/laya.ts and UPSTREAM_LIMITER in wrangler.jsonc) to
about 80% of the measured requests per second × 60.
Point the API gateway at it
cd platform/api-platform
# wrangler.jsonc: "UPSTREAM_LAYA_CPU_URL": "https://<user>-<space-name>.hf.space"
pnpm exec wrangler secret put UPSTREAM_LAYA_CPU_TOKEN # same value as LAYA_API_KEY
Move to a GPU
When traffic outgrows the CPU (sustained over ~1 question per second, p95 above
3 seconds, or usage revenue above ~$300/month): switch the Space hardware to
T4 small, remove --index-url ...cpu from the Dockerfile so the CUDA build of
PyTorch is installed, and set the Space variable LAYA_DEVICE=cuda. The URL stays
the same, so the gateway needs no change except a higher upstream limit.
Paid Spaces do not sleep. Do not set LAYA_JEV_STRICT: the gateway reads Laya's
own response shape.