implemented stateless ant/oai messages/responses apis

This commit is contained in:
Luxferre
2026-08-05 08:33:51 +03:00
parent d734a5cdce
commit 274873f9d3
5 changed files with 1387 additions and 1 deletions
+37 -1
View File
@@ -4,10 +4,13 @@ Dynagate is a lightweight, high-performance LLM gateway written in Go that acts
## Features
1. **OpenAI-compatible endpoints**:
1. **Multi-API Protocol Endpoints (Stateless)**:
- `/v1/models` (GET): Dynamically lists unique active model IDs.
- `/v1/chat/completions` (POST): Proxies non-streaming and streaming (`text/event-stream`) completions.
- `/v1/responses` (POST): Stateless-style OpenAI Responses API endpoint (automatically routed to upstream chat completions endpoints).
- `/v1/messages` (POST): Anthropic-compatible Messages API endpoint (automatically routed to upstream chat completions endpoints).
- `/v1/images/generations` (POST): Proxies image generation requests.
> **Note**: Dynagate operates in a completely stateless manner across all API formats (`/v1/chat/completions`, `/v1/responses`, `/v1/messages`). Dynagate does not store or persist server-side conversation state. Clients must include the full conversation history in each request for multi-turn dialogues.
2. **Zero-downtime live-reloading**:
- Watches `models.csv` (overridable via command-line flags) continuously using a background thread and automatically reloads configuration updates without dropping active connections.
@@ -112,6 +115,15 @@ The gateway maps columns dynamically by looking at the header row. If no header
- **`"-blank-"`**: The gateway will attach exactly `Authorization: Bearer` without any key appended.
- **Any other string**: The gateway will attach `Authorization: Bearer <key>`.
### Stateless Operation & Multi-Turn Conversations
Dynagate is designed as a lightweight, zero-state proxy gateway. All supported request formats (`/v1/chat/completions`, `/v1/responses`, `/v1/messages`) are processed statelessly without storing session context or conversation state on disk or in memory.
To maintain context in multi-turn conversations, clients **must include the entire conversation history** in every request payload:
- **OpenAI Chat Completions (`/v1/chat/completions`)**: Pass the full array of system, user, and assistant messages in `messages`.
- **OpenAI Responses API (`/v1/responses`)**: Pass previous conversation turns in `input` (or `messages`) along with `instructions`.
- **Anthropic Messages API (`/v1/messages`)**: Pass the full history of user and assistant messages in `messages` along with `system`.
### Manual testing with curl
#### 1. Model listing (authenticated)
@@ -142,6 +154,30 @@ curl -i -X POST http://localhost:8080/v1/chat/completions \
}'
```
#### 4. OpenAI-compatible Responses API (`/v1/responses`)
```bash
curl -i -X POST http://localhost:8080/v1/responses \
-H "Authorization: Bearer my-secure-gateway-token" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"instructions": "Be concise",
"input": "Explain relativity in one sentence"
}'
```
#### 5. Anthropic-compatible Messages API (`/v1/messages`)
```bash
curl -i -X POST http://localhost:8080/v1/messages \
-H "Authorization: Bearer my-secure-gateway-token" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet",
"system": "You are a helpful assistant",
"messages": [{"role": "user", "content": "Hello world"}]
}'
```
## Troubleshooting
### Dynamic loading failures