selfapi-v2 / HOWTOUSE.md
akashyadav758
Harden monitor (gate all routes), swap ChatGPT backend to free-Chatgpt-api, clean repo
5c7f4b5
|
Raw
History Blame Contribute Delete
3.62 kB
# How to use the API
One base URL fronts all three services. Every `/gpt`, `/gemini`, `/flow` call needs the
`API_KEY` as a Bearer token. The monitor UI (`/`) needs no key.
- **Base URL:** `https://akash1313-selfapi-v2.hf.space`
- **Auth header:** `Authorization: Bearer YOUR_API_KEY` *(your real key is in the gitignored `./api-key`)*
> ⚠️ **You must be logged in** to ChatGPT / Gemini / Flow inside the browser
> (`https://akash1313-selfapi-v2.hf.space/`) for real responses. The servers reply even when
> logged out, but with `extensionConnected:false` / empty data. Check first:
> ```bash
> curl -H "Authorization: Bearer YOUR_API_KEY" https://akash1313-selfapi-v2.hf.space/gpt/health
> ```
> `extensionConnected:true` = ready.
---
## ChatGPT β€” `/gpt`
| Endpoint | Method | Body |
|----------|--------|------|
| `/gpt/health` | GET | β€” |
| `/gpt/api/chat` | POST | `{"prompt": "...", "wait_for_response": true}` |
| `/gpt/api/chat/bulk` | POST | `{"prompts": ["...","..."], "delay_seconds": 2}` |
| `/gpt/v1/chat/completions` | POST | OpenAI-compatible (see below) |
```bash
# Simple chat
curl -X POST https://akash1313-selfapi-v2.hf.space/gpt/api/chat \
-H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{"prompt":"Write a haiku about the sea","wait_for_response":true}'
# OpenAI-compatible (drop-in for OpenAI SDKs β€” set base_url=.../gpt/v1)
curl -X POST https://akash1313-selfapi-v2.hf.space/gpt/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{"model":"gpt-5","messages":[{"role":"user","content":"hello"}],"stream":false}'
```
Optional fields: `"model"`, `"thinking_effort"`, `"conversation_id"` (continue a thread).
---
## Gemini β€” `/gemini` (form-encoded, not JSON)
| Endpoint | Method | Body |
|----------|--------|------|
| `/gemini/status` | GET | β€” |
| `/gemini/chat` | POST (form) | `prompt`, `user_id`, `new_chat`, `stream` |
| `/gemini/music` | POST (form) | `prompt` |
| `/gemini/reset` | POST | β€” |
| `/gemini/output/<file>` | GET | β€” (generated media) |
```bash
curl -X POST https://akash1313-selfapi-v2.hf.space/gemini/chat \
-H "Authorization: Bearer YOUR_API_KEY" \
-d "prompt=Explain quantum entanglement simply&new_chat=true"
```
---
## Flow (video / image) β€” `/flow` (JSON)
| Endpoint | Method | Body |
|----------|--------|------|
| `/flow/health` | GET | β€” |
| `/flow/generate/video` | POST | `{"prompt":"...","aspect":"portrait","duration":10,"count":1}` |
| `/flow/generate/image` | POST | `{"prompt":"...","aspect":"portrait","count":1}` |
| `/flow/upload/image` Β· `/flow/upload/video` | POST | multipart file |
| `/flow/download/<filename>` | GET | β€” |
```bash
# Text-to-video (aspect: portrait|landscape ; duration: 4,6,8,10)
curl -X POST https://akash1313-selfapi-v2.hf.space/flow/generate/video \
-H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{"prompt":"a cat surfing a wave, cinematic","aspect":"landscape","duration":8}'
# Text-to-image
curl -X POST https://akash1313-selfapi-v2.hf.space/flow/generate/image \
-H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{"prompt":"neon city at night","aspect":"square"}'
```
---
## Auth errors
| Code | Meaning |
|------|---------|
| `401` | Missing/wrong key |
| `503` | `API_KEY` not set on the server (gateway disabled, fail-closed) |
| `502` | Backend server not reachable (still booting / crashed β€” check `/chrome.log`) |
Rotate the key anytime: change the `API_KEY` secret in the Space settings (auto-restarts).