Gemini AI Connector for | Google Gemini API Integration
by Steven Marp https://apps.odoo.com/apps/browse?order=Newest&repo_maintainer_id=512936$ 39.99
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 381 |
| Technical Name |
sm_gemini_connector |
| License | OPL-1 |
| Website | https://apps.odoo.com/apps/browse?order=Newest&repo_maintainer_id=512936 |
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 381 |
| Technical Name |
sm_gemini_connector |
| License | OPL-1 |
| Website | https://apps.odoo.com/apps/browse?order=Newest&repo_maintainer_id=512936 |
Connect Odoo to Google Gemini Once
Configure Gemini from Odoo Settings and let other AI modules reuse the same connection. This connector is built as the shared base for AI Sales, AI CRM, AI Helpdesk, AI Inventory, and custom Gemini-powered Odoo apps.
Real Odoo and Google AI Studio Setup
Configure the connector in Odoo, test Gemini from Settings, and monitor Gemini quota from Google AI Studio.
Key Features
1 Secure Gemini ConfigurationStore the Gemini API key in Odoo system parameters, configure the API endpoint, choose the request timeout, and keep Gemini access centralized for every dependent AI module. |
Configure Gemini once from Odoo Settings |
|
Switch Gemini models without code changes |
2 Model Selector and Custom Model IDSelect popular Gemini models such as Gemini 2.5 Flash Lite, Gemini 2.5 Flash, or Gemini 2.5 Pro. Use Custom Model ID when Google AI Studio exposes a new model. |
3 Reusable Python ServiceBuild AI features faster with a reusable Odoo service: call Gemini, track usage, parse JSON responses, and handle API errors without duplicating provider code in every module. |
One service method for dependent apps |
|
Monitor token usage and control limits |
4 Token Tracking and Quota GuardTrack total token usage from Gemini responses and set a monthly token limit to prevent uncontrolled usage during demos, testing, or production. |
5 Connection Test from SettingsValidate the API key, selected model, endpoint, request timeout, and Gemini quota directly from Odoo Settings before dependent modules use the connector. |
Confirm Gemini works before building features |
How It Works
|
1
Configure GeminiEnter the Gemini API key, choose a model, and save settings. |
2
Test ConnectionConfirm API key, model, endpoint, and quota from Odoo Settings. |
3
Build AI AppsUse the connector service from any Odoo module that needs Gemini. |
Highlighted Features
Google Gemini connector · Google AI Studio API key · Gemini model selector · Custom model ID · Token tracking · Monthly limit guard · Connection testing · JSON parser helper · Reusable Odoo service · Odoo 18 AI foundation module
Gemini AI Connector for Odoo - Odoo 18 User and Technical Guide
Table of Contents
1. Overview
The Gemini AI Connector for Odoo module connects Odoo with Google Gemini through one reusable connector service.
It helps implementers and developers:
- Store the Gemini API key once in Odoo.
- Select a Gemini model from Odoo Settings.
- Use a custom Gemini model ID when Google releases new models.
- Configure the Google Generative Language API endpoint.
- Test Gemini connectivity from Odoo Settings.
- Track token usage returned by Gemini.
- Enforce a monthly token usage limit.
- Reuse the same Gemini service from other Odoo modules.
- Parse JSON responses generated by AI prompts.
The module is designed as a foundation dependency for Gemini-powered Odoo apps such as AI Sales, AI CRM, AI Helpdesk, AI Inventory, AI Accounting assistants, workflow automation tools, and custom customer projects.
2. What the Module Adds
Settings UI
The module adds a Gemini AI Connector block in Odoo Settings with:
- Gemini API Key.
- Gemini model selector.
- Custom Gemini model ID.
- Gemini API Base URL.
- Request Timeout.
- Test Gemini Connection action.
- Total Tokens Used counter.
- Monthly Token Limit.
- Reset Counter action.
Reusable Service
The module registers this Odoo abstract model:
sm.gemini.connector.service
Dependent modules can call:
env['sm.gemini.connector.service'].call_ai_chat(messages)
or directly:
env['sm.gemini.connector.service'].call_gemini_chat(messages)
JSON Helper
The connector also includes:
env['sm.gemini.connector.service'].parse_json_response(response)
This helper removes common Markdown code fences and extracts JSON blocks from Gemini responses.
Configuration Parameters
The connector stores settings in ir.config_parameter:
- sm_gemini_connector.gemini_api_key
- sm_gemini_connector.gemini_model
- sm_gemini_connector.gemini_custom_model
- sm_gemini_connector.gemini_api_base_url
- sm_gemini_connector.request_timeout
- sm_gemini_connector.total_tokens_used
- sm_gemini_connector.monthly_token_limit
3. Installation
- Copy the sm_gemini_connector folder into an Odoo addons path.
- Restart Odoo.
- Update Apps List.
- Install Gemini AI Connector for Odoo.
Command-line example:
python3 ~/odoo/odoo-18/odoo-server \ -c ~/odoo/conf/odoo.conf \ -d your_database \ -i sm_gemini_connector \ --stop-after-init \ --no-http
Dependencies
The module depends on:
- base
- web
No Sales, CRM, Inventory, Accounting, or Helpdesk dependency is required. This is intentional so the connector can be reused by many app types.
4. Gemini Configuration
Get API Key
- Open Google AI Studio.
- Create or select a project.
- Generate a Gemini API key.
- Copy the API key.
Configure Odoo
Open Settings -> Gemini AI Connector.
Enter Gemini API Key.
Select a Gemini model.
Keep API Base URL as:
https://generativelanguage.googleapis.com/v1beta
Set request timeout if needed.
Click Save.
Click Test Gemini Connection.
Model Selection
The connector currently includes:
- Gemini 2.5 Flash Lite.
- Gemini 2.5 Flash.
- Gemini 2.5 Pro.
- Gemini Flash Latest.
- Gemini 2 Flash.
- Gemini 2 Flash Lite.
- Custom Model ID.
Recommended starting model:
gemini-2.5-flash-lite
This model is usually a practical first choice for demos and lightweight AI automations.
Custom Model ID
Use Custom Model ID when Google exposes a model not listed in the dropdown.
Example:
gemini-2.5-flash-lite
5. Connection Test
The Test Gemini Connection button sends a small prompt to Gemini:
Reply with exactly: Gemini connected successfully.
If the connection works, Odoo shows a success notification.
If the connection fails, the notification shows a sanitized error message. The connector does not expose the API key in error messages.
Common Failure Reasons
Invalid API Key
Cause:
- Key was copied incorrectly.
- Key belongs to another project.
- Key was deleted or restricted.
Fix:
- Generate a new key in Google AI Studio.
- Paste it into Odoo and save.
Quota Exceeded
Cause:
- Google AI Studio free-tier request-per-day or request-per-minute limit has been reached.
Fix:
- Wait for quota reset.
- Use another model with available quota.
- Enable billing in Google Cloud.
Wrong Model ID
Cause:
- Selected model is not available for the API key/project.
- Custom model ID is misspelled.
Fix:
- Select a known working model.
- Check model availability in Google AI Studio.
Wrong API Base URL
Cause:
- API base URL was changed incorrectly.
Fix:
Restore:
https://generativelanguage.googleapis.com/v1beta
6. Developer Usage
Basic Chat Call
Use chat-style message dictionaries. The connector converts them to Gemini request format internally.
messages = [ { 'role': 'user', 'content': 'Explain Odoo Sales in one short paragraph.', } ] response = env['sm.gemini.connector.service'].call_ai_chat( messages, temperature=0.7, max_tokens=300, )
Direct Gemini Call
response = env['sm.gemini.connector.service'].call_gemini_chat( messages, temperature=0.4, max_tokens=500, )
System Prompt
The connector supports system messages.
messages = [ { 'role': 'system', 'content': 'You are a concise Odoo assistant.', }, { 'role': 'user', 'content': 'Summarize this customer note.', }, ] response = env['sm.gemini.connector.service'].call_ai_chat(messages)
Model Override
You can override the configured model for one call:
response = env['sm.gemini.connector.service'].call_ai_chat( messages, model='gemini-2.5-flash', )
JSON Response Parsing
raw_response = env['sm.gemini.connector.service'].call_ai_chat(messages) data = env['sm.gemini.connector.service'].parse_json_response(raw_response)
The parser handles:
- Plain JSON.
- Markdown json code fences.
- Markdown generic code fences.
- Text responses that contain a JSON object.
7. API Behavior
Endpoint
The connector calls:
POST {Gemini API Base URL}/models/{model}:generateContent
Default endpoint:
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent
Payload
The connector converts Odoo/chat-style messages to Gemini payload:
- system -> systemInstruction
- user -> Gemini user role
- assistant -> Gemini model role
8. Usage Tracking
Gemini returns usage metadata in the response.
The connector reads:
- promptTokenCount
- candidatesTokenCount
- totalTokenCount
It stores the total in:
sm_gemini_connector.total_tokens_used
Monthly Token Limit
The monthly limit is stored in:
sm_gemini_connector.monthly_token_limit
If the limit is 0, the connector treats it as unlimited.
If total usage reaches the configured limit, the connector stops requests and raises:
Gemini Connector monthly token limit reached.
Reset Counter
Use Reset Counter in Settings to reset usage to 0.
9. Security Notes
API Key Storage
The Gemini API key is stored in Odoo ir.config_parameter.
Recommendations:
- Limit Settings access to trusted administrators.
- Do not paste API keys into logs, chat messages, tickets, or screenshots.
- Rotate keys if they are exposed.
- Use Google Cloud restrictions where possible.
Error Sanitization
The connector sanitizes common API key patterns in error messages before showing them to users.
Still, administrators should avoid sharing full tracebacks publicly.
10. Troubleshooting
Test Connection Fails
Check:
- API key is saved.
- Model is available for the current project.
- API base URL is correct.
- Google AI Studio quota is available.
- Odoo server can reach the internet.
Quota Error
If Google says quota is exceeded:
- Check Google AI Studio Rate Limit page.
- Try another Gemini model with available quota.
- Wait for daily reset.
- Enable billing if production usage is needed.
Module Does Not Appear in Settings
Check:
- Module is installed.
- Browser page is refreshed.
- User has access to General Settings.
- Odoo assets are refreshed if needed.
Command:
python3 ~/odoo/odoo-18/odoo-server \ -c ~/odoo/conf/odoo.conf \ -d your_database \ -u sm_gemini_connector \ --stop-after-init \ --no-http
11. Technical Reference
Python Model
sm.gemini.connector.service
Important Methods
call_ai_chat(messages, temperature=0.7, max_tokens=1000, model=None) call_gemini_chat(messages, temperature=0.7, max_tokens=1000, model=None) test_gemini_connection() parse_json_response(response)
Settings Fields
sm_gemini_connector_gemini_api_key sm_gemini_connector_gemini_model sm_gemini_connector_gemini_custom_model sm_gemini_connector_gemini_api_base_url sm_gemini_connector_request_timeout sm_gemini_connector_tokens_used sm_gemini_connector_monthly_token_limit
Compatibility
- Tested on Odoo 18.0 Community & Enterprise.
- Requires Odoo base and web.
- Uses standard Odoo ORM, res.config.settings, and ir.config_parameter.
- Uses Python requests library.
12. Support and Maintenance
Maintainer:
Steven Marp
License:
OPL-1
The module is intended as a shared Gemini foundation for future Odoo AI apps and customer-specific AI automation projects.
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module