Skip to main content

Documentation Index

Fetch the complete documentation index at: https://platform.stepfun.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Call the Messages API to get the model-generated response data. This endpoint is compatible with the Anthropic Messages API format — you can use the Anthropic SDK directly or the same JSON shape.
This page lists only the currently confirmed supported fields. Do not pass fields that are not listed here.

Endpoint

POST https://api.stepfun.ai/v1/messages
When using the Anthropic SDK, set base_url to https://api.stepfun.ai — the SDK will automatically append /v1/messages, you don’t need to include /v1 manually.

Request Parameters

  • model string required
    Model name. Use the public model name your account has access to, e.g. step-3.7-flash or step-3.5-flash.
  • messages object array required
    Conversation history; at least one message.
  • max_tokens int required
    Maximum number of tokens to generate; must be greater than 0.
  • system string or array optional
    System prompt. Either a string or an array of text blocks.
  • tools object array optional
    List of tool definitions.
  • output_config object optional
    Structured output configuration.
  • stream boolean optional
    Whether to stream the response; default is non-streaming.
  • temperature float optional
    Sampling temperature, between 0 and 2.
  • top_p float optional
    Nucleus sampling parameter, greater than 0 and at most 1.
  • top_k int optional
    top-k parameter, between 0 and 500.
  • stop_sequences string array optional
    Stop sequences — generation stops when any of these appear in the output.

Response

Non-streaming response

Content-Type: application/json
{
    "id": "msg_xxx",
    "type": "message",
    "role": "assistant",
    "stop_reason": "end_turn",
    "usage": {
        "input_tokens": 20,
        "output_tokens": 12
    },
    "content": [
        {
            "type": "text",
            "text": "I'm an AI assistant."
        }
    ]
}
Response fields
  • id string
    Unique message ID.
  • type string
    Object type, always message.
  • role string
    Role name, always assistant.
  • content object array
    List of content blocks. Typically text; in tool-calling scenarios may include tool_use.
  • stop_reason string
    Why generation stopped. One of end_turn, tool_use, max_tokens.
  • usage object
    Token usage statistics — at least input_tokens and output_tokens.

Streaming response

Content-Type: text/event-stream Streaming uses standard SSE format. Each event has an event: line and a data: line; data: is JSON. Common event types: message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop, ping. When streaming tool-call arguments, content_block_delta.delta.type may be input_json_delta.
event: message_start
data: {"type":"message_start","message":{"id":"msg_xxx","type":"message","role":"assistant","model":"step-3.5-flash"}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}

event: message_delta
data: {"type":"message_delta","stop_reason":"end_turn","usage":{"input_tokens":20,"output_tokens":12}}

event: message_stop
data: {"type":"message_stop"}

Examples

from anthropic import Anthropic

client = Anthropic(api_key="STEP_API_KEY", base_url="https://api.stepfun.ai")

message = client.messages.create(
    model="step-3.5-flash",
    max_tokens=1024,
    system="You are an AI chat assistant provided by StepFun. You are fluent in English, Chinese, and many other languages. You answer user questions quickly and accurately while protecting user data.",
    messages=[
        {
            "role": "user",
            "content": "Introduce yourself in one sentence."
        }
    ],
)

print(message)
{
    "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
    "type": "message",
    "role": "assistant",
    "stop_reason": "end_turn",
    "usage": {
        "input_tokens": 35,
        "output_tokens": 20
    },
    "content": [
        {
            "type": "text",
            "text": "I'm an AI chat assistant by StepFun, ready to answer your questions in English, Chinese, and other languages quickly and accurately."
        }
    ]
}