From Google Gemini to FlowModels.
FlowModels speaks the OpenAI format, so you call Gemini models with the OpenAI SDK: you rewrite the messages, the configuration and the tools.
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 |
|---|---|---|
| SDK | google-genai |
openai |
| Base URL | https://generativelanguage.googleapis.com |
https://api.flowmodels.one/v1 |
| Key | GEMINI_API_KEY |
FLOWMODELS_API_KEY |
| Model name | gemini-3.7-flash |
gemini/gemini-3.7-flash |
The code before and after
- from google import genai
- from google.genai import types
-
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
+ from openai import OpenAI
+
+ client = OpenAI(
+ base_url="https://api.flowmodels.one/v1",
+ api_key=os.environ["FLOWMODELS_API_KEY"],
+ )
- response = client.models.generate_content(
- model="gemini-3.7-flash",
- contents="Hello!",
- config=types.GenerateContentConfig(
- system_instruction="Keep your answers short.",
- temperature=0.2,
- ),
- )
- print(response.text)
+ response = client.chat.completions.create(
+ model="gemini/gemini-3.7-flash",
+ temperature=0.2,
+ messages=[
+ {"role": "system", "content": "Keep your answers short."},
+ {"role": "user", "content": "Hello!"},
+ ],
+ )
+ print(response.choices[0].message.content)
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 |
|---|---|
system_instruction |
Becomes a message with role: "system". |
contents, parts |
Become messages with role and content. Images are blocks of type image_url, only in messages with role: "user". |
max_output_tokens, stop_sequences |
Are called max_tokens and stop here. |
response_mime_type, response_schema |
Through response_format with json_schema. FlowModels filters your schema down to the keys Gemini accepts. |
function_declarations |
Are called tools[].function here. The model reports tool_calls; FlowModels does not run your functions. |
search_domain_filter |
Models without a domain filter, such as Gemini, reject the field with 400 unsupported_for_model. |
Streaming |
With stream: true, the text arrives in choices[0].delta.content instead of through generate_content_stream. |
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.
-
Your code reads the response from
choices[0].message.contentinstead ofresponse.text.