Multi-Provider LLM Gateway#
The chat/completions endpoint provides a unified, OpenAI-compatible interface to multiple Large Language Models (LLMs), including GPT-4o, Claude 3.5 Sonnet, Gemini 1.5 Pro, and open-source models.
Supported Providers#
ChainHub supports the following LLM providers:OpenAI: GPT-4o, GPT-4o-mini, and o1/o3 reasoning models
Anthropic: Claude 3.5 series
Google: Gemini 1.5 Pro (2M token context window)
Open Source: Llama 3.1, Qwen 2.5, Mistral
API Specification#
API Specification#
This endpoint implements the OpenAI chat completions specification. Replace the OpenAI base URL with https://api.chainhub.tech/v1 and use your ChainHub API key.
Request Examples#
Basic Request#
Streaming Request#
The response follows the OpenAI chat.completion object structure.{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
Best Practices#
Context Management#
Include conversation history in the messages array to maintain context. For long conversations, consider using the Embeddings API for retrieval-augmented generation (RAG).Streaming#
Set stream: true for real-time token delivery in user-facing applications.Advanced Configuration#
System Role: Define assistant behavior (e.g., "You are a senior DevOps engineer")
Structured Output: Use tool definitions to control response JSON schema
Modified at 2026-02-08 08:34:50