curl -X POST https://api.fish.audio/v1/auth/tokens \
-H "Authorization: Bearer $FISH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"scopes": ["stt:write"],
"ttl_seconds": 120,
"max_session_duration_seconds": 1800,
"allowed_origins": ["https://app.example.com"],
"end_user_id": "user_42"
}'
import os
import requests
response = requests.post(
"https://api.fish.audio/v1/auth/tokens",
headers={
"Authorization": f"Bearer {os.environ['FISH_API_KEY']}",
"Content-Type": "application/json",
},
json={
"scopes": ["stt:write"],
"ttl_seconds": 120,
"max_session_duration_seconds": 1800,
"allowed_origins": ["https://app.example.com"],
"end_user_id": "user_42",
},
timeout=10,
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.fish.audio/v1/auth/tokens", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FISH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
scopes: ["stt:write"],
ttl_seconds: 120,
max_session_duration_seconds: 1800,
allowed_origins: ["https://app.example.com"],
end_user_id: "user_42",
}),
});
const data = await response.json();
console.log(data);
{
"token": "ek-fish-exampleTokenValueReturnedOnce",
"token_id": "etk_4c9f8b2e7a1d4f0a9b3c6d5e8f1a2b3c",
"expires_at": "2026-12-04T04:02:00Z",
"expires_in": 120,
"scopes": ["stt:write"],
"single_use": true,
"max_session_duration_seconds": 1800
}
{
"code": "api_key_spend_limit_exceeded",
"message": "API key spend limit exceeded for the current reset window.",
"limit_usd": "25.00",
"spent_usd": "25.04",
"resets_at": "2026-12-05T00:00:00+00:00"
}
{
"code": "classic_key_cannot_mint",
"message": "Classic API keys cannot mint ephemeral tokens. Create a scoped API key with the 'tokens:mint' scope instead."
}
{
"code": "api_key_scope_forbidden",
"required_scope": "stt:write",
"required_scopes": ["stt:write"],
"missing_scopes": ["stt:write"],
"message": "This API key is missing required scope: stt:write."
}
API Keys
Mint One-Time Ephemeral Token
Mint a short-lived single-use ek-fish- token from your backend for direct client connections
POST
/
v1
/
auth
/
tokens
curl -X POST https://api.fish.audio/v1/auth/tokens \
-H "Authorization: Bearer $FISH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"scopes": ["stt:write"],
"ttl_seconds": 120,
"max_session_duration_seconds": 1800,
"allowed_origins": ["https://app.example.com"],
"end_user_id": "user_42"
}'
import os
import requests
response = requests.post(
"https://api.fish.audio/v1/auth/tokens",
headers={
"Authorization": f"Bearer {os.environ['FISH_API_KEY']}",
"Content-Type": "application/json",
},
json={
"scopes": ["stt:write"],
"ttl_seconds": 120,
"max_session_duration_seconds": 1800,
"allowed_origins": ["https://app.example.com"],
"end_user_id": "user_42",
},
timeout=10,
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.fish.audio/v1/auth/tokens", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FISH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
scopes: ["stt:write"],
ttl_seconds: 120,
max_session_duration_seconds: 1800,
allowed_origins: ["https://app.example.com"],
end_user_id: "user_42",
}),
});
const data = await response.json();
console.log(data);
{
"token": "ek-fish-exampleTokenValueReturnedOnce",
"token_id": "etk_4c9f8b2e7a1d4f0a9b3c6d5e8f1a2b3c",
"expires_at": "2026-12-04T04:02:00Z",
"expires_in": 120,
"scopes": ["stt:write"],
"single_use": true,
"max_session_duration_seconds": 1800
}
{
"code": "api_key_spend_limit_exceeded",
"message": "API key spend limit exceeded for the current reset window.",
"limit_usd": "25.00",
"spent_usd": "25.04",
"resets_at": "2026-12-05T00:00:00+00:00"
}
{
"code": "classic_key_cannot_mint",
"message": "Classic API keys cannot mint ephemeral tokens. Create a scoped API key with the 'tokens:mint' scope instead."
}
{
"code": "api_key_scope_forbidden",
"required_scope": "stt:write",
"required_scopes": ["stt:write"],
"missing_scopes": ["stt:write"],
"message": "This API key is missing required scope: stt:write."
}
Mint a short-lived, one-time (single-use)
ek-fish- ephemeral token from your backend so an untrusted client (browser, mobile app, or desktop app) can connect directly to Fish Audio inference endpoints without exposing your sk-fish- API key.
For end-to-end browser WebSocket and fetch examples, see One-Time Ephemeral Tokens.
Authentication
Send a Scoped API key inAuthorization: Bearer <sk-fish-...> that carries:
tokens:mint, and- Every scope listed in the requestโs
scopesarray.
- Classic API keys are rejected with
403(code: "classic_key_cannot_mint"). - One-time
ek-fish-tokens cannot mint new tokens (403,code: "ephemeral_token_cannot_mint"). - Responses include
Cache-Control: no-storeandPragma: no-cache.
Constraints and rate limit
- Rate limit: Each team can mint up to 600 ephemeral tokens per minute. Exceeding this limit returns
429(code: "rate_limit_exceeded") withRetry-After: 60. - Single-use only:
single_usedefaults totrue; passingfalsereturns400(multi_use_not_supported). - Allowed scopes:
tts:write,stt:write,voice_design:write,realtime:write, andagents:session(reserved for gateway-routed agent sessions; RESTPOST /v1/agent/sessionsuses ask-fish-key). allowed_origins: Up to 20 exacthttp://host[:port]orhttps://host[:port]origins (no wildcards, credentials, paths, queries, fragments, or custom app schemes such ascapacitor://ortauri://; max 256 characters each). Omit for native mobile or desktop clients that do not send anOriginheader.max_session_duration_seconds:60โ14400(default3600). Cannot extend an endpointโs own maximum session cap (for example, 3,600 seconds on/v1/asr/realtime); whichever limit is lower fires first.
Errors
| Status | code | Cause |
|---|---|---|
400 | multi_use_not_supported | single_use was set to false. |
400 | invalid_ephemeral_scope | scopes contains a whitespace-only value or a scope outside the 5 allowed ephemeral scopes. |
400 | invalid_allowed_origin | An allowed_origins entry is not an exact http:// or https:// origin or contains wildcards, credentials, paths, queries, or fragments. |
401 | โ | Missing, invalid, expired, or revoked sk-fish- API key. |
402 | api_key_spend_limit_exceeded | Parent API key reached its USD spend limit (limit_usd, spent_usd, resets_at included). |
402 | insufficient_credit | Team has no available API credit, has a payment hold, or billing scope is closed. |
403 | classic_key_cannot_mint | Caller authenticated with a Classic API key instead of a Scoped key. |
403 | ephemeral_token_cannot_mint | Caller authenticated with an ek-fish- ephemeral token. |
403 | api_key_scope_forbidden | Calling scoped key lacks tokens:mint or one or more requested scopes (required_scope, required_scopes, and missing_scopes when applicable). |
422 | โ | Request body schema validation failed (for example, empty string in scopes, ttl_seconds out of range, >20 allowed_origins entries, origin >256 chars, or unknown field). |
429 | rate_limit_exceeded | Team exceeded 600 mint requests per minute; retry after Retry-After seconds. |
curl -X POST https://api.fish.audio/v1/auth/tokens \
-H "Authorization: Bearer $FISH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"scopes": ["stt:write"],
"ttl_seconds": 120,
"max_session_duration_seconds": 1800,
"allowed_origins": ["https://app.example.com"],
"end_user_id": "user_42"
}'
import os
import requests
response = requests.post(
"https://api.fish.audio/v1/auth/tokens",
headers={
"Authorization": f"Bearer {os.environ['FISH_API_KEY']}",
"Content-Type": "application/json",
},
json={
"scopes": ["stt:write"],
"ttl_seconds": 120,
"max_session_duration_seconds": 1800,
"allowed_origins": ["https://app.example.com"],
"end_user_id": "user_42",
},
timeout=10,
)
response.raise_for_status()
print(response.json())
const response = await fetch("https://api.fish.audio/v1/auth/tokens", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FISH_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
scopes: ["stt:write"],
ttl_seconds: 120,
max_session_duration_seconds: 1800,
allowed_origins: ["https://app.example.com"],
end_user_id: "user_42",
}),
});
const data = await response.json();
console.log(data);
{
"token": "ek-fish-exampleTokenValueReturnedOnce",
"token_id": "etk_4c9f8b2e7a1d4f0a9b3c6d5e8f1a2b3c",
"expires_at": "2026-12-04T04:02:00Z",
"expires_in": 120,
"scopes": ["stt:write"],
"single_use": true,
"max_session_duration_seconds": 1800
}
{
"code": "api_key_spend_limit_exceeded",
"message": "API key spend limit exceeded for the current reset window.",
"limit_usd": "25.00",
"spent_usd": "25.04",
"resets_at": "2026-12-05T00:00:00+00:00"
}
{
"code": "classic_key_cannot_mint",
"message": "Classic API keys cannot mint ephemeral tokens. Create a scoped API key with the 'tokens:mint' scope instead."
}
{
"code": "api_key_scope_forbidden",
"required_scope": "stt:write",
"required_scopes": ["stt:write"],
"missing_scopes": ["stt:write"],
"message": "This API key is missing required scope: stt:write."
}
Authorizations
Body
application/json
Requested ephemeral inference/session scopes. Must be a non-empty subset of both the parent API key's scopes and allowed ephemeral scopes (tts:write, stt:write, voice_design:write, realtime:write, agents:session).
Required array length:
1 - 16 elementsRequired string length:
1 - 64Response
Document created, URL follows
Was this page helpful?

