API Doc-CometAPI
English
  • English
  • Русский
HomeDashBoardModel Marketplace
HomeDashBoardModel Marketplace
Discord_Support
English
  • English
  • Русский
  1. 💬 Text Models
  • 🚀 Overview
    • Quick Start
    • Important Guidelines
    • Release Notes
    • Quickly request CometAPI via ApiDog
    • Models
  • 💬 Text Models
    • Chat
      POST
    • Responses
      POST
    • Anthropic Messages
      POST
    • Gemini Generating Content
      POST
    • Embeddings
      POST
    • Recognizing Images
      POST
  • 🖼️ Image Models
    • Midjourney
      • Midjourney Quick Start: Complete Image Generation Workflow in One Go
      • Task Fetching API
        • List by Condition
        • Fetch Single Task (most recommended)
      • Submit Editor
      • Submit Video
      • Imagine
      • Action (UPSCALE; VARIATION; REROLL; ZOOM, etc.)
      • Blend (image -> image)
      • Describe (image -> text)
      • Modal (Area Redesign & Zoom)
    • Replicate(image)
      • Create Predictions - General
      • replicate query
      • Create Task -flux-kontext-pro、max
      • Create Task -flux-1.1-pro
      • Create Task -flux-1.1-pro-ultra
    • seededit/seedream
      • bytedance-image-generation(seedream)
      • bytedance-Image Editing (seededit)
    • OpenAI
      • Images
      • gpt-4o-image generates image
      • Image Editing (gpt-image-1)
    • Gemini
      • Guide to calling gemini-2.5-flash-image (Nano Banana)
      • Gemini generates image
    • Hunyuan3D
  • 🎵 Music Models
    • Suno
      • Setting suno Version
      • Suno API Scenario Application Guide
      • Generate lyrics
      • Generate music clip
      • Upload clip
      • Submit concatenation
      • Full Track Audio Separation
      • Single Track Audio Separation
      • Create New Persona
      • add style tags
      • Single task query
      • Generate mp4 mv video
      • Timing: lyrics, audio timeline
      • Get wav format file
      • Get midi
      • Batch query tasks
  • 📺 Video Models
    • veo3
      • veo3-chat format
      • Submit video generation task
      • Query video generation status
    • sora-2
      • official
        • Create video
        • Remix video
        • Retrieve video
        • Delete video
        • Retrieve video content
      • sora-2 generate video by chat
    • runway(video)
      • official format
        • runway images raw video
        • Generate a video from a video
        • Generate an image from text
        • Upscale a video
        • Control a character
        • runway to get task details
      • Reverse Format
        • generate(text)
        • generate(Reference images)
        • Video to Video Style Redraw
        • Act-one Expression Migration
        • feed-get task
    • kling (video)
      • callback_url
      • Multimodal Video Editing
        • Initialize Video for Editing
        • Add Video Selection
        • Delete Video Selection
        • Clear Video Selection
        • Preview Selected Video Area
        • Create Task
      • Generating images
      • Expanded
      • Text Generation Video
      • Image Generation Video
      • Multi-Image To Video
      • Multi-Image to Image
      • Video Extension
      • virtual try-on
      • lip sync
      • effects
      • Video to audio
      • Text to audio
      • Individual queries
    • bytedance
      • bytedance-video
      • bytedance-video get
    • MiniMax Conch(video)
      • MiniMax Conch Official Documentation
      • MiniMax Conch Generation
      • MiniMax Conch Query
      • MiniMax Conch Download
  • 🔊 Audio Models
    • Create speech
    • Create transcription
    • Create translation
  • 🧩 Integration Guides
    • LiteLLM
    • Dify
    • Make
    • n8n
    • Lobe-Chat
    • COZE
    • Zapier
    • Activepieces
    • LlamaIndex
    • Continue
    • FlowiseAI
    • Chatbox
    • CherryStudio
    • Cursor
    • AnythingLLM
    • LangChain
    • BuildShip
    • gptme
    • Immersive Translation
    • Cline
    • Eudic Translation
    • ChatHub
    • OpenAI Translator
    • ChatAll Translation
    • Pot Translation
    • Zotero
    • NEXT CHAT (ChatGPT Next Web)
    • Obsidian's Text Generator Plugin
    • librechat
    • utools-ChatGPT Friend
    • avante.nvim
    • Open WebUI
    • GPT Academic Optimization (gpt_academic)
    • OpenManus
    • IntelliJ Translation Plugin
    • FastGPT
    • n8n Local Deployment
  • ⚠️ Errors
    • Error Codes & Handling
  • 📝 Code Examples
    • Text-to-Image Generation
    • Image-to-image generation URL upload
    • Regular Post Text Conversation
    • OpenAI Official Library Usage Example
    • Streamed Output
    • Json Fixed Format Output Code Display
    • Embedding code example
    • o1-preview Model Code Example
    • LangChain Usage Example (Successful Test Date: 2024-11-25)
    • Openai dall-e-3 & flux series drawing model
    • gpt, claude, gemini multimodal network image parsing example
    • Multimodal PDF File Parsing Examples for GPT, Claude, and Gemini
    • Code example
  • 🏄🏼‍♀️ Best Practices
    • Midjourney Best Practices
    • Retry Logic Documentation for CometAPI and OpenAI Official API
    • Runway Best Practices
    • Claude Code Installation and Usage Guide
    • Gemini CLI Installation and Usage Guide
    • Codex Usage Guide
    • CometAPI Account Balance Query API Usage Instructions
  • 💳 Pricing & Billing
    • About Pricing
  • 🤝🏼 Support
    • Help Center
    • Interface Stability
    • Privacy policy
    • Terms of service
    • Common Misconceptions
    • Confusion about use
  • [Counterpart] Face Recognition
    POST
  • [Counterpart] Creating Tasks
    POST
  1. 💬 Text Models

Chat

POST
https://api.cometapi.com/v1/chat/completions
Maintainer:Not configured

Overview#

chat/completions is the most common API interface for LLMs, taking a conversation list composed of multiple messages as input to get responses from the LLM model.

Important Notes#

⚠️ Model Variability
Different model providers may support different request parameters and return different response fields. We strongly recommend checking the official documentation of the respective model provider to understand the complete parameter list and usage methods.
⚠️ Response Pass-through Principle
CometAPI typically does not modify model response results outside of reverse-engineered formats, ensuring you receive response content consistent with the original API.

Reference Documentation#

For more detailed information about the chat/completions interface, please refer to the OpenAI Official Documentation.
OpenAI Related Guides:
Quickstart
Text Generation
Vision
Audio
Structured Outputs
Function Calling
Conversation State Management

API Reference#

Request Parameters#

Required Parameters#

model string required
Specifies the model ID to use for generating responses.
{
  "model": "gpt-4"
}
messages array required
A list of conversation messages containing roles and content. Each message must include:
role string - The role of the message, possible values:
system - System message, used to set assistant behavior
user - User message
assistant - Assistant's historical replies
content string - The specific content of the message
{
  "messages": [
    {
      "role": "system",
      "content": "You are a professional AI assistant"
    },
    {
      "role": "user",
      "content": "What is machine learning?"
    }
  ]
}

Optional Parameters#

stream boolean optional
Whether to enable streaming responses. When set to true, responses will be returned incrementally in the form of Server-Sent Events (SSE).
Default: false
{
  "stream": true
}
temperature number optional
Controls the randomness of responses, range 0-2.
Lower values (e.g., 0.2): more deterministic and focused
Higher values (e.g., 1.8): more random and creative
Default: 1.0
max_tokens integer optional
Limits the maximum number of tokens to generate.
top_p number optional
Nucleus sampling parameter, range 0-1. It's recommended not to adjust both temperature and top_p simultaneously.

Frequently Asked Questions#

How to handle rate limits?#

When encountering 429 Too Many Requests, implement exponential backoff retry:

How to maintain conversation context?#

Include the complete conversation history in the messages array:

What does finish_reason mean?#

ValueMeaning
stopNatural completion
lengthReached max_tokens limit
content_filterTriggered content filter
function_callModel called a function

How to control costs?#

1.
Use max_tokens to limit output length
2.
Choose appropriate models (e.g., gpt-3.5-turbo is more economical)
3.
Simplify prompts and avoid redundant context
4.
Monitor token consumption in the usage field

Request

Header Params

Body Params application/json

Examples

Responses

🟢200Successful Response
application/json
Body

Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.cometapi.com/v1/chat/completions' \
--header 'Authorization: Bearer {{api-key}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-5-mini",
    "messages": [
        {
            "role": "user",
            "content": "Hello!"
        }
    ],
    "stream": false
}'
Response Response Example
{
    "id": "chatcmpl-AreYSBEwmzB0kY3GxzBEhE1Olct83",
    "object": "chat.completion",
    "created": 1737350640,
    "model": "gpt-4o-2024-08-06",
    "system_fingerprint": "fp_f3927aa00d",
    "choices": [
        {
            "index": 0,
            "message": {
                "content": "Hello! How can I assist you today?",
                "role": "assistant"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "completion_tokens": 9,
        "completion_tokens_details": {},
        "prompt_tokens": 9,
        "prompt_tokens_details": {},
        "total_tokens": 18
    }
}
Modified at 2025-11-07 05:57:47
Previous
Models
Next
Responses
Built with