Skip to main content

Google Gemini Integration

KoreShield proxies Gemini requests through the OpenAI-compatible endpoint and applies sanitization and policy enforcement before forwarding to Gemini.

Installation

npm install koreshield

Setup

1

Get API Keys

Obtain your Google Gemini API key and your KoreShield API key.
2

Install KoreShield SDK

Install the KoreShield SDK for your preferred language.
3

Configure Security

Set up KoreShield scanning and proxy configuration.

Basic Request

import { Koreshield } from "koreshield";

const koreshield = new Koreshield({
  apiKey: process.env.KORESHIELD_API_KEY
});

const scan = await koreshield.scan({
  content: "Summarize the quarterly update."
});

if (scan.threat_detected) {
  throw new Error("Threat detected");
}

const response = await fetch("http://localhost:8000/v1/chat/completions", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    model: "gemini-2.5-pro",
    messages: [{ role: "user", content: "Summarize the quarterly update." }]
  })
});

Streaming

const response = await fetch("http://localhost:8000/v1/chat/completions", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    model: "gemini-2.5-pro",
    stream: true,
    messages: [{ role: "user", content: "Write a release summary." }]
  })
});

System Prompts and Multi-Turn

{
  "model": "gemini-2.5-pro",
  "messages": [
    {"role": "system", "content": "You are a product analyst."},
    {"role": "user", "content": "Summarize the update."},
    {"role": "assistant", "content": "Summary..."},
    {"role": "user", "content": "List risks."}
  ]
}

Compatibility Notes

KoreShield forwards OpenAI-compatible payloads to the Gemini provider adapter. Validate any advanced fields with your Gemini setup before using in production.

Error Handling

  • 403 indicates a blocked request due to policy enforcement
  • 429 or 5xx typically indicates provider or rate-limit issues

Security Controls

security:
  sensitivity: medium
  default_action: block
  features:
    sanitization: true
    detection: true
    policy_enforcement: true

Next Steps

Configuration

Configure providers and security settings

JavaScript SDK

Explore the JavaScript SDK

Python SDK

Explore the Python SDK

Build docs developers (and LLMs) love