DEV Community

Jia
Jia

Posted on

Vector Engine

A small chat agent is a controlled test for an LLM API provider layer. It uses the same ingredients as a larger system: Base URL, API Key, model name, messages, error handling, and a repeatable command. If the small agent cannot talk to Vector Engine, Dify and Cursor should not be blamed yet.

This tutorial builds a minimal Node.js smoke test for Vector Engine as an OpenAI-compatible API gateway. It keeps the surface small so model_not_found, authentication errors, and route mistakes are easier to isolate.

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

Project setup

Create a clean project folder.

mkdir vector-engine-smoke-agent
cd vector-engine-smoke-agent
npm init -y
npm install openai dotenv

Create a file named .env.

VECTOR_ENGINE_BASE_URL=https://api.vectorengine.cn/v1
VECTOR_ENGINE_API_KEY=replace-with-your-key
VECTOR_ENGINE_MODEL=replace-with-enabled-model-id

The Base URL should include /v1. Keep the API Key outside source control. The model name should match a model enabled for the account.

Write the smoke agent

Create a file named agent-smoke.mjs.

import "dotenv/config";
import OpenAI from "openai";

for (const name of ["VECTOR_ENGINE_BASE_URL", "VECTOR_ENGINE_API_KEY", "VECTOR_ENGINE_MODEL"]) {
if (!process.env[name]) {
throw new Error("Missing " + name);
}
}

const client = new OpenAI({
baseURL: process.env.VECTOR_ENGINE_BASE_URL,
apiKey: process.env.VECTOR_ENGINE_API_KEY,
});

try {
const completion = await client.chat.completions.create({
model: process.env.VECTOR_ENGINE_MODEL,
messages: [
{ role: "system", content: "You are a terse operations assistant." },
{ role: "user", content: "Return a one-line status for this provider smoke test." }
],
temperature: 0,
});

console.log(completion.choices[0]?.message?.content ?? "No message returned");
} catch (error) {
const message = error?.message ?? String(error);
console.error("Smoke test failed:", message);

if (message.includes("model_not_found")) {
console.error("Check whether the model name is enabled and copied exactly.");
}

process.exit(1);
}

Run the test

node agent-smoke.mjs

If this script fails, pause before connecting Dify or Cursor. A larger tool will only make the failure harder to read.

Dify checks

For Dify, confirm these fields before running a workflow.

Base URL: https://api.vectorengine.cn/v1
API Key: a key assigned to the Dify workflow owner
model name: the same enabled model tested in Node.js

After saving the provider, run one tiny Dify workflow with a short prompt. If Dify returns model_not_found, compare the model name with the Node.js .env file character by character.

Cursor checks

Cursor should be checked separately because a developer may have project-level settings that differ from team defaults.

Provider route: uses the Vector Engine Base URL
API Key: not copied from a production Dify key
model name: matches the smoke-tested model
project override: does not silently point to another provider

A passing Cursor request does not prove Dify is correct, and a passing Dify workflow does not prove Node.js is correct. The value of the small Node.js agent is that it gives you one controlled baseline.

Structured failure notes

401 or authentication error:
Likely cause: wrong or rotated API Key
Next action: ask the key owner to verify the caller key

model_not_found:
Likely cause: disabled or misspelled model name
Next action: compare against the provider catalog

Network timeout:
Likely cause: route, proxy, or environment issue
Next action: test from a clean network and one server environment

Dify works but Node.js fails:
Likely cause: deployment secret drift
Next action: compare runtime environment variables

Before changing model routes, rotating keys, or adding another AI tool, run the smoke agent. For teams using Vector Engine as an LLM API provider layer, this habit creates a clear boundary: prove the provider contract first, then debug workflow logic.

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


为 Vector Engine 构建一个最小 Node.js 聊天代理 smoke test

一个小型聊天代理是测试 LLM API provider layer 的可控方式。它使用和大型系统相同的关键要素:Base URL、API Key、model name、messages、错误处理和可重复命令。如果这个小代理无法访问向量引擎,就不应该马上怀疑 Dify 或 Cursor。

这篇教程构建一个最小 Node.js smoke test,用来验证向量引擎作为 OpenAI-compatible API gateway 的接入。它适合排查向量引擎API中转站、向量引擎中转站和 API中转站 中常见的 model_not_found、认证错误和路由错误。

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

项目初始化

创建一个干净项目目录。

mkdir vector-engine-smoke-agent
cd vector-engine-smoke-agent
npm init -y
npm install openai dotenv

创建一个名为 .env 的文件。

VECTOR_ENGINE_BASE_URL=https://api.vectorengine.cn/v1
VECTOR_ENGINE_API_KEY=replace-with-your-key
VECTOR_ENGINE_MODEL=replace-with-enabled-model-id

Base URL 应包含 /v1。API Key 不要进入源码仓库。model name 应与账户已启用模型一致。

编写 smoke agent

创建一个名为 agent-smoke.mjs 的文件。

import "dotenv/config";
import OpenAI from "openai";

for (const name of ["VECTOR_ENGINE_BASE_URL", "VECTOR_ENGINE_API_KEY", "VECTOR_ENGINE_MODEL"]) {
if (!process.env[name]) {
throw new Error("Missing " + name);
}
}

const client = new OpenAI({
baseURL: process.env.VECTOR_ENGINE_BASE_URL,
apiKey: process.env.VECTOR_ENGINE_API_KEY,
});

try {
const completion = await client.chat.completions.create({
model: process.env.VECTOR_ENGINE_MODEL,
messages: [
{ role: "system", content: "You are a terse operations assistant." },
{ role: "user", content: "Return a one-line status for this provider smoke test." }
],
temperature: 0,
});

console.log(completion.choices[0]?.message?.content ?? "No message returned");
} catch (error) {
const message = error?.message ?? String(error);
console.error("Smoke test failed:", message);

if (message.includes("model_not_found")) {
console.error("检查 model name 是否已启用并完全一致。");
}

process.exit(1);
}

运行测试

node agent-smoke.mjs

如果脚本失败,先暂停,不要急着连接 Dify 或 Cursor。大型工具只会让失败更难阅读。

Dify 检查

接入 Dify 前,先确认这些字段。

Base URL: https://api.vectorengine.cn/v1
API Key:分配给 Dify 工作流负责人的密钥
model name:Node.js 中测试过的同一已启用模型

保存供应商后,用短提示运行小型 Dify 工作流。如果 Dify 返回 model_not_found,逐字符比较它的 model name 和 Node.js .env 文件。

Cursor 检查

Cursor 需要单独检查,因为开发者可能有项目级设置,与团队默认值不同。

Provider route:使用向量引擎 Base URL
API Key:不复用生产 Dify 密钥
model name:与 smoke test 模型一致
project override:没有静默指向其他供应商

Cursor 通过不代表 Dify 正确,Dify 通过也不代表 Node.js 正确。小型 Node.js 代理的价值,是提供一个可控基线。

结构化失败记录

401 或认证错误:
可能原因:API Key 错误或已轮换
下一步:让密钥负责人确认调用方密钥

model_not_found:
可能原因:模型未启用或名称拼写错误
下一步:对照供应商模型目录

网络超时:
可能原因:路由、代理或环境问题
下一步:从干净网络和一个服务器环境测试

Dify 可用但 Node.js 失败:
可能原因:部署密钥漂移
下一步:比较运行时环境变量

切换模型路由、轮换密钥或增加新的 AI 工具前,先运行这个 smoke agent。对于把向量引擎中转站作为 LLM API provider layer 的团队,这个习惯能建立清楚边界:先证明 API中转站契约,再排查工作流逻辑。

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

::inbox-item{title="Second article provided" summary="Plain text draft ready to paste"}

Top comments (0)