@@ -537,10 +537,357 @@ curl http://localhost:8000/ai/version | jq
537537}
538538```
539539
540+ ## Usage Analytics
541+
542+ ### GET `/ai/usage/stats`
543+
544+ !!! note
545+ Requires database backend (`ai[sqlite]` or `ai[postgres]`). Not available with in-memory backend.
546+
547+ Get usage statistics with token counts, costs, and model breakdown.
548+
549+ **Query Parameters:**
550+
551+ | Parameter | Type | Required | Default | Description |
552+ |-----------|------|----------|---------|-------------|
553+ | `user_id` | string | No | all users | Filter by user |
554+ | `start_time` | datetime | No | all time | Start of time range |
555+ | `end_time` | datetime | No | now | End of time range |
556+ | `recent_limit` | integer | No | 10 | Number of recent activities |
557+
558+ **Response:**
559+
560+ ```json
561+ {
562+ "total_tokens": 45230,
563+ "input_tokens": 32100,
564+ "output_tokens": 13130,
565+ "total_cost": 0.47,
566+ "total_requests": 23,
567+ "success_rate": 95.6,
568+ "models": [
569+ {
570+ "model_id": "gpt-4o",
571+ "vendor": "OpenAI",
572+ "requests": 15,
573+ "tokens": 30000,
574+ "cost": 0.35,
575+ "percentage": 65.2
576+ }
577+ ],
578+ "recent_activity": [
579+ {
580+ "timestamp": "2024-01-15T10:30:00Z",
581+ "model": "gpt-4o",
582+ "input_tokens": 1500,
583+ "output_tokens": 800,
584+ "cost": 0.02,
585+ "success": true,
586+ "action": "chat"
587+ }
588+ ]
589+ }
590+ ```
591+
592+ **Example:**
593+
594+ ```bash
595+ # All-time stats
596+ curl http://localhost:8000/ai/usage/stats | jq
597+
598+ # Per-user stats
599+ curl "http://localhost:8000/ai/usage/stats?user_id=my-user"
600+
601+ # Time-range query
602+ curl "http://localhost:8000/ai/usage/stats?start_time=2024-01-01T00:00:00Z&recent_limit=20"
603+ ```
604+
605+ ---
606+
607+ ## LLM Catalog Endpoints
608+
609+ All LLM catalog endpoints are prefixed with `/llm`. See [LLM Catalog](llm-catalog.md) for full documentation.
610+
611+ ### GET `/llm/status`
612+
613+ Get catalog statistics.
614+
615+ ```json
616+ {
617+ "vendor_count": 32,
618+ "model_count": 1847,
619+ "deployment_count": 2103,
620+ "price_count": 1952,
621+ "top_vendors": [
622+ {"name": "OpenAI", "model_count": 156},
623+ {"name": "Google", "model_count": 89}
624+ ]
625+ }
626+ ```
627+
628+ ### GET `/llm/vendors`
629+
630+ List all vendors with model counts.
631+
632+ ```bash
633+ curl http://localhost:8000/llm/vendors | jq
634+ ```
635+
636+ ### GET `/llm/modalities`
637+
638+ List modalities (text, image, audio, video) with model counts.
639+
640+ ### GET `/llm/models`
641+
642+ Search and filter models.
643+
644+ **Query Parameters:**
645+
646+ | Parameter | Type | Default | Description |
647+ |-----------|------|---------|-------------|
648+ | `pattern` | string | null | Search pattern for model ID/title |
649+ | `vendor` | string | null | Filter by vendor name |
650+ | `modality` | string | null | Filter by modality |
651+ | `limit` | integer | 50 | Max results (1-200) |
652+ | `include_disabled` | boolean | false | Include disabled models |
653+
654+ ```bash
655+ # Search models
656+ curl "http://localhost:8000/llm/models?pattern=gpt-4&vendor=openai"
657+
658+ # Filter by modality
659+ curl "http://localhost:8000/llm/models?modality=image&limit=20"
660+ ```
661+
662+ **Response:**
663+
664+ ```json
665+ [
666+ {
667+ "model_id": "gpt-4o",
668+ "vendor": "OpenAI",
669+ "context_window": 128000,
670+ "input_price": 2.50,
671+ "output_price": 10.00,
672+ "released_on": "2024-05-13"
673+ }
674+ ]
675+ ```
676+
677+ ### GET `/llm/current`
678+
679+ Get current active LLM configuration enriched with catalog data.
680+
681+ ```json
682+ {
683+ "provider": "openai",
684+ "model": "gpt-4o",
685+ "temperature": 0.7,
686+ "max_tokens": 1000,
687+ "context_window": 128000,
688+ "input_price": 2.50,
689+ "output_price": 10.00,
690+ "modalities": ["text", "image"]
691+ }
692+ ```
693+
694+ ---
695+
696+ ## RAG Endpoints
697+
698+ All RAG endpoints are prefixed with `/rag`. See [RAG](rag.md) for full documentation.
699+
700+ ### POST `/rag/index`
701+
702+ Index documents from a path.
703+
704+ **Request:**
705+
706+ ```json
707+ {
708+ "path": "./app",
709+ "collection_name": "code",
710+ "extensions": [".py", ".ts"],
711+ "exclude_patterns": ["**/test_*"]
712+ }
713+ ```
714+
715+ **Response:**
716+
717+ ```json
718+ {
719+ "collection_name": "code",
720+ "documents_added": 1523,
721+ "total_documents": 1523,
722+ "duration_ms": 8300.5
723+ }
724+ ```
725+
726+ ### POST `/rag/search`
727+
728+ Semantic search across indexed documents.
729+
730+ **Request:**
731+
732+ ```json
733+ {
734+ "query": "how does authentication work",
735+ "collection_name": "code",
736+ "top_k": 5,
737+ "filter_metadata": null
738+ }
739+ ```
740+
741+ **Response:**
742+
743+ ```json
744+ {
745+ "query": "how does authentication work",
746+ "collection_name": "code",
747+ "results": [
748+ {
749+ "content": "class AuthService:\n ...",
750+ "metadata": {"source": "app/services/auth/service.py", "file_name": "service.py"},
751+ "score": 0.8932,
752+ "rank": 1
753+ }
754+ ],
755+ "result_count": 5
756+ }
757+ ```
758+
759+ ### GET `/rag/collections`
760+
761+ List all collection names.
762+
763+ ### GET `/rag/collections/{name}`
764+
765+ Get collection info (name, document count, metadata).
766+
767+ ### GET `/rag/collections/{name}/files`
768+
769+ List indexed files with chunk counts.
770+
771+ ```json
772+ {
773+ "collection_name": "code",
774+ "files": [
775+ {"source": "app/services/ai/service.py", "chunks": 45},
776+ {"source": "app/services/auth/service.py", "chunks": 23}
777+ ],
778+ "total_files": 87,
779+ "total_chunks": 1523
780+ }
781+ ```
782+
783+ ### DELETE `/rag/collections/{name}`
784+
785+ Delete a collection and all its documents.
786+
787+ ### GET `/rag/health`
788+
789+ RAG service health status including configuration and validation.
790+
791+ ---
792+
793+ ## Voice Endpoints
794+
795+ All voice endpoints are prefixed with `/voice`. See [Voice](voice.md) for full documentation.
796+
797+ ### TTS Catalog
798+
799+ | Endpoint | Description |
800+ |----------|-------------|
801+ | `GET /voice/catalog/tts/providers` | List TTS providers |
802+ | `GET /voice/catalog/tts/{provider_id}/models` | List models for provider |
803+ | `GET /voice/catalog/tts/{provider_id}/voices` | List voices for provider |
804+
805+ ### STT Catalog
806+
807+ | Endpoint | Description |
808+ |----------|-------------|
809+ | `GET /voice/catalog/stt/providers` | List STT providers |
810+ | `GET /voice/catalog/stt/{provider_id}/models` | List STT models |
811+
812+ ### Settings & Preview
813+
814+ | Endpoint | Description |
815+ |----------|-------------|
816+ | `GET /voice/settings` | Get current voice settings |
817+ | `POST /voice/settings` | Update voice settings |
818+ | `POST /voice/preview` | Generate voice preview (returns audio/mpeg) |
819+ | `GET /voice/preview/{voice_id}` | Browser-friendly voice preview |
820+ | `GET /voice/catalog/summary` | Full catalog summary |
821+
822+ ---
823+
824+ ## Error Handling
825+
826+ ### HTTP Status Codes
827+
828+ | Status | Description |
829+ |--------|-------------|
830+ | 200 | Success |
831+ | 400 | Bad request (invalid conversation_id, missing required fields) |
832+ | 403 | Forbidden (conversation access denied) |
833+ | 404 | Not found (conversation/collection doesn' t exist) |
834+ | 502 | Bad gateway (AI provider error) |
835+ | 503 | Service unavailable (AI service disabled or misconfigured) |
836+ | 500 | Internal server error |
837+
838+ # ## Error Response Format
839+
840+ ` ` ` json
841+ {
842+ " detail" : " Error message description"
843+ }
844+ ` ` `
845+
846+ # ## Common Errors
847+
848+ ** AI Service Disabled:**
849+ ` ` ` json
850+ {
851+ " detail" : " AI service error: AI service is disabled"
852+ }
853+ ` ` `
854+
855+ ** Missing API Key:**
856+ ` ` ` json
857+ {
858+ " detail" : " AI service error: Missing API key for openai provider. Set OPENAI_API_KEY environment variable."
859+ }
860+ ` ` `
861+
862+ ** Provider Error:**
863+ ` ` ` json
864+ {
865+ " detail" : " AI provider error: Rate limit exceeded"
866+ }
867+ ` ` `
868+
869+ ** Conversation Not Found:**
870+ ` ` ` json
871+ {
872+ " detail" : " Conversation error: Conversation abc-123 not found"
873+ }
874+ ` ` `
875+
876+ ** Collection Not Found:**
877+ ` ` ` json
878+ {
879+ " detail" : " Collection 'my-collection' not found"
880+ }
881+ ` ` `
882+
540883---
541884
542885** Next Steps:**
543886
887+ - ** [LLM Catalog](llm-catalog.md)** - Full catalog documentation
888+ - ** [RAG](rag.md)** - Full RAG documentation
889+ - ** [Cost Tracking](cost-tracking.md)** - Usage analytics
890+ - ** [Voice](voice.md)** - Voice capabilities
544891- ** [Service Layer](integration.md)** - Integration patterns and architecture
545892- ** [CLI Commands](cli.md)** - Command-line interface reference
546893- ** [Examples](examples.md)** - Real-world usage patterns
0 commit comments