GreenOps AI Studio Docs

Technical documentation for the edge LLM gateway.

What is GreenOps Studio AI?

GreenOps Studio AI is an AI Control Plane Enterprise and Edge-Native AI Proxy: an OpenAI-compatible LLM Security Gateway and AI FinOps Platform on Cloudflare Workers. It applies semantic caching, smart Flash routing, RAG token compression, FinOps telemetry, and PII Pre-Masking AES-256-GCM before Gemini, OpenAI, or a local GPU — with an AI Audit Trail SHA-256 for EU AI Act Compliance Software duties.

Introduction & architecture

GreenOps AI is an OpenAI-compatible LLM gateway on Cloudflare Workers. Traffic uses native TLS 1.3 (TLS 1.2 fallback) at the edge. Every chat request is Bearer-authenticated, heuristically sanitized, AES-256-GCM PII-sealed, optionally served from an advanced semantic KV cache, then smart-routed to Flash, a local GPU, Gemini Pro, or OpenAI — with a SHA-256 notary block on each completion.

Edge Worker

TypeScript proxy at the Cloudflare PoP with native TLS 1.3 (TLS 1.2 fallback). OpenAI-compatible POST /v1/chat/completions on the EU edge.

Advanced semantic cache

Multi-Tier Semantic Cache on GREENOPS_CACHE: exact/canonical/bag fingerprints, then edge cosine ≥ 95%, then LSH/Jaccard neighbor (≥ 0.65). HIT replies (including Studio SSE) skip the GPU and cost $0 / 0 g CO₂. Match type is X-GreenOps-Cache-Match.

Smart routing

Light prompts go to Flash/mini/local GPU. Pro/4o stay for high-complexity work. Outcome is X-GreenOps-Route.

RAG compression

PDF/TXT in context_documents are cleaned, reranked and capped (~28% / 280 tokens) before the LLM payload.

PII masking

On the EU edge (gcp:europe-west1), emails, cards, phones and tax IDs are AES-256-GCM sealed in WASM and pre-masked to placeholders before any Gemini/OpenAI call. Count is returned on X-PII-Redacted-Count and X-GreenOps-Sealed.

SHA-256 notary ledger

Every LLM completion and IDP ingest/answer appends a block to a private SHA-256 chain (prevHash→hash, schema v4). Header X-Audit-Hash exposes the head; GET /v1/audit/verify proves integrity for corporate security audits (EU AI Act).

FinOps / ESG

Response headers expose USD saved, CO₂ avoided, cache HIT/MISS, route, quota remaining and user tier.

Heuristic sanitization

The edge Worker scores incoming prompts in real time, rewrites injection, exploit and secret-leakage spans, then forwards the corrected text. Residual high-confidence attacks return 403 with X-GreenOps-Sanitize: blocked.

  • Cold path (MISS): compress RAG + WASM trim, smart-route the model, call the LLM, write KV, emit FinOps headers.
  • Hot path (HIT): KV/memory read — typically tens of milliseconds. Works with stream: true (SSE synthesized from cache).
  • Hybrid failover: cloud outage or X-GreenOps-Confidentiality hedges instantly to Ollama/GPU; chat continuity preserved.
  • Chat history: each completion is appended to Cloudflare KV GREENOPS_CHATS for the signed-in user.

FinOps stack: cache, routing, RAG

Three levers cut spend before a paid model is called. All four plans (Free, Pro, Business, Enterprise) get advanced semantic cache. Paid plans add longer TTL, failover, and higher rate limits.

Smart model routing

The edge micro-classifier scores complexity (length, reasoning verbs, RAG). Below the premium gate (~0.82, recalibrated by the EU monitor) Pro/4o are downgraded to Flash, mini, or local-llama3-8b. Above the gate, Flash/mini are promoted to the preferred flagship (Gemini Pro / GPT-4o). Outcome is X-GreenOps-Route + X-GreenOps-Cascade.

  • X-GreenOps-Route: flash — light task on Gemini Flash or GPT-4o-mini (after semantic-cache miss).
  • X-GreenOps-Route: local — local GPU / Ollama when reachable.
  • X-GreenOps-Route: premium — high-complexity / reasoning → flagship (including auto-promotion from Flash).
  • X-GreenOps-Route: green — non-urgent small-tier pinned to the greener EU grid.
  • X-GreenOps-Cache-Match — exact · bag · cosine · neighbor · vectorize (HIT = $0 tokens).

European carbon-aware routing

Non-urgent work is steered to the greenest reachable datacenter using live EU grid intensity.

EU edge performance monitor

Background telemetry recalibrates smart routing from empirical latency, accuracy and cost.

RAG token compression

Send PDF/TXT excerpts as context_documents (string or string[]). The Worker always strips page numbers, drops near-duplicates, reranks against the user query (relevance ≥ 0.32) and caps the injected context at 28% of original tokens or 280 tokens. Studio attachments take the same path.

Intelligent Document Processing (IDP)

Zero-export document pipeline for banks, insurers, and public sector: native PDF/TXT parsing on the Worker, tenant-scoped vector archive (VECTORIZE_DOCS), extractive answers without calling cloud LLMs, and SHA-256 notary linkage (schemaVersion: 4, field idp.documentSha256, header X-Audit-Hash).

IDP endpoints

Sealed document APIs (User / Admin)
MethodPathPurpose
POST/v1/idp/ingestParse PDF/TXT (Base64 or text), PII-seal, chunk + Vectorize upsert · X-GreenOps-Document-Hash
GET/v1/idp/documentsList tenant archive metadata (no full plaintext dump)
POST/v1/idp/queryVector / Jaccard retrieval over corporate chunks
POST/v1/idp/answerExtractive grounded answer + citations · audit idp_answer

Example: ingest + answer

cURL · IDP zero-export
curl -X POST https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/idp/ingest \
  -H "Authorization: Bearer GreenOpsKey123" -H "X-User-Role: User" \
  -H "Content-Type: application/json" \
  -d '{"filename":"nda.txt","text":"ARTICOLO 1 … zero-export …"}'

curl -X POST https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/idp/answer \
  -H "Authorization: Bearer GreenOpsKey123" -H "X-User-Role: User" \
  -H "Content-Type: application/json" \
  -d '{"query":"clausola zero-export","topK":4}'

Every ingest/query/answer appends a notarized audit block (provider: idp, signed idp metadata, blockHeight/chainId) with response header X-Audit-Hash. Compliance verifies integrity via GET /v1/audit/logs and GET /v1/audit/verify.

FinOps headers & quotas

Response headers

FinOps / ESG / quota headers on POST /v1/chat/completions
HeaderMeaning
X-Cache-StatusHIT / MISS / BYPASS. HIT is valid for streamed Studio replies.
X-GreenOps-Cache-Matchmemory / exact / canonical / bag / cosine (≥95%) / neighbor.
X-GreenOps-Routeflash · local · premium · requested
X-Fallback-Triggeredtrue when 429/5xx on the primary forced a secondary provider.
X-GreenOps-Cost-Saved-USDUSD avoided (cache HIT + WASM trim + RAG compression).
X-GreenOps-CO2-Saved-GGrams of CO₂ avoided.
X-RateLimit-LimitWindow quota: 1000 (Free/day), 100000 (Pro/month), 1000000 (Business/month), unlimited (Enterprise).
X-RateLimit-RemainingRequests left, or unlimited on Enterprise.
X-RateLimit-Windowday · month · unlimited
X-PII-Redacted-CountPII items masked before upstream.
X-GreenOps-Sanitizeclean / corrected / blocked. Corrected prompts are rewritten then forwarded.
X-GreenOps-Chat-IdKV conversation UUID for the saved turn.

Rate limits by plan

Edge quotas enforced before the LLM is called
PlanWindowBurst / minCache TTL
Free1,000 req/day3024 hours · semantic cache on
Pro100,000 req/month1,00030 days · failover OpenAI
Business1,000,000 req/month5,00030 days · ESG/FinOps export
EnterpriseUnlimited20,00030 days · dedicated footprint

Authentication & setup

Protected routes require gateway authentication via Authorization: Bearer <key> (preferred) or the native header X-Proxy-Auth. Studio JWT sessions also resolve to the same tenant key. All client↔edge traffic is carried over Cloudflare TLS 1.3 (secure TLS 1.2 fallback). For local and sandbox testing use the bootstrap key GreenOpsKey123.

Admin whitelist (server-side)

Admin privileges are not granted by the client header alone. The Worker elevates accounts whose email is listed in ADMIN_EMAILS (default includes info@copycomp.it), or when the master bootstrap key is presented with X-User-Role: Admin. This unlocks /v1/admin/users, the legal pack, air-gap controls, and analytics reset — Designed & Engineered in Italy for enterprise least-privilege.

Quick test key

Send Authorization: Bearer GreenOpsKey123 on chat, analytics and audit calls. Paid plans receive a gop_pro_… key after Stripe checkout. Provider keys (Gemini/OpenAI) are optional when the Worker already has server-side credentials.

Gateway authentication headers
HeaderRequiredMeaning
AuthorizationYes*Bearer token. Example: Bearer GreenOpsKey123.
X-Proxy-AuthYes*Equivalent gateway key if you do not send Authorization.
X-User-RoleNoUser (default), FinOps, Compliance, Admin.
X-User-Gemini-KeyNoBring-your-own Gemini key.
X-User-OpenAI-KeyNoBring-your-own OpenAI key.
X-Local-LLM-UrlNoOpenAI-compatible local runtime (Ollama / GPU).
X-Webhook-UrlNoSlack / Teams webhook. POSTed asynchronously via ctx.waitUntil with FinOps (cost, tokens) and ESG (carbon offset) fields.
X-Chat-IdNoExisting conversation UUID. Completions also accept body chat_id.

Copy-ready authentication

Send Authorization: Bearer <TOKEN> on every protected call. The snippets below POST a JSON chat body to /v1/chat/completions. Replace GreenOpsKey123 with your provisioned key in production.

Endpoints & API reference

Proxy URL: https://greenops-ai-proxy.copycomp-ai.workers.dev

Proxy URL
https://greenops-ai-proxy.copycomp-ai.workers.dev
POST · Chat Completions
https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chat/completions

OpenAPI explorer

Interactive live OpenAPI 3.0: expand any operation, set Bearer + X-User-Role, then Try it out against the production gateway.

Cloudflare Workers (EU edge) and mandatory PII masking guarantee full alignment with European data-protection standards (GDPR / EU AI Act). Response headers such as X-Export-Reports and X-User-Role document export eligibility and RBAC. Made in Italy: quality, ethics, transparency.

Loading specification…

Proxy endpoints on the GreenOps AI gateway
MethodPathAuthPurpose
POST/v1/chat/completionsYes + X-User-RoleOpenAI-compatible chat (JSON or SSE). Semantic cache, smart routing, RAG, PII seal. KV persist.
GET/v1/account/quotaYesRemaining quota for the current plan (day/month/unlimited)
GET/v1/chatsYes + X-User-RoleList saved conversations (User / Admin)
POST/v1/chatsYes + X-User-RoleCreate an empty chat
GET/v1/chats/:idYes + X-User-RoleLoad messages of one conversation
DELETE/v1/chats/:idYes + X-User-RoleDelete a conversation from KV
GET/healthNoUptime probe: status, timestamp, KV semantic cache
GET/v1/healthNoKV cache + analytics, Gemini / OpenAI readiness
GET/v1/monitoring/modelsYes + X-User-RoleEU edge EMA latency/accuracy/cost + smart-routing policy
GET/v1/analyticsYes + X-User-RoleFinOps / ESG totals. Response X-Export-Reports: true on Business/Enterprise
POST/v1/analytics/resetYes + AdminReset KV analytics totals
GET/v1/reports/monthlyFinOps/Admin + X-Export-ReportsCSRD/ESG monthly pack JSON/CSV/HTML. Business/Enterprise
GET/v1/audit/logsCompliance / AdminEU AI Act SHA-256 notary chain (schema v4) · X-Audit-Hash
GET/POST/v1/audit/verifyCompliance / AdminNotary integrity check · tamperEvidence · PQC status
GET/POST/v1/security/pqcCompliance / AdminML-KEM-768 hybrid + Cloudflare PQ TLS profile
GET/v1/esg/ledgerCompliance / FinOps / AdminCSRD ESRS E1 credits ledger · X-Export-Reports: csrd-ledger
GET/v1/esg/savings-chainYes + X-User-RoleSHA-256 CO₂/energy savings chain (cache + routing + RAG)
GET/v1/finops/paybackFinOps / AdminLicense payback / ROI · X-Export-Reports: finops-payback
GET/v1/admin/legal-packAdminMSA + GDPR/EU AI Act attestation · X-Export-Reports: admin-legal-pack
GET/POST/v1/sovereignty/air-gapAdmin (GET also Compliance)National air-gap kill-switch — blocks cloud egress, 100% local Ollama/cluster · X-GreenOps-Air-Gap
POST/v1/webhooks/stripeStripe-SignatureCheckout/invoice → Pro, Business or Enterprise; cancel/unpaid → deactivate
POST/api/webhooks/stripeStripe-SignatureAlias of /v1/webhooks/stripe
GET/v1/openapi.jsonNoOpenAPI 3.0.3 — drives this interactive explorer
GET/v1/openapi/validationNoEnterprise/compliance OpenAPI validation report (audit, ledger, RBAC, export)

Chat Completions

POST JSON with model + messages. Optional context_documents are always compressed before the LLM. Every sample sends Authorization: Bearer <TOKEN>. Testing uses GreenOpsKey123. Replies persist to KV and return X-GreenOps-Chat-Id, plus X-GreenOps-Route and cache/quota headers. stream: true still participates in the semantic cache.

Copy a language below. Each block is a ready-to-run POST to /v1/chat/completions.

Chat history & sessions

Studio conversations are stored on Cloudflare KV (GREENOPS_CHATS, fallback GREENOPS_CACHE). Every record has a mandatory user_id foreign key: list/get/delete/save queries only return rows for the signed-in user (WHERE user_id = current_user.id). History requires login. Pass X-Chat-Id (or body chat_id) to continue a session; the response header X-GreenOps-Chat-Id is the conversation to reuse.

  • Per-key isolation: KV keys never store the Bearer secret in plaintext.
  • Limits: 80 chats per user, 200 messages per chat. Title is taken from the first user prompt.
  • Studio sidebar calls GET /v1/chats and GET /v1/chats/:id with the same Bearer token as completions.
  • Bind GREENOPS_CHATS in wrangler.toml. Completions still persist if the binding falls back to GREENOPS_CACHE.
Chat history API on Cloudflare KV
MethodPathAuthPurpose
POST/v1/chat/completionsYesSaves the turn; returns X-GreenOps-Chat-Id
GET/v1/chatsYes{ chats: [{ id, title, updatedAt, preview, messageCount }] }
POST/v1/chatsYesCreate empty chat { title? } → 201
GET/v1/chats/:idYes{ id, title, messages: [{ role, content, at }] }
DELETE/v1/chats/:idYes{ deleted: true, id }

Copy a session example: complete a chat, list history, create an empty chat, reload messages, then delete. Always send Authorization: Bearer <TOKEN>.

cURL · chat session
# 1) First turn — persist a new chat (read X-GreenOps-Chat-Id from the response)
curl -D - https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer GreenOpsKey123" \
  -d '{
    "model": "gemini-3.5-flash",
    "messages": [{"role": "user", "content": "Hello GreenOps"}]
  }'

# 2) Continue the same session
curl https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer GreenOpsKey123" \
  -H "X-Chat-Id: CHAT_ID" \
  -d '{
    "model": "gemini-3.5-flash",
    "messages": [
      {"role": "user", "content": "Hello GreenOps"},
      {"role": "assistant", "content": "Hi"},
      {"role": "user", "content": "Continue"}
    ]
  }'

# 3) List, load, create empty, delete
curl https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chats \
  -H "Authorization: Bearer GreenOpsKey123"
curl https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chats/CHAT_ID \
  -H "Authorization: Bearer GreenOpsKey123"
curl -X POST https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chats \
  -H "Authorization: Bearer GreenOpsKey123" \
  -H "Content-Type: application/json" \
  -d '{"title":"New chat"}'
curl -X DELETE https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/chats/CHAT_ID \
  -H "Authorization: Bearer GreenOpsKey123"

Department RBAC

Send X-User-Role on every Control Plane call. Roles isolate departments: FinOps never reads chat text; Compliance never leaves the audit trail.

X-User-Role matrix
Role Chat / history Analytics ESG export Audit logs

Cryptographic audit trail (EU AI Act)

GET /v1/audit/logs (Compliance / Admin) returns a private SHA-256 block-chain notary (schema v4) for every LLM transaction and IDP answer: each block signs timestamp, request ID, model, tokens, USD/CO₂, PII, risk, optional idp, blockHeight, chainId, prevHash and hash. Tampering breaks chainValid. Validate with GET/POST /v1/audit/verify (tamperEvidence). Headers: X-Audit-Hash, X-GreenOps-Notary. Built for EU AI Act logging duties in banking, insurance, and public sector.

ESG & FinOps monthly export

GET /v1/reports/monthly?month=YYYY-MM&format=json|csv|html with header X-Export-Reports (true/json/csv/html). Returns a monthly sustainability pack: economic savings (USD) + avoided carbon footprint (g/kg/t) for CSRD/ESG corporate filings. FinOps/Admin on Business or Enterprise receive X-Export-Reports: true and a Content-Disposition attachment. Free/Pro return 403 export_plan_required. Studio Dashboard exposes month picker + CSV/PDF/HTML download.

Stripe webhooks

Point the Stripe Dashboard endpoint at the URL below. The Worker verifies Stripe-Signature with stripe.webhooks.constructEvent when STRIPE_WEBHOOK_SECRET is set.

POST · Stripe webhook
https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/webhooks/stripe
  • checkout.session.completed and invoice.payment_succeeded activate Pro, Business or Enterprise (email + subscription_id + plan → user record). New users get a welcome email with a password-setup link.
  • Plan is resolved from metadata.plan, Payment Link, price nickname/amount ($29 / $149 / $499+), or STRIPE_PRICE_*.
  • customer.subscription.deleted, subscription.updated with status unpaid/canceled, or a final invoice.payment_failed deactivates access (active: false, profile → Free).
  • Configure POST /v1/webhooks/stripe or POST /api/webhooks/stripe. Alias accepted. No browser CORS is required.
cURL · webhook
curl -X POST https://greenops-ai-proxy.copycomp-ai.workers.dev/v1/webhooks/stripe \
  -H "Content-Type: application/json" \
  -H "Stripe-Signature: t=1700000000,v1=…" \
  -d '{"type":"checkout.session.completed","data":{"object":{"customer_email":"dev@acme.com"}}}'

Pricing tiers & quotas

Limits are enforced at the edge. Free is daily + burst; Pro and Business are monthly; Enterprise is unlimited.

GreenOps AI Studio pricing tiers
Plan Price Request limits Features
Free$0/mo1,000 req/day · 30 req/minAdvanced semantic cache, smart Flash routing, RAG compression, baseline PII, Community & Docs
Pro$29/mo100,000 req/month · 1,000/minOpenAI failover, 30-day cache TTL, real-time ESG/FinOps telemetry, automated PII anonymization
Business$149/mo1,000,000 req/month · 5,000/minESG/FinOps PDF & CSV export, advanced PII rules, priority support
Enterprise$499+/moUnlimited · 20,000/minDedicated Workers & storage, custom ESG audit, 99.9% uptime SLA

Error handling & status codes

The gateway returns JSON errors. Chat quota responses include error.code, error.message and error.upgrade_url.

HTTP status codes returned by the AI gateway
Status Name Typical cause What to do
401UnauthorizedMissing/invalid Bearer or X-Proxy-Auth.Send Authorization: Bearer GreenOpsKey123 (test) or your provisioned key. Check for extra spaces.
429Rate Limit ExceededFree 1,000/day or 30/min; Pro 100k/mo; Business 1M/mo. Read X-RateLimit-Remaining.Wait for Retry-After, or upgrade. Burst resets every 60 seconds.
500Gateway ErrorUnhandled Worker exception or upstream failure after retries.Retry with backoff. Check GET /v1/health. Confirm Gemini/OpenAI keys if the model is cloud-hosted.
404Not FoundUnknown /v1/chats/:id for this gateway key.List chats with GET /v1/chats, then use an id from that payload.
  • 403: RBAC blocked the route (for example Audit requires Compliance/Admin) or a residual prompt attack was blocked after heuristic sanitization (X-GreenOps-Sanitize: blocked). Corrected prompts continue with corrected.
  • 400: malformed JSON, missing messages[], or a required provider key is absent for that model.
  • SSE: send stream: true. Cache HIT is returned as synthesized SSE (no paid upstream call).
  • 404 on /v1/chats/:id: the conversation is missing or belongs to another gateway key.

Testing & QA

GreenOps ships an automated suite so the gateway, semantic cache, chat history, and the Studio docs modal stay copy-ready. Backend tests run in Vitest against an in-memory mock Worker (or a live origin when GREENOPS_URL is set). Frontend tests run in Playwright against the static Studio server on port 4173.

  • Install once: npx playwright install chromium (needed for E2E). Vitest is a local npm dependency.
  • Default API tests never call production: tests/helpers/mock-greenops-worker.js mocks completions, KV cache HIT/MISS, and /v1/chats.
  • Point API tests at a live Worker with GREENOPS_URL and optional GREENOPS_AUTH.

Backend · Vitest

tests/api.spec.js covers the OpenAI-compatible gateway: missing Bearer returns 401; a valid key returns 200 with FinOps/ESG headers; an identical prompt is a semantic-cache MISS then HIT; GET/POST/DELETE /v1/chats persist and drop history. Run with npm run test:api (vitest run tests/api.spec.js).

Frontend · Playwright

tests/e2e/docs.spec.js opens Studio, clicks Documentation, fetches same-origin /docs.html without redirect loops, and checks the copyable language tabs (cURL, Python, JavaScript/TypeScript, C#, VB.Net) in English and Italian. Playwright starts node scripts/studio-static.mjs on port 4173. Run with npm run test:e2e.

Quick commands

From the repository root. npm test runs API tests first, then E2E.

Automated test scripts
Command What it runs
npm testRuns all tests
npm run test:apiRuns the API tests
npm run test:e2eRuns the E2E tests
npm · test scripts
npm test
npm run test:api
npm run test:e2e

Contact & support

Reach GreenOps Studio by email. Technical issues go to support; general inquiries to info; Enterprise and commercial requests to sales.