Deploy Gemini-OpenAI-Proxy
Converting the OpenAI API protocol to the Google Gemini Pro protocol.
gemini-openai-proxy
Just deployed
Deploy and Host Gemini-OpenAI-Proxy on Railway
Gemini-OpenAI-Proxy is an open-source gateway that translates the OpenAI API protocol into the Google Gemini API protocol. It enables OpenAI-compatible applications to communicate directly with Gemini models while supporting Chat Completions, Embeddings, Vision requests, and Model endpoints without requiring application code changes.
About Hosting Gemini-OpenAI-Proxy
Railway provides a fast and reliable platform for deploying Gemini-OpenAI-Proxy using the official Docker image. The proxy runs as a lightweight stateless HTTP service that accepts OpenAI-compatible requests and forwards them to Google Gemini using your Google AI Studio API key. Railway automatically manages HTTPS, networking, deployments, and scaling, allowing developers to expose an OpenAI-compatible endpoint with minimal configuration. Since the application does not persist state, no database or Railway Volume is required.
Common Use Cases
- Connect OpenAI-compatible applications to Google Gemini without modifying client code.
- Replace OpenAI backends with Gemini while continuing to use existing SDKs.
- Proxy Chat, Embeddings, Vision, and Model API requests through a unified OpenAI-compatible endpoint.
Dependencies for Gemini-OpenAI-Proxy Hosting
| Dependency | Required | Purpose |
|---|---|---|
| Google AI Studio API Key | Yes | Authenticates requests to Gemini models. |
Deployment Dependencies
| Resource | Link |
|---|---|
| GitHub Repository | https://github.com/zhu327/gemini-openai-proxy |
| Docker Image | https://hub.docker.com/r/zhu327/gemini-openai-proxy |
| Google AI Studio | https://ai.google.dev |
| Google OpenAI Compatibility Documentation | https://ai.google.dev/gemini-api/docs/openai |
| OpenAI API Reference | https://platform.openai.com/docs/api-reference |
Implementation Details
Docker
This template deploys the official Docker image:
zhu327/gemini-openai-proxy:latest
Railway pulls the prebuilt image directly.
Public Networking
| Setting | Value |
|---|---|
| Proxy Type | HTTP Proxy |
| Target Port | 8080 |
After deployment:
- Open your Railway service.
- Navigate to Settings → Networking.
- Click Generate Domain.
Your proxy endpoint will be available at:
https:///v1
Environment Variables
Configure the following Railway Variables before deployment.
| Variable | Required | Description |
|---|---|---|
PORT | No | Internal application port. Defaults to 8080. |
GPT_4_VISION_PREVIEW | No | Gemini model used when clients request gpt-4-vision-preview. |
DISABLE_MODEL_MAPPING | No | Set to 1 to disable automatic OpenAI → Gemini model mapping. |
Raw Editor example:
PORT=8080
GPT_4_VISION_PREVIEW=gemini-1.5-flash-latest
DISABLE_MODEL_MAPPING=0
Getting a Google AI Studio API Key
Before using the proxy:
-
Visit:
-
Sign in with your Google account.
-
Open Google AI Studio.
-
Create a new API Key.
-
Copy the generated key.
When making requests to Gemini-OpenAI-Proxy, use the Google AI Studio API Key as the Bearer token:
Authorization: Bearer YOUR_GOOGLE_AI_STUDIO_API_KEY
Persistent Storage
No Railway Volume is required.
Gemini-OpenAI-Proxy is completely stateless and processes requests entirely in memory.
Database
No database is required.
Build & Start
Railway deploys the official Docker image automatically.
No custom build or start commands are required.
Accessing the Application
After deployment:
- Generate a Railway Domain.
- Configure your OpenAI-compatible application to use:
https:///v1
- Use your Google AI Studio API Key as the Bearer token.
Your existing OpenAI SDKs and clients can now communicate with Gemini through the proxy.
Chat Completion Example
curl https:///v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_GOOGLE_AI_STUDIO_API_KEY" \
-d '{
"model":"gpt-3.5-turbo",
"messages":[
{
"role":"user",
"content":"Say this is a test!"
}
],
"temperature":0.7
}'
Vision Example
Gemini-OpenAI-Proxy supports OpenAI Vision requests.
curl https:///v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_GOOGLE_AI_STUDIO_API_KEY" \
-d '{
"model":"gpt-4-vision-preview",
"messages":[
{
"role":"user",
"content":[
{
"type":"text",
"text":"What is in this image?"
},
{
"type":"image_url",
"image_url":{
"url":"https://example.com/image.jpg"
}
}
]
}
]
}'
To use Gemini Pro Vision instead of the default model, configure:
GPT_4_VISION_PREVIEW=gemini-1.5-pro-latest
Embeddings Example
curl https:///v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_GOOGLE_AI_STUDIO_API_KEY" \
-d '{
"model":"text-embedding-ada-002",
"input":"This is a test sentence."
}'
Multiple inputs are also supported:
{
"model": "text-embedding-ada-002",
"input": [
"Sentence one",
"Sentence two"
]
}
Model Mapping
By default, Gemini-OpenAI-Proxy automatically maps common OpenAI models to Gemini equivalents.
| OpenAI Model | Gemini Model |
|---|---|
gpt-4 | gemini-1.5-flash-002 |
gpt-4-turbo-preview | gemini-1.5-pro-latest |
gpt-4o | gemini-2.0-flash-exp |
gpt-4-vision-preview | gemini-1.5-flash-latest |
text-embedding-ada-002 | text-embedding-004 |
Disable Model Mapping
To send Gemini model names directly, configure:
DISABLE_MODEL_MAPPING=1
Example request:
{
"model": "gemini-1.0-pro-latest",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}
Supported Features
- OpenAI Chat Completions API
- OpenAI Embeddings API
- OpenAI Models API
- Image / Vision requests
- Automatic OpenAI → Gemini model mapping
- Optional direct Gemini model support
- Stateless architecture
- OpenAI SDK compatibility
Compatibility Notice
Google AI Studio now provides an official OpenAI-compatible API endpoint.
For new projects, you may also consider Google's official compatibility layer:
Gemini-OpenAI-Proxy remains useful for deployments that require its proxy-based architecture or custom model mapping behavior.
Why Deploy Gemini-OpenAI-Proxy on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Gemini-OpenAI-Proxy on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
gemini-openai-proxy
zhu327/gemini-openai-proxy:latest