Click below π“Follow Rongjie AI”to subscribe to the public account
DeepSeek has fully opened the V3 version on the web and API. Today, Rongjie will introduce how to call the API interface.
1 Create API key
1. Visit the website: https://platform.deepseek.com/api_keys to create an API Key.
2. Enter the name for the API key, you can choose any name.
3. After clicking create, the API key will appear, remember it only appears once, so save it well.
API Key: sk-b55cb01382df4eeca23b68e947a6bad1
2 Using Python to Call DeepSeek V3 API
2.1 Single Round Conversation
If you haven’t installed the openai library, please install it first. Use pip install openai.
Remember to replace the api_key in the code with your own.
# Please install OpenAI SDK first: `pip3 install openai`from openai import OpenAIclient = OpenAI(api_key="sk-b55cb01382df4eeca23b68e947a6bad1", base_url="https://api.deepseek.com")response = client.chat.completions.create( model="deepseek-chat", messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": "Who are you?"}, ], stream=False)print(response.choices[0].message.content)
In the code, the content in {“role”: “user”, “content”: “Who are you?”} is your question in the single round conversation.
The code returns:
Hello! I am the intelligent assistant DeepSeek-V3 developed by DeepSeek Company in China. If you have any questions, I will do my best to help you.
You can see that the response has returned the DeepSeek-V3 version.
2.2 Multi-Round Conversation
Next, I will ask two questions consecutively. The first question is, what is the highest mountain in the world? The second question is what is the second highest mountain? The large model will remember your first question to answer the second question, and you can also see that the second round of conversation adds the content of the first message.
from openai import OpenAIclient = OpenAI(api_key="sk-b55cb01382df4eeca23b68e947a6bad1", base_url="https://api.deepseek.com")# Round 1messages = [{"role": "user", "content": "What is the highest mountain in the world?"}]response = client.chat.completions.create( model="deepseek-chat", messages=messages)messages.append(response.choices[0].message)print(f"Messages Round 1: {messages}")# Round 2messages.append({"role": "user", "content": "What is the second highest mountain?"})response = client.chat.completions.create( model="deepseek-chat", messages=messages)messages.append(response.choices[0].message)print(f"Messages Round 2: {messages}")
The second round of conversation is based on the first round.
In the first round request, the messages passed to the API are:
[ {"role": "user", "content": "What is the highest mountain in the world?"}]
In the second round request:
You need to append the output from the first round to the end of messages
Add the new question to the end of messages
The printed message contents for both rounds are:
Messages Round 1: [{'role': 'user', 'content': 'What is the highest mountain in the world?'}, ChatCompletionMessage(content='The highest mountain in the world is **Mount Everest**, located in the Himalayas, crossing the border between China and Nepal. Mount Everest has an elevation of **8848.86 meters** (according to the joint measurement data of China and Nepal in 2020), making it the highest mountain on Earth.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None)]Messages Round 2: [{'role': 'user', 'content': 'What is the highest mountain in the world?'}, ChatCompletionMessage(content='The highest mountain in the world is **Mount Everest**, located in the Himalayas, crossing the border between China and Nepal. Mount Everest has an elevation of **8848.86 meters** (according to the joint measurement data of China and Nepal in 2020), making it the highest mountain on Earth.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None), {'role': 'user', 'content': 'What is the second highest mountain?'}, ChatCompletionMessage(content='The second highest mountain in the world is **K2**, located in the Karakoram mountain range, crossing the border between China and Pakistan. K2 has an elevation of **8611 meters**, making it the second highest peak in the world, just after Mount Everest. Due to its extreme climbing difficulty, K2 is also known as the "Savage Mountain", a challenge that climbers aspire to conquer.', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None)]
3 Model Pricing
All models have been upgraded to DeepSeek-V3.
The table shows the prices before and after the discount.From now until 24:00 Beijing time on 2025-02-08, all users can enjoy discounted prices for the DeepSeek-V3 API. After this date, the model prices will revert to the original prices.
## Historical Articles ##
1. A step-by-step guide to publishing coze on Feishu Multidimensional Table, configuring your own AI field shortcut
2. Year-end summary without help! These 6 free AI PPT tools can generate high-quality PPTs with one click for novices
3. In 5 minutes, learn how to integrate the Kimi large model into WeChat public account, Rongjie will guide you to play with humorous AI customer service!
4. Don’t know how to call the large model API yet? Kimi API Key application and calling, full nanny-level guidance
If you have learned or been inspired, don’t forget to give me a thumbs up, a view, and share, all three β because your feedback is really important!