Documentation navigation
On this page

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 / ProtocolComplete endpointAuthenticationRead text from
OpenAI · ResponsesPOST https://api.khaix.net/v1/responsesAuthorization: Beareroutput[].content[].text
OpenAI · Chat CompletionsPOST https://api.khaix.net/v1/chat/completionsAuthorization: Bearerchoices[0].message.content
Claude · Anthropic MessagesPOST https://api.khaix.net/v1/messagesx-api-keycontent[].text
Grok · Responses / ChatPOST /v1/responses
POST /v1/chat/completions
Authorization: BearerRead text according to the selected protocol
GeminiNot yet availableNot applicableNot 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 · Responses
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 · Chat Completions
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 · Messages
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 · Responses SSE
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
  }'
ProtocolKey events or completion method
ResponsesHandle response.output_text.delta, response.completed, and error
Chat CompletionsAccumulate choices[].delta.content until the completion marker
MessagesHandle Anthropic event types such as content_block_delta
GrokParse Responses / Chat Completions SSE events according to the corresponding protocol
GeminiNot 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 · Declare a 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",
    "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 · Return the function result
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 · Responses JSON Schema
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
        }
      }
    }
  }'
ProtocolSchema locationNotes
Responsestext.formatField names differ from Chat Completions
Chat Completionsresponse_format.json_schemaThe 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.