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
  • 🖼️ Image Models
    • OpenAI
      • gpt-4o-image generates image
      • Images
      • Image Editing (gpt-image-1)
    • 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
    • seededit/seedream
      • bytedance-Image Editing (seededit)
      • bytedance-image-generation(seedream)
    • bria
      • Generate Image
      • Generate Vector Graphics - Base (Beta)
      • Image Editing
      • Query Status
    • Gemini
      • Guide to calling gemini-2.5-flash-image (Nano Banana)
      • Gemini generates image
    • Hunyuan3D
  • 📺 Video Models
    • sora-2
      • official
        • Create video
        • Remix video
        • Retrieve video
        • Retrieve video content
      • self-developed
        • Retrieve video
        • Create video
    • veo3
      • veo3-chat format
      • Submit video generation task
      • Query video generation status
    • 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
      • Text to Video
      • Image to Video
      • Multi-Image To Video
      • Video Extension
      • Avatar
      • Lip-Sync
      • Video Effects
      • Text to Audio
      • Video to Audio
      • TTS
      • Image Generation
      • Multi-Image to Image
      • Image Expansion
      • Image Recognize
      • Virtual Try-On
      • [Counterpart] Creating Tasks
      • lip sync
      • Individual queries
    • 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
    • bytedance
      • bytedance-video
      • bytedance-video get
    • MiniMax Conch(video)
      • MiniMax Conch Official Documentation
      • MiniMax Conch Generation
      • MiniMax Conch Query
      • MiniMax Conch Download
  • 🎵 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
  • 🔊 Audio Models
    • Realtime
    • Create speech
    • Create transcription
    • Create translation
  • 🧩 Integration Guides
    • LiteLLM
    • Dify
    • Make
    • n8n
    • Lobe-Chat
    • COZE
    • Zapier
    • Activepieces
    • LlamaIndex
    • Continue
    • FlowiseAI
    • Chatbox
    • CherryStudio
    • 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
  1. 💬 Text Models

Chat

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

Overview#

chat/completions is the most common LLM API interface, which takes a list of messages forming a conversation as input and returns intelligent model responses.

Important Notes#

⚠️ Model Variations
Different model providers may support different request parameters and return varying response fields. We strongly recommend consulting the respective model provider's official documentation for complete parameter lists and usage methods.
⚠️ Response Pass-through Principle
CometAPI usually does not modify the model’s responses, except when restoring certain internally developed model calls.

Reference Documentation#

For more detailed information about the chat/completions interface, please refer to the OpenAI Official Documentation.
OpenAI Related Guides:
Quickstart
Text Input/Output
Image Input
Audio Input/Output
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 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, the response will be returned in chunks as Server-Sent Events (SSE).
Default: false
{
  "stream": true
}
temperature number optional
Controls response randomness, 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. Recommended not to adjust both temperature and top_p simultaneously.

FAQ#

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.
Streamline prompts and avoid redundant context
4.
Monitor token consumption in the usage field

Request

Header Params

Body Params application/json

Examples

Responses

🟢200Image Input
application/json
Body

Request Request Example
Shell
JavaScript
Java
Swift
cURL
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.1",
  "messages": [
    {
      "role": "developer",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello!"
    }
  ]
}'
Response Response Example
Default
{
    "id": "chatcmpl-CbnYmQAVmFC6IzQTs9X0bFc3J1S7q",
    "object": "chat.completion",
    "created": 1763124680,
    "model": "gpt-5.1-2025-11-13",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Hello! How can I help you today?",
                "refusal": null,
                "annotations": []
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 18,
        "completion_tokens": 18,
        "total_tokens": 36,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "audio_tokens": 0
        },
        "completion_tokens_details": {
            "reasoning_tokens": 0,
            "audio_tokens": 0,
            "accepted_prediction_tokens": 0,
            "rejected_prediction_tokens": 0
        }
    },
    "service_tier": "default",
    "system_fingerprint": null
}
Modified at 2025-11-14 12:51:39
Previous
Models
Next
Responses
Built with