Migrate from the Google Gemini API to TokenRex
Move Gemini calls to the OpenAI-compatible format on TokenRex.
Steps
- Create a TokenRex API key.
- Install the OpenAI SDK.
- Rewrite generateContent calls as chat completions with a Gemini model ID.
- Note: the Google-native request format is not supported.
What to check after switching
- Run your existing test prompts and compare replies.
- Check the usage field in responses to confirm token counts and costs.
- Short model IDs are used on TokenRex, for example gpt-6-sol rather than openai/gpt-6-sol.
Example
from openai import OpenAI
client = OpenAI(api_key="YOUR_TOKENREX_KEY", base_url="https://tokenrex.ai/api/public")
resp = client.chat.completions.create(
model="gemini-3.8-flash",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)Questions
- Can I switch back?
- Yes. Nothing is locked in: change the base URL and key back and your code keeps working.
Related
- How to use the OpenAI SDK with a custom base URL
- What is a model ID?
- Migrate from the OpenAI API to TokenRex
- Migrate from OpenRouter to TokenRex
- Migrate from the Anthropic API to TokenRex
- Migrate from LangChain's ChatOpenAI default endpoint to TokenRex
- Migrate from the Vercel AI SDK OpenAI provider to TokenRex
- Migrate from several separate provider accounts to TokenRex
- Migrate from USD card billing to TokenRex