在一个开发者群看到有DMXAPI这个网站,好奇进去看,真有干货。

而且创作文章还能获得现金奖励,屌丝程序员的福利啊!

python程序员很容易上手:

"""
DMXAPI 对话接口调用示例
功能:使用 gpt-5-mini 模型进行智能对话
"""

import json
import requests

# ==================== API 配置 ====================

# API 接口地址
url = "https://www.dmxapi.cn/v1/chat/completions"

# 请求头配置
headers = {
    "Authorization": "sk-**********************************",  # 替换为你的 DMXAPI 令牌
    "Content-Type": "application/json"
}

# ==================== 请求参数 ====================

# 构造请求数据
payload = {
    "model": "gpt-5-mini",  # 选择使用的模型
    "messages": [
        {
            "role": "system", 
            "content": "You are a helpful assistant."  # 系统提示词:定义 AI 助手的角色
        },
        {
            "role": "user", 
            "content": "周树人和鲁迅是兄弟吗?"  # 用户问题
        }
    ]
}

# ==================== 发送请求 ====================

try:
    # 发送 POST 请求到 API
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    response.raise_for_status()  # 检查 HTTP 错误
    
    # 输出响应结果
    print("=" * 50)
    print("API 响应结果:")
    print("=" * 50)
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
    
except requests.exceptions.RequestException as e:
    # 异常处理
    print(f"❌ 请求失败: {e}")

api令牌还有很多对大家友好的设置,不如token限制等。

为了减少免费模型负载压力,设置了一元充值门槛,免费不收费,不扣费,相当nice。

把api key换成我的key,model设置为MiniMax-M2.7-free。

得到如下响应:

==================================================
API 响应结果:
==================================================
{
  "id": "0632d549c18b4f1b7b618f687ec3c9b1",
  "object": "chat.completion",
  "created": 1776525904,
  "model": "MiniMax-M2.7",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "周树人就是鲁迅,他们是同一个人,周树人是鲁迅的原名,并非兄弟关系。\n\n周树人(1881年9月25日-1936年10月19日),笔名鲁迅,是中国现代著名的文学家、思想家。他原名周樟寿,后改名周树人,字豫才。\"鲁迅\"是他1918年发表《狂人日记》时开始使用的笔名。\n\n可能有些朋友会把鲁迅和他的兄弟搞混,这里简单介绍一下:\n- 鲁迅的弟弟是周作人(1885-1967),也是著名的翻译家和散文家\n- 他的另一个弟弟是周建人(1888-1984),是生物学家\n\n周树人和鲁迅是一个人,希望这个解释能帮助您澄清这个误解。",
        "reasoning_content": "This question asks whether Zhou Shuren and Lu Xun are brothers. This is a question about literary history and related to Chinese modern literary history. Zhou Shuren is the real name of Lu Xun, they are the same person, not brothers. I need to correct this common misunderstanding and briefly introduce the identity of Lu Xun.\n"
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 30,
    "completion_tokens": 220,
    "total_tokens": 250,
    "prompt_tokens_details": {
      "cached_tokens_details": {}
    },
    "completion_tokens_details": {},
    "claude_cache_creation_5_m_tokens": 0,
    "claude_cache_creation_1_h_tokens": 0
  }
}
很适合正在做一些实验项目的开发者。

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐