- Notifications
You must be signed in to change notification settings - Fork6
yokingma/OpenCursor
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
OpenCursor 是基于 Cursor AI 编辑器接口实现的 OpenAI 兼容的 API,支持流式响应。
本项目仅为研究学习目的,不得用于任何商业用途。
docker pull docker.cnb.cool/aigc/opencursor:latest
假设项目运行在本地(127.0.0.1),端口为3000
(默认),可以在.env中配置。
BaseUrl 为http://127.0.0.1:3000/v1
- 打开 Cursor 网页端,并登录。
- 打开开发者工具
- 在
Application
或者应用
标签下找到 CookieWorkosCursorSessionToken
- 复制
WorkosCursorSessionToken
值作为API_KEY
请求支持普通消息体和图片模式消息体:
// 普通消息体{//..."messages":[{"role":"user","content":"Say this is a test"}],//...}// 图片传入式消息体,但是不支持读图,暂时不知道Cursor接口的传图参数是什么。{//..."messages":[{"role":"user","content":[{"type":"text","text":"Say this is a test"},{"type":"image_url","image_url":{"url":"https://example.com/image.png"}}]}],}
示例为TS语言,其他语言或者详细使用请参考OpenAI 官方API文档 和OpenAI 官方库
npm install openai
importOpenAIfrom'openai';// API_KEY 为 Cursor 网页端登录的 WorkosCursorSessionTokenconstclient=newOpenAI({apiKey:API_KEY,baseURL:'http://127.0.0.1:3000/v1',});asyncfunctionmain(){constchatCompletion=awaitclient.chat.completions.create({messages:[{role:'user',content:'Say this is a test'}],model:'gpt-4o',});}main();
// ...asyncfunctionmain(){conststream=awaitclient.chat.completions.create({model:'gpt-4o',messages:[{role:'user',content:'Say this is a test'}],stream:true,});forawait(constchunkofstream){process.stdout.write(chunk.choices[0]?.delta?.content||'');}}main();
npm installnpm run dev
About
Cursor AI编辑器接口转为OpenAI兼容的API,仅供研究学习使用。Convert Cursor to an OpenAI-compatible API, For learning purposes only.