NOTE: This is a research project. Please do not use it commercially and use it responsibly.
This project implements a web API that offers a unified interface to Google Gemini, and Claude 3.
-
Self-hosted: Python/FastAPI enables flexibility to run anywhere. Not locked into proprietary platforms.
-
Streaming support: Real-time responses from Claude streaming.
-
Lightweight and scalable: Built with FastAPI for high performance.
-
API Key: No API Key required.
✅ Claude-3 API integration is also fully implemented and available
✅ Google Gemini API integration available now
✅ UI Configuration: Implement routing for localhost:8000/WebAI path
⚙️ PIP: In progress
This repository is up-to-date.
Please don't forget to give a Star ⭐
Python version >= 3.10 Accounts on the following (all offer free signups):
- Google Gemini: https://gemini.google.com/
- Claude: https://claude.ai/
Then, add your token(s) to the Config.conf
file. (see Configuration section).
Note
Note: Claude and Gemini offer Auto Login options - you can either log in through your browser and skip this step.
git clone https://github.com/Amm1rr/WebAI-to-API.git && cd WebAI-to-API
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install -r requirements.txt
Navigate into the webai2api
directory, and run the web server:
cd WebAI-to-API/webai2api/
python run.py
Now the API documentation and Configuration Web UI should be available at the following addresses:
Tip
Open Web UI Configuration: http://localhost:8000/WebAI
Open API documentation: http://localhost:8000/docs
Note
Gemini
Claude
Claude/Gemini
Input / Output
# Input:
_____
{
"message": "Hi, Who are you?",
"stream": true
}
--------------------
# Output:
_____
{
I am a Chatbot assistant :)
}
--------------------
# Response Output:
_____
# Streaming
"String"
# Not Streaming
"String"
- Node.js: Download and install from the official website (https://nodejs.org)
First , Navigate to the UI directory:
cd WebAI-to-API/webai2api/UI
- Install dependencies:
npm install
- Build the project:
npm run build
Once you have launched the web server using python webai2api\run.py
:
Note
Note: The first argument to run the example determines whether to return streaming or not.
cd examples/
python WebAPI-to-API/webai2api/test.py
OR
python example_claude.py false
python example_claude.py true
python example_gemini.py
or try Claude with cURL
run this cURL command in a terminal window:
curl -X 'POST' \
'http://localhost:8000/claude' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"message": "who are you?",
"stream": false
}'
Note
Note: The session_id
is configured in the Config.conf file. If you send this variable empty, it will use the Config.conf
Note
Note: Claude and Gemini offer two authentication options - you can either log in through your browser and skip this step, or you can follow the instructions below to configure the authentication.
Important
"The auto login by browser issue is caused by using multiple accounts or browser profiles. It will take some time to fully resolve. A future update will address it. For now, if you have problems logging in with your browsers, try logging in with just one browser or manually copy sessions and cookies as a workaround, as described in the instructions below."
The easiest way is to just log in to the chatbot websites. (Claude | Gemini)
OR
First you need to add your tokens to the Config.conf
file (see Configuration section).
Method 1:
For Gemini, all you need to do is login to your account using your web browser. (Firefox, Chrome, Safari, Edge...)
Method 2:
Google Gemini:
Please obtain the cookies mentioned here from an authorized session on gemini.google.com. The cookies can be used to send POST requests to the /gemini endpoint along with a message in a JSON payload. It is important that the session_id, which is your __Secure-1PSID cookie, and the session_idts and session_idcc, which is your Secure-1PSIDTS and Secure-1PSIDCC cookie, are included in the request. (Screenshot)
Name | Session Name |
---|---|
session_id |
__Secure-1PSID |
session_idts |
__Secure-1PSIDTS |
session_idcc |
__Secure-1PSIDCC |
- Login to gemini.google.com
- Open
Developer Tools
(Press F12) - Go to
Application Tab
- Go to
Cookies Tab
- Copy the content of
__Secure-1PSID
and__Secure-1PSIDTS
and__Secure-1PSIDCC
. Copy the value of those cookie. - Set in Config.conf file.
Method 1:
For Claude, all you need to do is login to your account using your web browser. (Firefox, Chrome, Safari, Edge...)
Method 2:
Claude:
You can get cookie from the browser's developer tools network tab ( see for any claude.ai requests check out cookie ,copy whole value ) or storage tab ( You can find cookie of claude.ai ,there will be four values ) (Screenshot)
- Login to claude.ai
- Open
Developer Tools
(Press F12) - Go to
Network Tab
- Select an ajax request (like step 3 in picture)
- Copy the content of
Cookie
- Set in Config.conf file.
- Open Web UI Panel: http://localhost:8000/WebAI
How to find tokens
Note
Note: Claude and Gemini present Auto Login options - logging in through your browser or configuring Claude and Gemini using the provided config file.
You can specify the model type in the settings for the /v1/chat/completions
endpoint. The available options are "Claude" and "Gemini".
By default, the system uses the "Claude" model.
# Case-Sensitive
[Main]
Model=Claude
# or
Model=Gemini
- WebAI-to-API\webai2api\Config.conf
# Case-Sensitive
[Main]
Model = [Claude] or [Gemini]
[Claude]
COOKIE=[YOURS]
[Gemini]
SESSION_ID=[YOURS]
SESSION_IDTS=[YOURS]
SESSION_IDCC=[YOURS]
This project is licensed under the MIT License. Feel free to use it however you like.