Core APIs
Text API
The sections below list endpoints, authentication methods, and minimal examples for OpenAI Responses, Chat Completions, Claude Anthropic Messages, and Grok-compatible APIs. Gemini is not yet available.
Protocols and endpoints
The three protocols have different request bodies, response structures, and streaming events. Enter the Base URL in SDK configuration, or use the complete endpoint in the table when sending HTTP requests directly.
| API / Protocol | Complete endpoint | Authentication | Read text from |
|---|---|---|---|
| OpenAI · Responses | POST https://api.khaix.net/v1/responses | Authorization: Bearer | output[].content[].text |
| OpenAI · Chat Completions | POST https://api.khaix.net/v1/chat/completions | Authorization: Bearer | choices[0].message.content |
| Claude · Anthropic Messages | POST https://api.khaix.net/v1/messages | x-api-key | content[].text |
| Grok · Responses / Chat | POST /v1/responsesPOST /v1/chat/completions | Authorization: Bearer | Read text according to the selected protocol |
| Gemini | Not yet available | Not applicable | Not applicable |
Check the console for OpenAI, Claude, and Grok model IDs, pricing, and availability. The native Gemini protocol is not currently available.
Responses API
Responses submits text through input and supports streaming events, function tools, and structured output. Coding agents such as Codex also use this protocol.
curl https://api.khaix.net/v1/responses \
-H "Authorization: Bearer sk-replace-with-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "Confirm the API connection in one sentence."
}'A completed request returns status: "completed". Text is located in output items whose type is message. The SDK's output_text is a convenience property; the top level of a REST response does not necessarily contain this field.
Chat Completions
Most OpenAI-compatible clients connect through Chat Completions. Roles and conversation content belong in the messages array.
curl https://api.khaix.net/v1/chat/completions \
-H "Authorization: Bearer sk-replace-with-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"messages": [
{"role": "user", "content": "Confirm the API connection in one sentence."}
]
}'Response text is usually located at choices[0].message.content. The input, text.format, and streaming event handlers used by Responses do not apply to this protocol.
Anthropic Messages
Messages uses the Anthropic request structure. max_tokens is required, and the API version is passed in a request header.
curl https://api.khaix.net/v1/messages \
-H "x-api-key: sk-replace-with-your-key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 128,
"messages": [
{"role": "user", "content": "Confirm the API connection in one sentence."}
]
}'Read text from the response's content array. Claude Code sends an authorization header when connecting to the gateway through ANTHROPIC_AUTH_TOKEN; see the client documentation for configuration.
Grok and Gemini
Grok text models are available through the OpenAI-compatible gateway and can use Responses, Chat Completions, or Messages endpoints. The native Gemini protocol is not currently available. Addresses and compatibility settings from other platforms cannot be used directly with KHaiXAPI.
Streaming text output
Add "stream": true to a Responses, Chat Completions, or Messages request body to enable streaming output. This is a minimal Responses SSE request:
curl -N https://api.khaix.net/v1/responses \
-H "Authorization: Bearer sk-replace-with-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "Write a short response in three lines.",
"stream": true
}'| Protocol | Key events or completion method |
|---|---|
| Responses | Handle response.output_text.delta, response.completed, and error |
| Chat Completions | Accumulate choices[].delta.content until the completion marker |
| Messages | Handle Anthropic event types such as content_block_delta |
| Grok | Parse Responses / Chat Completions SSE events according to the corresponding protocol |
| Gemini | Not yet available; the native protocol is not currently provided |
Handle HTTP errors, SSE error events, client disconnects, and overall timeouts separately. The three protocols use different chunk structures and require their own parsing logic.
Standard function tools
The model only returns a function name and arguments; the application remains responsible for execution. Validate the arguments, run the controlled function, and return the result to the model with the original call_id.
curl https://api.khaix.net/v1/responses \
-H "Authorization: Bearer sk-replace-with-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "Find the current time in Shanghai.",
"tools": [{
"type": "function",
"name": "get_city_time",
"description": "Return the local time in the specified city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": false
},
"strict": true
}]
}'The response's output will contain type: "function_call", name, arguments, and call_id. Send a second request after executing the function:
curl https://api.khaix.net/v1/responses \
-H "Authorization: Bearer sk-replace-with-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"previous_response_id": "replace-with-previous-response-id",
"input": [{
"type": "function_call_output",
"call_id": "replace-with-function-call-id",
"output": "{\"city\":\"Shanghai\",\"time\":\"10:30\"}"
}]
}'Structured text output
Use JSON Schema when you need a fixed JSON structure. Returned results must still pass parsing, type, and business-rule validation; support for the full Schema depends on the model.
curl https://api.khaix.net/v1/responses \
-H "Authorization: Bearer sk-replace-with-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "Classify this sentence: The server has recovered and the issue is resolved.",
"text": {
"format": {
"type": "json_schema",
"name": "ticket_result",
"strict": true,
"schema": {
"type": "object",
"properties": {
"status": {"type": "string", "enum": ["open", "resolved"]},
"summary": {"type": "string"}
},
"required": ["status", "summary"],
"additionalProperties": false
}
}
}
}'| Protocol | Schema location | Notes |
|---|---|---|
| Responses | text.format | Field names differ from Chat Completions |
| Chat Completions | response_format.json_schema | The Schema wrapper must also include a name and strict mode |
Structured results are still returned as text content. Treat the request as successful only after the content passes parsing and business validation. Handle refusals, interrupted output, unsupported Schema features, and JSON parsing failures separately.