The MIVAA Gateway is a Supabase Edge Function that acts as a proxy to the MIVAA Python backend service. It provides access to all backend APIs including RAG, search, AI services, and more.
Edge Function: mivaa-gateway
Base URL: https://bgbavxtjlbvgplozizxu.supabase.co/functions/v1/mivaa-gateway
Backend Service: https://v1api.materialshub.gr
Requests can use either:
// Option 1: Supabase Auth
Authorization: Bearer <supabase_access_token>
// Option 2: MIVAA API Key
X-API-Key: <mivaa_api_key>
Method: POST
Path: /
Request:
{
action: string, // Required - Endpoint action (see available actions below)
payload?: object, // Optional - Request payload
params?: object, // Optional - URL parameters
method?: string // Optional - HTTP method override
}
Response:
{
success: boolean,
data?: any,
error?: string,
metadata?: {
processingTime: number,
endpoint: string
}
}
{
action: 'health_check'
}
{
action: 'kb_create_document',
payload: {
workspace_id: string,
title: string,
content: string,
content_markdown?: string,
summary?: string,
category_id?: string,
seo_keywords?: string[],
status?: 'draft' | 'published' | 'archived',
visibility?: 'workspace' | 'private' | 'public',
metadata?: object,
// Only valid when category is "Pricing". Enables the price_lookup agent tool
// to classify how the doc contributes to a price composition.
price_doc_type?: 'price_list' | 'discount_rule' | 'contract_terms' | 'promotion'
}
}
Upsert semantics (2026-04): when a doc with the same (workspace_id, title, category_id)
already exists, the endpoint updates it in place and only regenerates the embedding if
the content field actually changed. Re-uploading a manufacturer price list with the
same title therefore refreshes the prices without creating duplicates.
{
action: 'kb_update_document',
params: { doc_id: string },
payload: {
title?: string,
content?: string,
content_markdown?: string,
summary?: string,
category_id?: string,
seo_keywords?: string[],
status?: 'draft' | 'published' | 'archived',
visibility?: 'workspace' | 'private' | 'public',
metadata?: object,
price_doc_type?: 'price_list' | 'discount_rule' | 'contract_terms' | 'promotion'
}
}
{
action: 'kb_search',
payload: {
workspace_id: string,
query: string,
search_type?: 'semantic' | 'full_text' | 'hybrid',
limit?: number,
// All filters below are optional (added 2026-04)
category_id?: string,
category_slug?: string, // e.g. "pricing" — restricts to one category
price_doc_type?: 'price_list' | 'discount_rule' | 'contract_terms' | 'promotion',
allowed_access_levels?: ('admin' | 'agent' | 'public')[],
// Admin search defaults to false (drafts included); set true to exclude drafts.
require_published?: boolean,
match_threshold?: number // 0.0-1.0 for semantic, default 0.5
}
}
Each result now includes:
category_slug, category_name — resolved from the joined categoryprice_doc_type — the sub-type when the doc is in the Pricing category{
action: 'search_knowledge_base',
payload: {
query: string,
workspace_id: string,
search_types?: ('chunks' | 'products' | 'entities' | 'kb_docs' | 'images')[],
top_k?: number,
similarity_threshold?: number,
// 'admin' sees all access levels, 'agent' sees agent+public, 'public' sees public only
caller?: 'admin' | 'agent' | 'public',
// NEW 2026-04 — scope the kb_docs portion of the search
category_id?: string,
category_slug?: string,
price_doc_type?: 'price_list' | 'discount_rule' | 'contract_terms' | 'promotion'
}
}
When scoped to category_slug: 'pricing', chunks include price_doc_type,
category_slug, and category_name so the price_lookup agent tool can
classify each match when composing a price.
{
action: 'kb_create_from_pdf',
payload: {
file_url: string,
title?: string,
category_id?: string
}
}
{
action: 'kb_create_category',
payload: {
workspace_id: string,
name: string,
slug?: string, // e.g. "pricing" — used by category filters
description?: string,
icon?: string,
color?: string,
access_level?: 'admin' | 'agent' | 'public',
trigger_keyword?: string // optional gate for agent-level categories
}
}
Creating the "Pricing" category:
{
"action": "kb_create_category",
"payload": {
"workspace_id": "<uuid>",
"name": "Pricing",
"slug": "pricing",
"access_level": "admin",
"trigger_keyword": "price"
}
}
{
action: 'rag_upload',
payload: {
file_url: string,
category?: string,
workspace_id?: string,
title?: string
}
}
{
action: 'rag_search',
payload: {
query: string,
top_k?: number,
strategy?: 'semantic' | 'vector' | 'hybrid' | 'mmr' | 'multimodal' | 'material',
include_metadata?: boolean
}
}
{
action: 'rag_query',
payload: {
query: string,
context_limit?: number,
include_sources?: boolean
}
}
{
action: 'rag_get_job',
params: {
job_id: string
}
}
Use rag_search with a strategy parameter for all search operations. See RAG/Document Processing actions above.
{
action: 'ai_classify_document',
payload: {
document_id: string,
classification_type: string
}
}
{
action: 'ai_detect_boundaries',
payload: {
chunks: Array<object>,
threshold?: number
}
}
{
action: 'ai_validate_product',
payload: {
product_data: object,
validation_rules?: object
}
}
{
action: 'images_analyze',
payload: {
image_url: string,
analysis_type?: 'classification' | 'detection' | 'segmentation'
}
}
{
action: 'images_search',
payload: {
query_image_url: string,
limit?: number
}
}
{
action: 'admin_list_jobs',
payload: {
status?: 'pending' | 'processing' | 'completed' | 'failed',
limit?: number,
offset?: number
}
}
{
action: 'admin_job_statistics'
}
{
action: 'admin_system_health'
}
For file uploads (e.g., PDF processing), use multipart/form-data:
const formData = new FormData();
formData.append('file', fileBlob);
formData.append('category', 'technical-specs');
formData.append('workspace_id', 'workspace-123');
const response = await fetch(
'https://bgbavxtjlbvgplozizxu.supabase.co/functions/v1/mivaa-gateway',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${session.access_token}`
},
body: formData
}
);
{
success: false,
error: string,
statusCode?: number,
details?: object
}
Common Error Codes:
400 - Bad request (invalid action or payload)401 - Unauthorized404 - Endpoint not found500 - Backend service error503 - Service unavailableSee the full list of 100+ available actions in the API Endpoints Documentation.