File size: 4,270 Bytes
dd651c4
 
bb4ddbd
dd651c4
1d3620d
dd651c4
bb4ddbd
 
 
dd651c4
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
bb4ddbd
dd651c4
 
 
 
 
 
 
 
bb4ddbd
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
from fastapi import APIRouter
from typing import List, Dict, Any
from ..core.config import settings

router = APIRouter(prefix="/docs", tags=["Documentation"])

def get_api_info():
    token = settings.token or "ACCESS2026"
    return {
    "title": "OpenCode API Documentation",
    "description": "Human-readable summary of available endpoints, their jobs, and how to interact with them.",
    "auth": {
        "type": "Bearer Token",
        "header": f"Authorization: Bearer {token}",
        "description": "Most endpoints require this token for access."
    },
    "endpoints": [
        {
            "path": "/health",
            "method": "GET",
            "job": "Check system health and status.",
            "interaction": "Send a GET request. No auth required.",
            "example": "curl https://auxteam-opencode-api.hf.space/health"
        },
        {
            "path": "/provider",
            "method": "GET",
            "job": "List available LLM providers (e.g., blablador, openai, anthropic).",
            "interaction": "Send GET request with Bearer token.",
            "example": f"curl -H 'Authorization: Bearer {token}' https://auxteam-opencode-api.hf.space/provider"
        },
        {
            "path": "/session",
            "method": "POST",
            "job": "Create a new chat session.",
            "interaction": "Send POST request. Optional JSON body: {'title': 'My Session', 'model_id': 'alias-large'}.",
            "example": f"curl -X POST -H 'Authorization: Bearer {token}' https://auxteam-opencode-api.hf.space/session"
        },
        {
            "path": "/session",
            "method": "GET",
            "job": "List all active chat sessions.",
            "interaction": "Send GET request with Bearer token.",
            "example": f"curl -H 'Authorization: Bearer {token}' https://auxteam-opencode-api.hf.space/session"
        },
        {
            "path": "/session/{session_id}/message",
            "method": "POST",
            "job": "Send a message to the agent and receive a streaming response.",
            "interaction": "Send POST request with JSON body. Returns Server-Sent Events (SSE).",
            "payload": {
                "content": "Message string (required)",
                "model_id": "Optional model ID (defaults to alias-large)",
                "system": "Optional system prompt override"
            },
            "example": f"curl -X POST -H 'Authorization: Bearer {token}' -H 'Content-Type: application/json' -d '{{\"content\": \"Hi\"}}' https://auxteam-opencode-api.hf.space/session/{{id}}/message"
        },
        {
            "path": "/session/{session_id}/abort",
            "method": "POST",
            "job": "Cancel an ongoing message generation.",
            "interaction": "Send POST request with Bearer token.",
            "example": f"curl -X POST -H 'Authorization: Bearer {token}' https://auxteam-opencode-api.hf.space/session/{{id}}/abort"
        },
        {
            "path": "/question",
            "method": "GET",
            "job": "List questions waiting for user input (used by QuestionTool).",
            "interaction": "Send GET request. Returns list of pending question requests.",
            "example": f"curl -H 'Authorization: Bearer {token}' https://auxteam-opencode-api.hf.space/question"
        },
        {
            "path": "/question/{request_id}/reply",
            "method": "POST",
            "job": "Answer a pending question from the agent.",
            "interaction": "Send POST request with JSON body: {'answers': [['Label1'], ['Label2']]}.",
            "example": f"curl -X POST -H 'Authorization: Bearer {token}' -H 'Content-Type: application/json' -d '{{\"answers\": [[\"Yes\"]]}}' https://auxteam-opencode-api.hf.space/question/{{id}}/reply"
        },
        {
            "path": "/agent",
            "method": "GET",
            "job": "List available agent configurations.",
            "interaction": "Send GET request.",
            "example": f"curl -H 'Authorization: Bearer {token}' https://auxteam-opencode-api.hf.space/agent"
        }
    ]
}

@router.get("")
@router.get("/")
async def get_api_docs():
    """Return a human-readable summary of the API."""
    return get_api_info()