Get an API key
Go to the Account Management submenu on the console and open Interface Keys to create a key.
Environment setup
Install Python dependencies
Python users can reuse the OpenAI SDK:
pip install --upgrade 'openai>=1.0'Install cURL
Install curl with your OS package manager:
-
Debian/Ubuntu (
apt):sudo apt-get update sudo apt-get install curl -
CentOS (
yumordnf; CentOS 8+ usesdnf):- With yum:
sudo yum install curl- With dnf (CentOS 8):
sudo dnf install curl -
macOS (
brew; install Homebrew from brew.sh if needed):brew install curl
Test a basic API request
Once you have installed the required dependencies and obtained an API key, you can make requests using the Python SDK or curl. Below are simple examples using Python and curl.
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
The responses for both streaming and non-stream requests are similar to the following:
Response
{
"id": "b7b56af0-52a6-483f-a589-948182676a1",
"object": "chat.completion",
"created": 170989341,
"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
}
}Some example error responses are shown below(for detailed error information, see the Error Codes documentation):
- Request Timeout Mechanism:A time limit of 10 minutes is set for each request. If a request is not completed within this time limit, the system will stop waiting, immediately terminate the request, and return an error response with status code 503.
- Rate Limiting:The system also enforces rate limits to control the frequency of requests. If a user’s request rate exceeds the allowed limit, the system will not process the excess requests and will instead return an error response with status code 429. This error indicates “Too Many Requests”, meaning that too many requests have been sent within a given time window.
Last updated on