Text API

Chat, Legacy Completions, and Responses; supports SSE streaming

The Text API provides Chat, Legacy text completion, and Responses. All three support non-streaming JSON and SSE streaming.

Overview

The Guid AI gateway exposes three text endpoints. Choose by scenario:

EndpointUse whenEndpoint type
POST /v1/chat/completionsGeneral chat, tool calling, multimodal input (images, etc.), streaming SSEopenai
POST /v1/completionsLegacy text completion (prompt → continuation)openai
POST /v1/responsesMulti-turn Responses, reasoning, structured output, tool callingopenai-response

Selection tips:

  • Most new projects should prefer Chat Completions (/v1/chat/completions).
  • Use Completions (/v1/completions) only for single-prompt continuation or legacy SDK compatibility.
  • Use Responses (/v1/responses) when you need previous_response_id multi-turn context or Responses structured output.

Prerequisite: model must appear in the Models API list and include the matching endpoint type in supported_endpoint_types.

Conventions: Auth, Base URL, Content-Type, etc. are covered in Common Conventions. Error formats are in Common Conventions.

Endpoints

MethodPathDescription
POST/v1/chat/completionsChat (supports SSE streaming)
POST/v1/completionsText completion
POST/v1/responsesResponses chat

POST /v1/chat/completions

Chat completions with non-streaming JSON and SSE streaming.

Auth: Bearer Token

Content-Type: application/json

Request body

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello, who are you?"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "stream": false
}

Request fields

FieldTypeRequiredDescription
modelstringYesModel ID
messagesarrayYesConversation message list
messages[].rolestringYessystem / user / assistant / tool
messages[].contentstring / arrayYesText or multimodal content
streambooleanNoWhen true, returns an SSE stream; default false
temperaturenumberNoSampling temperature, 0–2
top_pnumberNoNucleus sampling, 0–1
max_tokensintegerNoMax output tokens
max_completion_tokensintegerNoMax completion tokens
stopstring / arrayNoStop sequences
toolsarrayNoTool definitions
tool_choicestring / objectNoTool selection strategy
response_formatobjectNoStructured output format
stream_optionsobjectNoStreaming options, e.g. { "include_usage": true }

Multimodal message example (image input):

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "What's in this image?" },
        {
          "type": "image_url",
          "image_url": { "url": "https://example.com/image.jpg" }
        }
      ]
    }
  ]
}

Request example (curl)

Non-streaming:

curl https://www.guid.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello, who are you?"}
    ],
    "temperature": 0.7,
    "max_tokens": 1024,
    "stream": false
  }'

Streaming (SSE):

curl -N https://www.guid.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": true
  }'

Response body (non-streaming)

HTTP 200, Content-Type: application/json

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1712697600,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I'm an AI assistant. How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 15,
    "total_tokens": 43
  }
}

Response fields

FieldTypeDescription
idstringResponse ID, e.g. chatcmpl-xxx
objectstringAlways chat.completion
createdintegerUnix timestamp (seconds)
modelstringModel actually used
choicesarrayGeneration results; length equals request n (default 1)
choices[].indexintegerResult index, starting at 0
choices[].message.rolestringAlways assistant
choices[].message.contentstring / nullReply text; may be null for tool calls
choices[].message.tool_callsarrayTool call list (when tools are enabled)
choices[].message.tool_calls[].idstringTool call ID
choices[].message.tool_calls[].typestringAlways function
choices[].message.tool_calls[].function.namestringFunction name
choices[].message.tool_calls[].function.argumentsstringFunction arguments as a JSON string
choices[].message.reasoning_contentstringReasoning text (reasoning models)
choices[].finish_reasonstringStop reason; see table below
usageobjectToken usage; see Shared response objects

finish_reason values:

ValueDescription
stopNatural stop or hit a stop sequence
lengthReached max_tokens limit
tool_callsModel initiated a tool call
content_filterContent blocked by safety policy

Tool call response example:

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1712697600,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_abc123",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\":\"Beijing\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 50,
    "completion_tokens": 20,
    "total_tokens": 70
  }
}

Response body (streaming)

HTTP 200, Content-Type: text/event-stream

With "stream": true in the request body, the server pushes SSE events. Each message looks like:

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1712697600,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1712697600,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1712697600,"model":"gpt-4o","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":28,"completion_tokens":15,"total_tokens":43}}

data: [DONE]

Streaming chunk fields

FieldTypeDescription
idstringSame ID as the final response
objectstringAlways chat.completion.chunk
createdintegerUnix timestamp (seconds)
modelstringModel used
system_fingerprintstringSystem fingerprint (some models)
choices[].indexintegerResult index
choices[].delta.rolestringFirst chunk may include assistant
choices[].delta.contentstringIncremental text fragment
choices[].delta.reasoning_contentstringIncremental reasoning text (reasoning models)
choices[].delta.tool_callsarrayIncremental tool call fragments
choices[].finish_reasonstring / nullStop reason on the last chunk; otherwise null
usageobjectAppears only on the last chunk (requires stream_options.include_usage=true)

Streaming end marker: final line data: [DONE].


POST /v1/completions

Legacy text completion endpoint.

Auth: Bearer Token

Content-Type: application/json

Request body

{
  "model": "gpt-4o",
  "prompt": "Say this is a test",
  "max_tokens": 100,
  "temperature": 0.7,
  "stream": false
}

Request fields

FieldTypeRequiredDescription
modelstringYesModel ID
promptstring / arrayYesPrompt text
max_tokensintegerNoMax output tokens
temperaturenumberNoSampling temperature
top_pnumberNoNucleus sampling
nintegerNoNumber of completions; default 1
streambooleanNoWhether to stream
stopstring / arrayNoStop sequences

Request example (curl)

Non-streaming:

curl https://www.guid.ai/v1/completions \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "prompt": "Say this is a test",
    "max_tokens": 100,
    "temperature": 0.7,
    "stream": false
  }'

Streaming (SSE):

curl -N https://www.guid.ai/v1/completions \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "prompt": "Say this is a test",
    "stream": true
  }'

Response body (non-streaming)

HTTP 200

{
  "id": "cmpl-abc123",
  "object": "text_completion",
  "created": 1712697600,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "text": "This is indeed a test.",
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 6,
    "total_tokens": 11
  }
}

Response fields

FieldTypeDescription
idstringResponse ID, e.g. cmpl-xxx
objectstringAlways text_completion
createdintegerUnix timestamp (seconds)
modelstringModel used
choicesarrayGeneration results
choices[].indexintegerResult index
choices[].textstringCompletion text
choices[].finish_reasonstringstop / length / content_filter
usageobjectToken usage; see Shared response objects

Response body (streaming)

data: {"id":"cmpl-abc123","object":"text_completion","created":1712697600,"choices":[{"index":0,"text":"This","finish_reason":null}]}

data: {"id":"cmpl-abc123","object":"text_completion","created":1712697600,"choices":[{"index":0,"text":" is","finish_reason":null}]}

data: [DONE]

Streaming chunk fields

FieldTypeDescription
idstringResponse ID
objectstringAlways text_completion
createdintegerUnix timestamp (seconds)
choices[].indexintegerResult index
choices[].textstringIncremental text fragment
choices[].finish_reasonstring / nullStop reason on the last chunk

POST /v1/responses

Responses chat endpoint supporting multi-turn conversation, tool calling, reasoning, and more.

Auth: Bearer Token

Content-Type: application/json

Request body

{
  "model": "gpt-4o",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "Explain quantum computing in one sentence."
        }
      ]
    }
  ],
  "temperature": 0.7,
  "max_output_tokens": 1024,
  "stream": false
}

Request fields

FieldTypeRequiredDescription
modelstringYesModel ID
inputstring / arrayYesInput content; string or message array
instructionsstringNoSystem instructions
temperaturenumberNoSampling temperature
max_output_tokensintegerNoMax output tokens
streambooleanNoWhether to stream
toolsarrayNoTool definitions
tool_choicestring / objectNoTool selection strategy
previous_response_idstringNoPrevious response ID for multi-turn chat
storebooleanNoWhether to store the conversation
metadataobjectNoCustom metadata

Request example (curl)

Non-streaming:

curl https://www.guid.ai/v1/responses \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": [
      {
        "role": "user",
        "content": [
          {"type": "input_text", "text": "Explain quantum computing in one sentence."}
        ]
      }
    ],
    "temperature": 0.7,
    "max_output_tokens": 1024,
    "stream": false
  }'

Streaming (SSE):

curl -N https://www.guid.ai/v1/responses \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "Hello",
    "stream": true
  }'

Response body (non-streaming)

HTTP 200

{
  "id": "resp_abc123",
  "object": "response",
  "created_at": 1712697600,
  "status": "completed",
  "model": "gpt-4o",
  "output": [
    {
      "type": "message",
      "id": "msg_abc123",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Quantum computing uses quantum bits that can exist in superposition to perform certain calculations exponentially faster than classical computers.",
          "annotations": []
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 15,
    "output_tokens": 28,
    "total_tokens": 43
  },
  "temperature": 0.7,
  "top_p": 1.0
}

Response fields

FieldTypeDescription
idstringResponse ID, e.g. resp_xxx
objectstringAlways response
created_atintegerUnix timestamp (seconds)
statusstringResponse status; see table below
modelstringModel used
outputarrayOutput item list
output[].typestringOutput type; see table below
output[].idstringOutput item ID
output[].statusstringOutput item status
output[].rolestringRole (assistant for message type)
output[].contentarrayContent block list
output[].content[].typestringContent type, e.g. output_text
output[].content[].textstringText content
output[].content[].annotationsarrayAnnotation/citation list
output[].call_idstringTool call ID (function_call type)
output[].namestringFunction name (function_call type)
output[].argumentsstring / objectFunction arguments (function_call type)
output[].qualitystringImage quality (image_generation_call type)
output[].sizestringImage size (image_generation_call type)
instructionsstringSystem instructions (echo)
temperaturenumberSampling temperature (echo)
top_pnumberNucleus sampling (echo)
max_output_tokensintegerMax output tokens (echo)
previous_response_idstringPrevious response ID
parallel_tool_callsbooleanWhether parallel tool calls are enabled
storebooleanWhether the conversation is stored
metadataobjectCustom metadata
incomplete_details.reasonstringIncomplete reason (when status=incomplete)
errorobjectError info (when status=failed)
usageobjectToken usage; see Shared response objects

status values:

ValueDescription
completedGeneration finished
in_progressGeneration in progress
failedGeneration failed
incompleteIncomplete due to token limit or similar

output[].type values:

ValueDescription
messageAssistant text message
function_callFunction/tool call
image_generation_callImage generation call
web_search_callWeb search call

Response body (streaming)

HTTP 200, Content-Type: text/event-stream

data: {"type":"response.created","response":{"id":"resp_abc123","object":"response","status":"in_progress"}}

data: {"type":"response.output_text.delta","delta":"Quantum","output_index":0,"content_index":0}

data: {"type":"response.output_text.delta","delta":" computing","output_index":0,"content_index":0}

data: {"type":"response.completed","response":{"id":"resp_abc123","status":"completed","usage":{"input_tokens":15,"output_tokens":28,"total_tokens":43}}}

data: [DONE]

Streaming event fields

FieldTypeDescription
typestringEvent type; see table below
responseobjectFull or partial response object
deltastringIncremental text
output_indexintegerOutput item index
content_indexintegerContent block index
itemobjectAdded/completed output item
item_idstringOutput item ID
partobjectReasoning summary fragment

Common type values:

ValueDescription
response.createdResponse created
response.output_text.deltaText delta
response.output_item.addedOutput item added
response.output_item.doneOutput item completed
response.function_call_arguments.deltaFunction arguments delta
response.function_call_arguments.doneFunction arguments completed
response.completedResponse completed