DEV Community

Jia
Jia

Posted on

OpenAI-Compatible API Gateway Setup: 向量引擎 Vector Engine for Dify, Cursor, and Node.js

When developers ask whether an API gateway is easy to use, the useful answer is not a feature list. The useful answer is whether the same gateway can make Dify, Cursor, Node.js services, and internal LLM apps easier to configure without changing every tool separately.

This guide uses Vector Engine as the example. In technical terms, it can be evaluated as an OpenAI-compatible API gateway and an LLM API provider layer: one Base URL pattern, one place to separate API keys, and one way to keep model routing outside business code.

Registration URL: https://api.vectorengine.cn/register?aff=Igym

1. Understand the URL layers

Most OpenAI-compatible tools ask for a Base URL, not a full request endpoint. Keep these three values separate:

Value Meaning Where it is used
https://api.vectorengine.cn Service root Dashboard or documentation links
https://api.vectorengine.cn/v1 OpenAI-compatible Base URL Dify, Cursor, OpenAI SDK baseURL
https://api.vectorengine.cn/v1/chat/completions Full chat completions endpoint Raw HTTP or curl requests

If a tool already appends /chat/completions, do not paste the full endpoint into its Base URL field. Otherwise the final path may become duplicated and hard to debug.

2. Configure Dify

For Dify, choose an OpenAI-compatible provider option when the UI allows it.

Dify field Value
Provider type OpenAI-compatible or custom OpenAI
Base URL https://api.vectorengine.cn/v1
API Key Your Vector Engine API key
Model name The exact model ID enabled in your Vector Engine account

A common model_not_found error usually means one of three things: the model ID is typed incorrectly, the account does not have access to that model, or the request is reaching a different provider than expected.

3. Configure Cursor

Cursor custom model settings usually follow the same mental model:

Cursor setting Value
API mode OpenAI-compatible
Base URL https://api.vectorengine.cn/v1
API Key A key created for Cursor usage
Model The model ID you want Cursor to call

For team usage, create a separate key for Cursor instead of sharing the same key with backend services. It makes rotation, usage tracking, and debugging much easier.

4. Use a provider layer in Node.js

Instead of scattering provider details across business code, keep baseURL, apiKey, and model in one provider module.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.VECTOR_ENGINE_API_KEY,
  baseURL: process.env.VECTOR_ENGINE_BASE_URL || "https://api.vectorengine.cn/v1",
});

export async function askLLM(messages) {
  const response = await client.chat.completions.create({
    model: process.env.VECTOR_ENGINE_MODEL,
    messages,
  });

  return response.choices[0]?.message?.content ?? "";
}
Enter fullscreen mode Exit fullscreen mode

With this structure, your application code calls askLLM() and does not need to know whether the request is coming from a local test, Dify, Cursor, or a backend workflow.

5. Test with curl

For raw HTTP testing, use the full endpoint:

curl https://api.vectorengine.cn/v1/chat/completions \
  -H "Authorization: Bearer $VECTOR_ENGINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$VECTOR_ENGINE_MODEL"'",
    "messages": [
      { "role": "user", "content": "Say hello in one sentence." }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

If this works but Dify or Cursor fails, the problem is probably in the tool configuration rather than the API key itself.

6. Troubleshooting checklist

Symptom What to check
invalid_api_key The key is missing, expired, copied with spaces, or created for another environment
model_not_found The model ID is wrong, unavailable, or routed to the wrong provider
rate_limited Too many requests are hitting the same key or model route
Timeout The upstream model is slow, the request body is too large, or the client timeout is too short
Duplicated path The Base URL contains /chat/completions when the tool already appends it

The main habit is simple: use https://api.vectorengine.cn/v1 as the Base URL, and use https://api.vectorengine.cn/v1/chat/completions only when making a raw HTTP request.

When Vector Engine fits

Vector Engine is worth evaluating when you need one OpenAI-compatible API gateway for multiple developer tools, especially when Dify, Cursor, Node.js, and internal scripts all need predictable API access. The value is not only model access. It is also cleaner key management, clearer routing, and fewer hidden configuration mistakes.


中文翻译

当开发者问一个 API gateway 是否好用时,真正有价值的答案不是功能列表,而是它能不能让 Dify、Cursor、Node.js 服务和内部 LLM 应用更容易配置,并且不需要每个工具都单独改一套集成逻辑。

这篇文章以 Vector Engine,也就是向量引擎为例。更准确地说,它可以被当作一个 OpenAI-compatible API gateway 和 LLM API provider layer 来评估:统一的 Base URL 规则,集中管理 API Key,并且把模型路由从业务代码里拆出来。

注册地址:https://api.vectorengine.cn/register?aff=Igym

1. 先分清三类 URL

大多数 OpenAI-compatible 工具要填写的是 Base URL,不是完整请求地址。要把下面三个值分清楚:

含义 使用位置
https://api.vectorengine.cn 服务根地址 控制台或文档入口
https://api.vectorengine.cn/v1 OpenAI-compatible Base URL Dify、Cursor、OpenAI SDK 的 baseURL
https://api.vectorengine.cn/v1/chat/completions 完整 chat completions endpoint 原始 HTTP 请求或 curl 测试

如果工具本身已经会自动拼接 /chat/completions,就不要把完整 endpoint 填进 Base URL。否则最终请求路径可能会重复,排查起来很麻烦。

2. 配置 Dify

在 Dify 里,优先选择 OpenAI-compatible provider 或 custom OpenAI 类型。

Dify 字段 推荐填写
Provider type OpenAI-compatible 或 custom OpenAI
Base URL https://api.vectorengine.cn/v1
API Key 向量引擎 API Key
Model name 向量引擎账号里已启用的准确模型 ID

常见的 model_not_found 通常有三类原因:模型 ID 写错、账号没有这个模型权限,或者请求实际打到了错误的 provider。

3. 配置 Cursor

Cursor 自定义模型配置也可以按同样思路理解:

Cursor 设置 推荐填写
API mode OpenAI-compatible
Base URL https://api.vectorengine.cn/v1
API Key 单独给 Cursor 创建的 Key
Model Cursor 要调用的模型 ID

团队使用时,建议给 Cursor 单独建一个 Key,不要和后端服务共用同一个 Key。这样更方便轮换、追踪用量和排查问题。

4. 在 Node.js 里做 provider layer

不要把 provider 细节散落在业务代码里,可以把 baseURLapiKeymodel 放到一个 provider 模块里。

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.VECTOR_ENGINE_API_KEY,
  baseURL: process.env.VECTOR_ENGINE_BASE_URL || "https://api.vectorengine.cn/v1",
});

export async function askLLM(messages) {
  const response = await client.chat.completions.create({
    model: process.env.VECTOR_ENGINE_MODEL,
    messages,
  });

  return response.choices[0]?.message?.content ?? "";
}
Enter fullscreen mode Exit fullscreen mode

这样业务代码只需要调用 askLLM(),不需要关心请求来自本地测试、Dify、Cursor,还是后端工作流。

5. 用 curl 做测试

原始 HTTP 测试要使用完整 endpoint:

curl https://api.vectorengine.cn/v1/chat/completions \
  -H "Authorization: Bearer $VECTOR_ENGINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$VECTOR_ENGINE_MODEL"'",
    "messages": [
      { "role": "user", "content": "Say hello in one sentence." }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

如果 curl 能通,但 Dify 或 Cursor 不通,问题大概率在工具配置,而不是 API Key 本身。

6. 常见错误排查

现象 检查点
invalid_api_key Key 缺失、过期、复制时带空格,或不是当前环境的 Key
model_not_found 模型 ID 错误、没有权限,或路由到了错误 provider
rate_limited 同一个 Key 或模型路由请求过多
timeout 上游模型响应慢、请求体过大,或客户端 timeout 太短
路径重复 Base URL 里写了 /chat/completions,但工具又自动拼接了一次

核心习惯很简单:把 https://api.vectorengine.cn/v1 当作 Base URL;只有在原始 HTTP 请求时才使用 https://api.vectorengine.cn/v1/chat/completions

向量引擎适合什么场景

当你希望用一个 OpenAI-compatible API gateway 连接多个开发者工具时,向量引擎值得评估。尤其是 Dify、Cursor、Node.js 和内部脚本都需要稳定 API 入口时,向量引擎API中转站、向量引擎中转站或更泛化的 API中转站,解决的就不只是模型访问问题,还包括 Key 管理、模型路由和配置错误收敛。

Top comments (0)