Proxy Interface
The Proxy Interface is the core of the XAI XAPI service. It receives AI API requests from your application and intelligently forwards them to upstream service providers.
Endpoint
All API requests compatible with OpenAI or Anthropic should be sent to the following base URL:
- OpenAI Compatible:
https://api.xaixapi.com
- Anthropic Compatible:
https://api.xaixapi.com
You just need to append the official API path to these base URLs.
Examples:
- OpenAI's
v1/chat/completions
->https://api.xaixapi.com/v1/chat/completions
- Anthropic's
v1/messages
->https://api.xaixapi.com/v1/messages
Authentication
All proxy requests must include your XAI API Key in the HTTP Header.
Authorization: Bearer sk-Xvs...
Model Mapping
XAI XAPI supports model mapping, which means you can specify a custom model name in your request (e.g., gpt-3.5*=gpt-4o-mini
), and the platform will automatically map models starting with gpt-3.5
to gpt-4o-mini
.
This mapping can be configured at two levels:
- System-level (
/x-conf
): Configured by theroot
administrator and applies to all users. - User-level (
/x-users
): Parent users can configure independent mapping rules for their child users.
For any given request, user-level model mapping takes precedence. The system-level mapping is only used if a user-level mapping for the requested model does not exist. If neither is found, the original model name is used without change.
Intelligent Routing and Failover
This is where the core value of the XAI XAPI lies. When you make a request:
- Based on the requested model, the system uses the
LevelMapper
to determine whichLevel
's key pool to use. - It selects an upstream key from the corresponding
Level
's key pool using a round-robin algorithm. - If the request fails (e.g., due to a
429
rate limit error or a5xx
server error), the system will:- Automatically put the problematic key into a "sleep" state for a period of time.
- Select the next key from the current
Level
's pool and retry. - If all keys in the current
Level
fail, the system will intelligently "failover" to anotherLevel
's key pool to continue retrying, based on yourGear
andAllowLevels
settings.
- This entire process is completely transparent to the caller. You will only receive the final successful result, or a final error message if all attempts fail.