TikHub Streaming AI API Documentation#
TikHub AI Proxy provides a unified gateway to stream responses from leading AI models — including OpenAI, Anthropic Claude, and Google Gemini — through a single base URL: https://ai.tikhub.io.Streaming allows you to receive model output incrementally as it's generated, reducing perceived latency and enabling real-time display in your applications.
Base URL#
Supported Providers & Endpoints#
| Provider | Endpoint Path | Auth Header | Streaming Format |
|---|
| OpenAI | /v1/responses | Authorization: Bearer <key> | SSE |
| Anthropic | /v1/messages | x-api-key: <key> | SSE |
| Gemini | /v1beta/models/{MODEL}:streamGenerateContent?alt=sse | x-goog-api-key: <key> | SSE |
All streaming responses use the Server-Sent Events (SSE) protocol. Set Accept: text/event-stream or handle data: prefixed lines accordingly.
Authentication#
Use your TikHub API key in the provider-specific header:# OpenAI-compatible
Authorization: Bearer sk-xxxxxxxxxxxx
# Anthropic-compatible
x-api-key: sk-xxxxxxxxxxxx
# Gemini-compatible
x-goog-api-key: sk-xxxxxxxxxxxx
OpenAI Streaming#
Endpoint#
POST https://ai.tikhub.io/v1/responses
Request Parameters#
| Parameter | Type | Required | Description |
|---|
model | string | ✅ | Model name (e.g., gpt-4o, gpt-5) |
input | string | ✅ | The user prompt |
stream | boolean | ✅ | Must be true for streaming |
Example (Python)#
Anthropic Claude Streaming#
Endpoint#
POST https://ai.tikhub.io/v1/messages
Request Parameters#
| Parameter | Type | Required | Description |
|---|
model | string | ✅ | Model name (e.g., claude-opus-4-6, claude-sonnet-4-5-20250929) |
max_tokens | integer | ✅ | Maximum number of tokens to generate |
stream | boolean | ✅ | Must be true for streaming |
messages | array | ✅ | Conversation messages in {role, content} format |
SSE Event Types#
| Event Type | Description |
|---|
message_start | Initial message metadata |
content_block_start | Start of a content block |
content_block_delta | Incremental text chunk (text_delta) |
content_block_stop | End of a content block |
message_delta | Final message metadata (stop reason, usage) |
message_stop | Stream complete |
Example (Python)#
Google Gemini Streaming#
Endpoint#
POST https://ai.tikhub.io/v1beta/models/{MODEL}:streamGenerateContent?alt=sse
Request Parameters#
| Parameter | Type | Required | Description |
|---|
contents | array | ✅ | Conversation turns in {role, parts} format |
Supported Models#
SSE Response Structure#
Each SSE data: payload contains a JSON object with the following structure:{
"candidates": [
{
"content": {
"parts": [{"text": "..."}],
"role": "model"
}
}
]
}
Example (Python)#
General Notes#
SSE Protocol: All streaming responses follow the Server-Sent Events format. Each event line is prefixed with data: followed by a JSON payload. The stream ends with data: [DONE] (OpenAI/Gemini) or a message_stop event (Anthropic).
Error Handling: Always check HTTP status codes before processing the stream. Non-2xx responses will return a JSON error body instead of SSE events.
Timeouts: Streaming connections may remain open for extended periods. Configure your HTTP client with appropriate read timeouts.
Rate Limits: Standard TikHub API rate limits apply. Monitor response headers for rate limit information.
Support#
For questions or issues, contact us at:Modified at 2026-02-09 19:32:03