4Z API

API Quick Start Guide

Account signup

Signup benefits

  • New users get $0.2 trial credit
  • Minimum top-up: $1
  • Register: Sign up

Setup

1. Get a token

  1. Sign in to the console
  2. Open the Tokens page
  3. Click Add token to get an API Key

Tip: When creating a token you can also set smart routing so the platform picks the best channel automatically. See Smart routing below.

2. API configuration

Optional BASE_URL values

https://4zapi.com
https://4zapi.com/v1
https://4zapi.com/v1/chat/completions

Note: Different clients may need different BASE_URL values; try the list above in order.

3. Pick a model

  • Model names are in the first column of Supported models on the home page

Example config

{
  "base_url": "https://4zapi.com",
  "api_key": "your_token_here",
  "model": "selected_model_name"
}

Smart routing

Smart routing lets you control channel selection without changing code, optimizing for lowest price, fastest speed, highest success rate, or global best.

Modes

Mode Description
System default Unset; follow the platform global policy
Smart auto (auto) Across all accessible channels, pick the best by speed / success / price
Price first (price) Lowest unit price among available channels
Speed first (speed) Fastest response among available channels
Success-rate first (success_rate) Highest recent success rate

Three ways to set it

Priority from high to low:

model suffix  >  request body provider.sort  >  token routing mode

Option 1: Model name suffix (simplest, per request)

Append a colon suffix to the model name. No other config changes required.

{
  "model": "gpt-6-luna:price",
  "messages": [...]
}

Supported suffixes:

Suffix Effect OpenRouter-style alias
:price Lowest price :floor
:speed Fastest :nitro
:success_rate Highest success rate :stable

Suffixes only affect routing and are not sent upstream. Unknown suffixes (e.g. :beta, :v2) stay in the model name.


Option 2: Request body provider.sort (per request)

Add a provider field. Applies to that request only; does not change the token defaults.

{
  "model": "gpt-6-luna",
  "messages": [{"role": "user", "content": "Hello"}],
  "provider": {
    "sort": "speed"
  }
}

provider.sort values: price / speed / success_rate / floor / nitro / stable

Note: provider.sort does not support "auto". "auto" or unknown values are ignored and fall back to the token routing mode.


Option 3: Token routing mode (recommended, persistent)

When creating or editing a token, choose a routing mode. It applies to all requests with that token.

Path: Token management → New/Edit token → Routing priority mode

Option When to use
System default (unset) No special need; follow platform policy
Smart auto (auto) Let the platform find the global best channel
Price first (price) Cost-sensitive jobs
Speed first (speed) Realtime / low latency
Success-rate first (success_rate) Critical jobs

About smart auto (auto):

  • Expands candidates to all groups your account can access, not only the token's original group
  • Scores speed, success rate, and price in realtime
  • Billing multiplier follows the group of the channel actually routed to

Routing preview (simulate before switching)

Before changing modes, preview which channel and rate a mode would pick:

GET https://4zapi.com/api/user/routing-preview?model=gpt-6-luna&priority=price&prompt_tokens=500
Param Description
model Required model name
priority Optional: auto / price / speed / success_rate
prompt_tokens Optional input tokens for cost estimate

Example response:

{
  "priority_applied": "price",
  "estimated_group": "standard",
  "estimated_price_per_1k": 0.002,
  "price_multiplier": 0.4,
  "warning": false,
  "channel_available": true,
  "prompt_tokens": 500,
  "estimated_cost": 1.0
}
Field Description
estimated_group Predicted channel group
estimated_price_per_1k Estimated USD per 1K tokens
price_multiplier Price ratio vs system default auto (< 1 means cheaper)
warning true if this mode is >1.5× auto; review carefully
estimated_cost Estimated cost for the given prompt tokens

FAQ

Q: If both model suffix and provider.sort are set, which wins?

The model suffix wins. With :price, provider.sort is ignored.

Q: Can I override a token's routing mode per call?

Yes. Use provider.sort or a model suffix. Overrides apply only to that request.

Q: How does auto differ from leaving routing unset?

Both use a scored algorithm, but auto expands candidates to all accessible groups; unset stays within the token's configured groups.

Q: If auto routes to another group, does billing change?

Yes. Billing follows the routed channel's group. Use routing preview to confirm group and rate first.


Verify

  1. Test in the chat page
  2. Call the API with Postman, curl, etc.
  3. Use routing preview to confirm smart routing

Tip: Validate in chat first, then integrate in code