Examples
Practical code examples for common integration patterns.
Chat Completion
Send a message and receive a complete model response.
Request Example
curl https://gateway.hkting.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
],
"temperature": 0.7,
"max_tokens": 500
}'Response Example
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1734567890,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Quantum computing uses qubits instead of bits..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 142,
"total_tokens": 160
}
}Streaming
Receive responses incrementally via Server-Sent Events (SSE) for real-time applications.
Request Example
curl https://gateway.hkting.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "Write a short poem about AI."}
],
"stream": true
}'Tool Calling (Function Calling)
Let the model call functions defined in your request to fetch data or take actions.
Request Example
curl https://gateway.hkting.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "What'''s the weather like in Paris today?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name"
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'Response Example
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\":\"Paris\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}The model decides when to call a tool. If it does, the response includes a tool_calls field instead of content. You then send the tool result back to continue the conversation.
Embeddings
Generate vector embeddings for text input using supported embedding models.
Request Example
curl https://gateway.hkting.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"model": "text-embedding-ada-002",
"input": "The quick brown fox jumps over the lazy dog"
}'Agent Integration
Configure AI coding agents and assistants to use HuiLink as their API backend.
Configuration
# Configure Claude Code to use Token Gateway
export ANTHROPIC_BASE_URL=https://gateway.hkting.com
export ANTHROPIC_API_KEY=sk-your-api-key
# Start a Claude Code session
claudeClaude Code uses Anthropic's Messages API format. HuiLink provides protocol conversion between OpenAI and Anthropic formats, enabling seamless integration with both ecosystems.