获取免费chatgpt apikey

第一步  访问github marketplace打开github:(没有账号需要先注册账号)https://github.com/marketplace/models/azure-openai/gpt-4-1/playground

image

第二步  申请apikey点击Get developer key
image

选择classic,输入Note
image

拖到底部,点击Generate token
image

然后把token复制下来。

第三步  配置到dify中 (重点)
输入模型名称:openai/gpt-4.1
API Key:您刚申请的APIkeyAPI
endpoint URL:https://models.github.ai/inference
模型上下文长度:1049000

python文件引用

# ========== 1. 配置 ==========
client = OpenAI(api_key="你的apikey", base_url="https://models.github.ai/inference")


resp = client.chat.completions.create(
    model="gpt-4o-mini",
    # model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": prompt}],
    temperature=0.4,
  )
  # print(resp)
  return resp.choices[0].message.content
posted @ 2025-10-11 11:56  赏金猎人小熊  阅读(13)  评论(0)    收藏  举报