Spaces:
Running
Running
File size: 15,793 Bytes
80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 80e0598 550ed76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# AI SBOM Generator API Documentation
## Overview
The AI SBOM Generator API provides a comprehensive solution for generating CycloneDX-compliant AI Software Bill of Materials (AI SBOM) for Hugging Face models. This API uses a configurable field registry system to extract and score AI SBOM fields across 5 categories, providing detailed completeness assessment and standards compliance.
---
## Table of Contents
- [Base URL](#base-url)
- [API Endpoints](#api-endpoints)
- [API Status](#api-status)
- [Registry Status](#registry-status)
- [Generate AI SBOM](#generate-ai-sbom)
- [Generate AI SBOM with Completeness Score Report](#generate-ai-sbom-with-completeness-score-report)
- [Get Completeness Score Only](#get-completeness-score-only)
- [Download Generated AI SBOM](#download-generated-ai-sbom)
- [Form-Based Generation (Web UI)](#form-based-generation-web-ui)
- [Web UI](#web-ui)
- [Security Features](#security-features)
- [Field Registry System](#field-registry-system)
- [Completeness Score](#completeness-score)
- [Notes on Using the API](#notes-on-using-the-api)
- [Error Handling](#error-handling)
---
## Base URL
When deployed on Hugging Face Spaces, the base URL will be:
```
https://aetheris-ai-aibom-generator.hf.space
```
Replace this with your actual deployment URL.
---
## API Endpoints
### API Status
**Purpose**: Check if the API is operational and get version information.
**Endpoint**: `/status`
**Method**: GET
**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/status"
```
**Expected Response**:
```json
{
"status": "operational",
"version": "1.0.0",
"generator_version": "1.0.0"
}
```
---
### Registry Status
**Purpose**: Check the field registry configuration status and available fields.
**Endpoint**: `/api/registry/status`
**Method**: GET
**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/api/registry/status"
```
**Expected Response**:
```json
{
"registry_available": true,
"total_fields": 29,
"categories": [
"required_fields",
"metadata",
"component_basic",
"component_model_card",
"external_references"
],
"field_count_by_category": {
"required_fields": 4,
"metadata": 5,
"component_basic": 5,
"component_model_card": 14,
"external_references": 1
},
"registry_manager_loaded": true
}
```
---
### Generate AI SBOM
**Purpose**: Generate an AI SBOM for a specified Hugging Face model.
**Endpoint**: `/api/generate`
**Method**: POST
**Parameters**:
- `model_id` (required): The Hugging Face model ID (e.g., 'meta-llama/Llama-2-7b-chat-hf')
- `include_inference` (optional): Whether to use AI inference to enhance the AI SBOM (default: true)
- `use_best_practices` (optional): Whether to use industry best practices for scoring (default: true)
- `hf_token` (optional): Hugging Face API token for accessing private models
**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/generate" \
-H "Content-Type: application/json" \
-d '{
"model_id": "deepseek-ai/DeepSeek-R1",
"include_inference": true,
"use_best_practices": true
}'
```
**Expected Response**: JSON containing the generated AI SBOM, model ID, timestamp, and download URL.
```json
{
"aibom": {
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:deepseek-ai-DeepSeek-R1",
"version": "1.0.0",
"metadata": {
"timestamp": "2025-07-15T18:31:18Z",
"tools": [
{
"vendor": "Aetheris AI",
"name": "AI SBOM Generator",
"version": "1.0.0"
}
],
"properties": [
{
"name": "primaryPurpose",
"value": "text-generation"
},
{
"name": "suppliedBy",
"value": "deepseek-ai"
}
]
},
"components": [
{
"type": "machine-learning-model",
"name": "DeepSeek-R1",
"purl": "pkg:huggingface/deepseek-ai/DeepSeek-R1",
"description": "Advanced reasoning model with enhanced capabilities",
"licenses": [
{
"license": {
"name": "DeepSeek License"
}
}
],
"modelCard": {
"limitation": "Model may have limitations in certain domains"
}
}
],
"externalReferences": [
{
"type": "distribution",
"url": "https://huggingface.co/deepseek-ai/DeepSeek-R1"
}
]
},
"model_id": "deepseek-ai/DeepSeek-R1",
"generated_at": "2025-07-15T18:31:18Z",
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"download_url": "/output/deepseek-ai_DeepSeek-R1_ai_sbom.json"
}
```
---
### Generate AI SBOM with Completeness Score Report
**Purpose**: Generate an AI SBOM along with a detailed completeness score report.
**Endpoint**: `/api/generate-with-report`
**Method**: POST
**Parameters**: Same as Generate AI SBOM
**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/generate-with-report" \
-H "Content-Type: application/json" \
-d '{
"model_id": "deepseek-ai/DeepSeek-R1",
"include_inference": true,
"use_best_practices": true
}'
```
**Expected Response**: Same as Generate AI SBOM plus completeness score details.
```json
{
"aibom": { ... },
"model_id": "deepseek-ai/DeepSeek-R1",
"generated_at": "2025-07-15T18:31:18Z",
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"download_url": "/output/deepseek-ai_DeepSeek-R1_ai_sbom.json",
"completeness_score": {
"total_score": 62.3,
"section_scores": {
"required_fields": 20.0,
"metadata": 8.0,
"component_basic": 20.0,
"component_model_card": 4.3,
"external_references": 10.0
},
"max_scores": {
"required_fields": 20,
"metadata": 20,
"component_basic": 20,
"component_model_card": 30,
"external_references": 10
},
"field_checklist": {
"bomFormat": "present",
"specVersion": "present",
"serialNumber": "present",
"version": "present",
"primaryPurpose": "present",
"suppliedBy": "present",
"standardCompliance": "missing",
"domain": "missing",
"autonomyType": "missing",
"name": "present",
"type": "present",
"purl": "present",
"description": "present",
"licenses": "present",
"energyConsumption": "missing",
"hyperparameter": "missing",
"limitation": "present",
"safetyRiskAssessment": "missing",
"typeOfModel": "present",
"modelExplainability": "missing",
"energyQuantity": "missing",
"energyUnit": "missing",
"informationAboutTraining": "missing",
"informationAboutApplication": "missing",
"metric": "missing",
"metricDecisionThreshold": "missing",
"modelDataPreprocessing": "missing",
"useSensitivePersonalInformation": "missing",
"downloadLocation": "present"
},
"category_details": {
"required_fields": {
"present_fields": 4,
"total_fields": 4,
"percentage": 100.0
},
"metadata": {
"present_fields": 2,
"total_fields": 5,
"percentage": 40.0
},
"component_basic": {
"present_fields": 5,
"total_fields": 5,
"percentage": 100.0
},
"component_model_card": {
"present_fields": 2,
"total_fields": 14,
"percentage": 14.3
},
"external_references": {
"present_fields": 1,
"total_fields": 1,
"percentage": 100.0
}
}
}
}
```
---
### Get Completeness Score Only
**Purpose**: Get the completeness score for a model without generating a full AI SBOM.
**Endpoint**: `/api/models/{model_id}/score`
**Method**: GET
**Parameters**:
- `model_id` (path parameter): The Hugging Face model ID
- `use_best_practices` (query parameter, optional): Whether to use industry best practices for scoring (default: true)
- `hf_token` (query parameter, optional): Hugging Face API token for accessing private models
**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/api/models/deepseek-ai/DeepSeek-R1/score?use_best_practices=true"
```
**Expected Response**:
```json
{
"model_id": "deepseek-ai/DeepSeek-R1",
"total_score": 62.3,
"section_scores": {
"required_fields": 20.0,
"metadata": 8.0,
"component_basic": 20.0,
"component_model_card": 4.3,
"external_references": 10.0
},
"max_scores": {
"required_fields": 20,
"metadata": 20,
"component_basic": 20,
"component_model_card": 30,
"external_references": 10
},
"field_checklist": {
"bomFormat": "present",
"specVersion": "present",
"name": "present",
"downloadLocation": "present"
},
"generated_at": "2025-07-15T18:31:18Z",
"request_id": "550e8400-e29b-41d4-a716-446655440000"
}
```
---
### Download Generated AI SBOM
**Purpose**: Download a previously generated AI SBOM file.
**Endpoint**: `/output/{filename}`
**Method**: GET
**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/output/deepseek-ai_DeepSeek-R1_ai_sbom.json" \
-o "deepseek_r1_aibom.json"
```
---
### Form-Based Generation (Web UI)
**Purpose**: Generate AI SBOM through the web interface form submission.
**Endpoint**: `/generate`
**Method**: POST
**Content-Type**: `application/x-www-form-urlencoded`
**Parameters**:
- `model_id` (required): The Hugging Face model ID
- `g-recaptcha-response` (required): reCAPTCHA response token
**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/generate" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "model_id=deepseek-ai/DeepSeek-R1&g-recaptcha-response=YOUR_RECAPTCHA_TOKEN"
```
---
## Web UI
The API also provides a user-friendly web interface accessible at the base URL. The web UI includes:
- **Model ID input field** with validation
- **reCAPTCHA protection** against automated abuse
- **Real-time generation** with progress indicators
- **Downloadable results** with completeness scoring
- **Field checklist visualization** showing extraction results
- **Category-based scoring breakdown**
---
## Security Features
### Rate Limiting
- **10 requests per minute** per IP address
- **5 concurrent requests** maximum
- **1MB request size limit**
### reCAPTCHA Protection
- **Google reCAPTCHA v2** integration for web UI
- **Automated bot detection** and prevention
- **Configurable through environment variables**
### Input Validation
- **Model ID format validation** (alphanumeric, hyphens, underscores, forward slashes)
- **XSS protection** through HTML escaping
- **SQL injection prevention** through parameterized queries
---
## Field Registry System
The AI SBOM Generator uses a configurable field registry system that enables:
### **29 Configurable Fields** across 5 categories:
- **Required Fields (4)**: bomFormat, specVersion, serialNumber, version
- **Metadata (5)**: primaryPurpose, suppliedBy, standardCompliance, domain, autonomyType
- **Component Basic (5)**: name, type, purl, description, licenses
- **Component Model Card (14)**: energyConsumption, hyperparameter, limitation, safetyRiskAssessment, typeOfModel, modelExplainability, energyQuantity, energyUnit, informationAboutTraining, informationAboutApplication, metric, metricDecisionThreshold, modelDataPreprocessing, useSensitivePersonalInformation
- **External References (1)**: downloadLocation
### **Multi-Strategy Extraction**:
1. **HuggingFace API** β Direct metadata extraction (High confidence)
2. **Model Card** β Structured documentation parsing (Medium-high confidence)
3. **Config Files** β Technical details from JSON files (High confidence)
4. **Text Patterns** β Regex extraction from README (Medium confidence)
5. **Intelligent Inference** β Smart defaults from context (Medium confidence)
6. **Fallback Values** β Placeholders when no data available (Low confidence)
### **SPDX 3.0 Compatibility**:
- **100% field coverage** with SPDX 3.0 AI Profile specification
- **59% exact field name matches** with official SPDX 3.0 fields
- **Future dual-format support** for both CycloneDX and SPDX output
- **Current limitation** does not generate output in SPDX format
---
## Completeness Score
The completeness score is calculated using a weighted scoring system across five categories:
### **Scoring Categories**:
- **Required Fields (20%)**: Essential CycloneDX infrastructure
- **Metadata (20%)**: AI-specific metadata and provenance
- **Component Basic (20%)**: Core component identification
- **Component Model Card (30%)**: Advanced AI model documentation
- **External References (10%)**: Distribution and reference links
### **Field Tiers**:
- **Critical (C)**: Essential fields with 3x weight multiplier
- **Important (I)**: Valuable fields with 2x weight multiplier
- **Supplementary (S)**: Additional fields with 1x weight multiplier
### **Score Interpretation**:
- **90-100**: Exceptional documentation quality
- **80-89**: Comprehensive documentation
- **70-79**: Good documentation with minor gaps
- **60-69**: Adequate documentation with some missing elements
- **50-59**: Basic documentation with significant gaps
- **Below 50**: Insufficient documentation
### **Confidence-Based Filtering**:
- Only fields extracted with **medium** or **high** confidence contribute to the score
- **Low** or **none** confidence extractions are excluded to ensure score reliability
- Individual field failures don't prevent overall SBOM generation
---
## Notes on Using the API
### **Model ID Format**
- Use the exact Hugging Face model identifier (e.g., `meta-llama/Llama-2-7b-chat-hf`)
- Model IDs are case-sensitive
- Private models require a valid `hf_token`
### **Response Times**
- **Simple models**: 5-15 seconds
- **Complex models with inference**: 30-60 seconds
- **Large models**: Up to 2 minutes
### **File Storage**
- Generated AI SBOMs are stored temporarily (7 days)
- Download URLs are valid for the file retention period
- Files are automatically cleaned up to manage storage
### **Best Practices**
- Use `use_best_practices=true` for industry-standard scoring
- Include `include_inference=true` for enhanced field extraction
- Cache results locally to avoid repeated API calls for the same model
- Use the registry status endpoint to verify system configuration
---
## Error Handling
### **Common HTTP Status Codes**:
- **200 OK**: Successful request
- **400 Bad Request**: Invalid model ID format or missing parameters
- **404 Not Found**: Model not found on Hugging Face
- **429 Too Many Requests**: Rate limit exceeded
- **500 Internal Server Error**: Server-side processing error
### **Error Response Format**:
```json
{
"detail": "Error description",
"error_code": "SPECIFIC_ERROR_CODE",
"timestamp": "2025-07-15T18:31:18Z"
}
```
### **Common Error Scenarios**:
- **Invalid Model ID**: Check format and existence on Hugging Face
- **Private Model Access**: Ensure valid `hf_token` is provided
- **Rate Limiting**: Wait before retrying or implement exponential backoff
- **Registry Unavailable**: System falls back to basic field extraction
---
## Support and Documentation
For additional support, documentation updates, or feature requests:
- **GitHub Repository**: [[Link to GitHub Isuses](https://github.com/aetheris-ai/aibom-generator/issues)]
- **API Status Page**: Use `/status` and `/api/registry/status` endpoints
- **Web Interface**: Available at the base URL for interactive testing
This API provides comprehensive AI SBOM generation capabilities with industry-leading field coverage, standards compliance, and configurable scoring systems.
|