From xAI to FlowModels.
The xAI API follows the OpenAI format. You swap the base URL and the key and put xai/ in front of the model.
What changes
The base URL, the key and the model name. Everything else stays, as long as you do not use any of the fields in the table below.
| Setting | Before | On FlowModels |
|---|---|---|
| Base URL | https://api.x.ai/v1 |
https://api.flowmodels.one/v1 |
| Key | XAI_API_KEY |
FLOWMODELS_API_KEY |
| Model name | grok-4.7 |
xai/grok-4.7 |
The code before and after
client = OpenAI(
- base_url="https://api.x.ai/v1",
- api_key=os.environ["XAI_API_KEY"],
+ base_url="https://api.flowmodels.one/v1",
+ api_key=os.environ["FLOWMODELS_API_KEY"],
)
response = client.chat.completions.create(
- model="grok-4.7",
+ model="xai/grok-4.7",
messages=[{"role": "user", "content": "Hello!"}],
)
Fields that behave differently
What the chosen model supports decides. The fields it accepts are listed under supported_parameters in GET /v1/models.
| Field | Behavior on FlowModels |
|---|---|
web_search |
On models that support it, you turn on web search with web_search: true. On xAI, search_domain_filter takes up to five domains. |
reasoning_effort |
Only on models with reasoning. The levels are listed under capabilities.reasoning_levels; any other level results in 400 unsupported_for_model. |
response_format |
json_object and json_schema, depending on what the model supports. Otherwise you get 400 unsupported_for_model. |
tools, tool_choice |
Type function only. FlowModels does not run your functions; the model reports tool_calls. |
What to check after the move
-
The new key is in
FLOWMODELS_API_KEY, andGET /v1/modelslists your model. -
A call without streaming returns
choices[0].message.contentas expected. -
With
stream: truethe events arrive; withstream_options.include_usagethe usage is in the last event. -
Tool calls and
response_formatwork with exactly the model you use. -
Your error handling separates
429 insufficient_quota(credit exhausted) from429 rate_limit_exceeded,429 concurrent_requests_exceededand503 provider_overloaded. - The request log in your dashboard shows the model, tokens and cost of the call.
- Plan for extra cost with web search: every search is billed additionally.