Hi, upgraded to max cause gemini told me, i can add it to CSAI. But all the ways presented by Gemini don’t work. There is no add button in settings, like suggested and adding code to functions.php in child also doesn’t work. Hope you can help
Hey @ospahr,
Thanks for writing in! We currently you have access and integrate OpenAI, HuggingFace, Anthropic, Grok, GPT4All, LM Studio, and Stable Diffusion in the CSAI settings. To add Gemini, you will have to register a new Provider. Check out this developer guide:
We do plan to add native support for Gemini.
If you already have your code added in your child theme’s functions.php file, please do share it in your next response so we can check it.
Best Regards.
Thank you, here is the code in my function.php
<?php // ============================================================================= // FUNCTIONS.PHP // ----------------------------------------------------------------------------- // Overwrite or add your own custom functions to Pro in this file. // ============================================================================= // ============================================================================= // TABLE OF CONTENTS // ----------------------------------------------------------------------------- // 01. Enqueue Parent Stylesheet // 02. Additional Functions // ============================================================================= // Enqueue Parent Stylesheet // ============================================================================= add_filter( 'x_enqueue_parent_stylesheet', '__return_true' ); // Additional Functions // ============================================================================= // Registrierung von Google Gemini für Cornerstone AI (CSAI) add_filter( 'cs_ai_providers', function( $providers ) { $providers['google_gemini'] = [ 'label' => 'Google Gemini', 'endpoint' => 'https://generativelanguage.googleapis.com/v1beta/openai/', 'models' => [ 'gemini-1.5-flash' => 'Gemini 1.5 Flash', 'gemini-1.5-pro' => 'Gemini 1.5 Pro' ] ]; return $providers; });Hey @ospahr,
I tried testing this but it’s not simple so it’s strongly recommended that we wait for the official integration of Gemini. For now, try the following code. Change YOUR_ACTUAL_API_KEY_HERE with your actual Gemini API.
You don’t have to encode the API under CSAI because the API is hardcoded in the code. It works in my test but it’s no guarantee that it will work on your end and we regretfully cannot provide further support on this as the work involved for the integration is quite involved.
add_action('init', function() {
// 1. Enter your Google Gemini API Key here
$my_gemini_key = 'YOUR_ACTUAL_API_KEY_HERE';
if (function_exists('cs_ai_provider_register')) {
cs_ai_provider_register('gemini', [
'label' => __('Google Gemini', 'cornerstone'),
'logo' => 'https://upload.wikimedia.org/wikipedia/commons/8/8a/Google_Gemini_logo.svg',
'description' => __('Generates text using Google Gemini models.', 'cornerstone'),
'chat' => [
'values' => [
// UPDATED: Default to the new Flash model
'model' => 'gemini-2.5-flash',
],
// We keep the controls in case they decide to show up,
// but the code below will use the hardcoded key if the field is empty.
'controls' => [
[
'key' => 'model',
'type' => 'select',
'label' => __('Model', 'cornerstone'),
'options' => [
// UPDATED: New model options
['value' => 'gemini-2.5-flash', 'label' => 'Gemini 2.5 Flash (Fast)'],
['value' => 'gemini-2.5-pro', 'label' => 'Gemini 2.5 Pro (High Quality)'],
],
],
],
'callable' => function($request) use ($my_gemini_key) {
$settings = $request['settings'];
// Use the setting if available, otherwise fallback to the hardcoded key
$api_key = !empty($settings['api_key']) ? $settings['api_key'] : $my_gemini_key;
// UPDATED: Fallback to the new model
$model = $settings['model'] ?: 'gemini-2.5-flash';
$prompt = $request['message']['content'] ?? '';
if (empty($api_key) || $api_key === 'YOUR_ACTUAL_API_KEY_HERE') {
return ['message' => ['content' => 'Error: Please add your API Key in functions.php']];
}
// Google Gemini API Endpoint
$url = "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent?key={$api_key}";
$body = [
'contents' => [
[
'parts' => [
['text' => $prompt]
]
]
]
];
$response = wp_remote_post($url, [
'headers' => ['Content-Type' => 'application/json'],
'body' => json_encode($body),
'timeout' => 30
]);
if (is_wp_error($response)) {
return ['message' => ['content' => 'Connection Error: ' . $response->get_error_message()]];
}
$data = json_decode(wp_remote_retrieve_body($response), true);
if (isset($data['error'])) {
return ['message' => ['content' => 'Gemini API Error: ' . $data['error']['message']]];
}
$text = $data['candidates'][0]['content']['parts'][0]['text'] ?? 'No response from Gemini.';
return [
'message' => [
'content' => $text,
],
];
},
],
]);
}
}, 100);
Thanks a lot and a happy new year. we will continue using your great products
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

