Legacy IntegrationsGeminiAPI
Gemini JavaScript SDK Integration
Use Gemini's JavaScript SDK to integrate with CoreValue to log your Gemini AI usage.
This integration method is maintained but no longer actively developed. For the best experience and latest features, use our new AI Gateway with unified API access to multiple models.
Proxy Integration
Fetch
Visit the Google Generative AI API Key page. Follow the instructions to create a new API key. Make sure to save the key as you will need it for the next steps.
export COVA_API_KEY=<your CoreValue API key>
export GOOGLE_API_KEY=<your Google Generative AI API key>Ensure you have the necessary packages installed in your Javascript project:
npm install node-fetchconst fetch = require('node-fetch');
const url = `https://gateway.corevalue.dev/v1beta/models/model-name:generateContent?key=${process.env.GOOGLE_API_KEY}`;
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.COVA_API_KEY}`,
'Cova-Target-Url': `https://generativelanguage.googleapis.com`,
};
const body = JSON.stringify({
contents: [{
parts: [{
text: 'Write a story about a magic backpack.'
}]
}]
});
fetch(url, { method: 'POST', headers: headers, body: body })
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));Google Generative AI SDK
Visit the Google Generative AI API Key page. Follow the instructions to create a new API key. Make sure to save the key as you will need it for the next steps.
export COVA_API_KEY=<your CoreValue API key>
export GOOGLE_API_KEY=<your Google Generative AI API key>Ensure you have the necessary packages installed in your Javascript project:
npm install @google/genaiimport { GoogleGenAI } from "@google/genai";
if (!process.env.GOOGLE_API_KEY) {
throw new Error("GOOGLE_API_KEY environment variable must be set");
}
if (!process.env.COVA_API_KEY) {
throw new Error("COVA_API_KEY environment variable must be set");
}
const genAI = new GoogleGenAI({
apiKey: `${process.env.GOOGLE_API_KEY}`,
httpOptions: {
baseUrl: "https://gateway.corevalue.dev",
headers: {
"Authorization": `Bearer ${process.env.COVA_API_KEY}`,
"Cova-Target-Url": "https://generativelanguage.googleapis.com", // Change this to "https://aiplatform.googleapis.com" if vertexai is set to true
},
},
});
async function generateContent() {
const response = await genAI.models.generateContent({
model: "gemini-2.0-flash-001",
contents: "Why is the sky blue?",
});
console.log(response.text);
}
generateContent();