Skip to content

Text-based Conversation ​

Fast-API is fully compatible with the OpenAI Chat Completions API format and supports both streaming and non-streaming output modes.

Basic Information ​

  • Endpoint: https://fast-api.org/v1/chat/completions
  • Authentication: Bearer Token (API Key)
  • Request Method: POST

Request Parameters ​

ParameterTypeDescription
modelstringModel name (e.g., gpt-4o-mini, claude-sonnet-4-6)
messagesarrayConversation messages list
streambooleanEnable streaming output (default: false)
temperaturenumberControls randomness (0~2, default: 1)
max_tokensintegerMaximum output token count
top_pnumberNucleus sampling parameter (0~1, default: 1)

Non-Streaming Request Example ​

python
import requests

url = "https://fast-api.org/v1/chat/completions"
headers = {
    "Authorization": "Bearer sk-yourAPIKey",
    "Content-Type": "application/json"
}
payload = {
    "model": "gpt-4o-mini",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello, please introduce yourself."}
    ]
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

cURL Example ​

bash
curl https://fast-api.org/v1/chat/completions \
  -H "Authorization: Bearer sk-yourAPIKey" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Notes ​

  • Please keep your API Key safe and do not share it with others
  • It is recommended to use HTTPS protocol
  • The response format is completely consistent with the official OpenAI API