Skip to Content
API ReferenceChatCreate chat

Create Chat Completion

Create an AI chat conversation and get the model-generated chat response data

Endpoint

POST https://api.stepfun.ai/v1/chat/completions

Request Parameters

  • model string required
    Name of the model to use

  • messages object array required
    List of different categories of messages entered by the user or generated by the model so far

    Expand/Collapse
    • System message object
      Expand/Collapse
      • role string

        Role name for system messages, always system

      • content string

        Text content of the system message

    • User message object
      Expand/Collapse
      • role string
        Role name for user messages, always user
      • content string or object array
        User message content, either a multipart message list or a plain text message string
        Expand/Collapse
        • Plain text message string
        • multipart message list object array
          Structured list of mixed image, video, audio, and text messages
          Expand/Collapse
          • Text message object
            Expand/Collapse
            • type string
              Always text
            • text string
              Message text content
          • Image message object
            Expand/Collapse
            • type string
              Always image_url
            • image_url object
              Expand/Collapse
              • url string

                Image URL or base64-encoded image. Supported formats: jpg/jpeg, png, webp, static gif; only http and https are allowed.
                Example base64 format: data:image/jpeg;base64,${base64_string}. Replace the image format (jpeg) and the corresponding base64 string as needed.

              • detail string optional

                Whether to enable detail mode: choose low/high, default is low.

                low mode scales the image to a fixed size with a token count around 400.
                high mode provides more detailed and richer information. It performs better on large images, OCR, or extreme aspect ratios. Token count varies by the image.

          • Video message object
            Expand/Collapse
            • type string
              Always video_url
            • video_url object
              Expand/Collapse
              • url string

                URL of the video. Format: video/mp4; only http and https are supported. Video must be under 128 MB and the duration is recommended to be under 5 minutes.

          • Audio message object
            Expand/Collapse
            • type string
              Always input_audio
            • input_audio object
              Expand/Collapse
              • data string

                Audio content, provided as a base64-encoded audio file.
                Example base64 format: data:audio/mpeg;base64,${base64_string}. Replace the audio format (currently only mp3 and wav are supported) and its corresponding base64 string.

    • Tool function message object
      Expand/Collapse
      • role string
        Role name for tool messages, always tool
      • content string
        Content returned after executing the function
      • tool_call_id string
        ID of the executed function, returned by the assistant in the previous turn.
    • Chat assistant message object
      Expand/Collapse
      • role string
        Role name for assistant messages, always assistant
      • content string | null
        Text content of the assistant message
  • tools object array optional
    List of functions supported for Toolcall

    Expand/Collapse
    • type string

    Tool type, always function

    • function object

    Description of the function

    Expand/Collapse
    • name string

    Function name. Only English letters, numbers, and _- are allowed; recommended to keep it under 64 characters.

    • description string

    Function description, supports Chinese and English. It tells the model what the function does so the model can judge and choose.

    • parameters object

    Parameters of the function

    Expand/Collapse
    • type object

    Parameter description, usually object

    • properties object

    Function parameter definitions, with the key as the parameter name, and type and description describing the type and details.

    Expand/Collapse
    • type string|number|integer|object|array|boolean

    Parameter type. See json-schema  for reference.

    • description string

    Parameter description, supports Chinese and English. It tells the model what each parameter means.

  • max_tokens int optional
    Maximum number of tokens to generate for the chat. Default is INF (no limit, determined automatically by the model). The total of input and generated tokens is limited by the specified model’s maximum context length.

  • temperature float optional
    Sampling temperature, a number between 0.0 and 2.0. Higher values (e.g., 0.8) make the output more random; lower values (e.g., 0.2) make it more focused and deterministic. Default is 0.5.

  • top_p float optional
    Top-p sampling. The model generates tokens within the probability mass of top_p and outputs them. Default is 0.9.

  • n int optional
    Controls how many response messages the model generates for each input message. Default is 1; no hard max, but suggested up to 5.

  • stream bool optional
    Whether to stream the response messages. Default is false.

  • stop string | string array optional
    Stops generation when encountering any of the stop content. Empty by default.

  • frequency_penalty float optional
    Default is 0. A number between 0.0 and 1.0. Higher values penalize tokens that have appeared frequently in the generated text, reducing repetition.

  • response_format object optional
    Used to instruct the model to output in a specific format. Default is {"type":"text"}, meaning text output. Set { "type": "json_object" } to turn on JSON Mode and output parseable JSON.

  • reasoning_format object optional
    Used to instruct the model which reasoning field to use when outputting; default is general, meaning general reasoning that returns a reasoning field. Options are [general,deepseek-style]. When set to deepseek-style, you can use the DeepSeek-compatible reasoning_content field to obtain the reasoning content.

Response

Returns Chat Completion response object, or Chat Completion streaming response object chunk

Examples

from openai import OpenAI client = OpenAI(api_key = "STEP_API_KEY", base_url = "https://api.stepfun.ai/v1") completion = client.chat.completions.create( model = "step-3.5-flash", messages = [ { "role": "system", "content": "You are an AI chat assistant provided by StepFun. You are good at Chinese, English, and many other languages. While keeping user data safe, you can respond quickly and accurately to users' questions and requests. Your answers and suggestions should reject content related to pornography, gambling, drugs, violence, or terrorism.", }, { "role": "user", "content": "Hello, please introduce StepFun's artificial intelligence!" }, ], ) print(completion)
Response
{ "id": "b7b56af0-52a6-483f-a589-948182676a1b", "object": "chat.completion", "created": 1709893411, "model": "step-3.5-flash", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hello! StepFun is a company focused on artificial intelligence technology and is dedicated to developing and providing various AI solutions. Our AI capabilities cover natural language processing, computer vision, and machine learning to help users in many industries improve efficiency and create value.\n\nWe provide a variety of AI products and services, including intelligent customer service, virtual assistants, smart recommendations, and intelligent moderation. These products and services can be applied across industries such as finance, retail, education, and healthcare. By using our AI, users can better understand and analyze data, deliver personalized services and experiences, and improve the efficiency and accuracy of their decisions.\n\nWe value the security and privacy of user data and strictly follow relevant laws, regulations, and industry standards. We believe AI technology should create more benefits for people rather than negative impacts. We will continue to work hard to provide smarter, more efficient, and safer AI solutions." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 83, "completion_tokens": 176, "total_tokens": 259 } }
Last updated on