From 15ad765e2c76cbd06ba6262074922acfb80b4267 Mon Sep 17 00:00:00 2001 From: Jethro Lin Date: Mon, 9 Dec 2024 14:42:15 +0800 Subject: [PATCH] add new api doc v2 --- doc/llmapiv2.html | 339 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 doc/llmapiv2.html diff --git a/doc/llmapiv2.html b/doc/llmapiv2.html new file mode 100644 index 0000000..587bc50 --- /dev/null +++ b/doc/llmapiv2.html @@ -0,0 +1,339 @@ + + + + + + LLM API Documentation v2 + + + +

LLM API Documentation v2

+ +

Overview

+

This document describes the API endpoints for the LLM service.

+ +

Base URL

+
https://llmbackend.local:7890
+ +

Authentication

+ + +

Required Headers

+

All API requests must include:

+
Content-Type: application/json
+Accept: application/json
+X-API-Version: 1.0
+X-Client-ID: your-client-id
+ +

Endpoints

+ +

Public Routes

+ +
+

GET /

+

Root endpoint that returns the API status.

+
Response:
+
{
+    "success": true,
+    "data": {
+        "status": "ok",
+        "version": "1.0"
+    }
+}
+
+ +
+

GET /api/test

+

Simple test endpoint to verify API connectivity.

+
+ +
+

POST /api/auth/token

+

Exchange auth token for an access token.

+
Request Body:
+
{
+    "auth_token": "64-character-auth-token"
+}
+
Response:
+
{
+    "success": true,
+    "data": {
+        "access_token": "generated-access-token",
+        "expires_in": 3600
+    }
+}
+
+ +

Protected Client Routes

+ +
+

POST /api/llm/request

+

Make a request to the LLM service.

+
Headers:
+
Authorization: Bearer {access_token}
+
Request Body:
+
{
+    "prompt": "Your prompt text here",
+    "max_tokens": 100,
+    "temperature": 0.7,
+    "top_p": 1,
+    "frequency_penalty": 0,
+    "presence_penalty": 0
+}
+
Response:
+
{
+    "success": true,
+    "data": {
+        "response": "LLM generated response"
+    }
+}
+
+ +

Admin Authentication

+ +
+

POST /api/admin/login

+
Request Body:
+
{
+    "email": "your-email",
+    "password": "your-password"
+}
+
Response:
+
{
+    "success": true,
+    "data": {
+        "token": "admin-bearer-token",
+        "admin": {
+            "id": 1,
+            "email": "your-email"
+        }
+    }
+}
+
+ +
+

POST /api/admin/logout

+
Headers:
+
Authorization: Bearer {admin_token}
+
+ +
+

PUT /api/admin/change-password

+
Headers:
+
Authorization: Bearer {admin_token}
+
Request Body:
+
{
+    "current_password": "current-password",
+    "new_password": "new-password",
+    "new_password_confirmation": "new-password"
+}
+
+ +

Client Management

+ +
+

GET /api/admin/clients

+
Headers:
+
Authorization: Bearer {admin_token}
+
Response:
+
{
+    "success": true,
+    "data": {
+        "items": [
+            {
+                "id": 1,
+                "name": "Client Name",
+                "llm_provider_id": 1,
+                "created_at": "2024-12-05T00:00:00Z"
+            }
+        ]
+    }
+}
+
+ +
+

POST /api/admin/clients

+
Headers:
+
Authorization: Bearer {admin_token}
+
Request Body:
+
{
+    "name": "New Client Name",
+    "llm_provider_id": 1
+}
+
+ +
+

GET /api/admin/clients/{client_id}

+
Headers:
+
Authorization: Bearer {admin_token}
+
+ +
+

PUT /api/admin/clients/{client_id}

+
Headers:
+
Authorization: Bearer {admin_token}
+
Request Body:
+
{
+    "name": "Updated Client Name",
+    "llm_provider_id": 1
+}
+
+ +
+

DELETE /api/admin/clients/{client_id}

+
Headers:
+
Authorization: Bearer {admin_token}
+
+ +
+

POST /api/admin/clients/{client_id}/auth-token

+
Headers:
+
Authorization: Bearer {admin_token}
+
Response:
+
{
+    "success": true,
+    "data": {
+        "client_id": 1,
+        "auth_token": "generated-auth-token",
+        "created_at": "2024-12-05T00:00:00Z"
+    }
+}
+
+ +

LLM Provider Management

+ +
+

GET /api/admin/llm-providers

+
Headers:
+
Authorization: Bearer {admin_token}
+
Response:
+
{
+    "success": true,
+    "data": {
+        "items": [
+            {
+                "id": 1,
+                "name": "OpenAI",
+                "service_name": "openai",
+                "api_url": "https://api.openai.com/v1",
+                "status": "active",
+                "created_at": "2024-12-05T00:00:00Z"
+            }
+        ]
+    }
+}
+
+ +
+

POST /api/admin/llm-providers

+
Headers:
+
Authorization: Bearer {admin_token}
+
Request Body:
+
{
+    "name": "OpenAI",
+    "service_name": "openai",
+    "api_url": "https://api.openai.com/v1",
+    "api_token": "your-api-token",
+    "status": "active"
+}
+
+ +
+

GET /api/admin/llm-providers/{provider_id}

+
Headers:
+
Authorization: Bearer {admin_token}
+
+ +
+

PUT /api/admin/llm-providers/{provider_id}

+
Headers:
+
Authorization: Bearer {admin_token}
+
Request Body:
+
{
+    "name": "Updated OpenAI",
+    "service_name": "openai",
+    "api_url": "https://api.openai.com/v1",
+    "api_token": "your-api-token",
+    "status": "active"
+}
+
+ +
+

DELETE /api/admin/llm-providers/{provider_id}

+
Headers:
+
Authorization: Bearer {admin_token}
+
+ +

Error Responses

+

All endpoints return standardized error responses:

+
{
+    "success": false,
+    "error": "error_code",
+    "message": "Error message",
+    "errors": {
+        "field": ["Error details"]
+    }
+}
+ +

Success Responses

+

All successful responses follow the format:

+
{
+    "success": true,
+    "data": {
+        // Response data
+    }
+}
+ +