入门

安装

只需一个软件包:iagenify。它为 import 提供 ESM 源码,为 require 提供打包后的 CommonJS 版本,可在 Node 18 及以上版本、浏览器和 Cloudflare Workers 中运行。

iagenify 0.5.4Apache-2.0type: module
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

安装

npm install iagenify

yarn add iagenify
python -m pip install iagenify

导入软件包

两个入口提供相同的接口。加载方式决定使用哪个入口。

// ESM — resolves to the package source
import { IaGenify } from "iagenify";

// CommonJS — resolves to the bundled build
const { IaGenify } = require("iagenify");
# Python has a single import form: the package is installed with pip
# (python -m pip install iagenify) and imported directly.
from iagenify import IaGenify

其他导出项

客户端是常用入口,但错误类、本地基础组件和纯辅助函数也都可以直接访问,因此 instanceof 能正常工作,你也可以独立于引擎使用解析器。

import {
  IaGenify,
  IaGenifyError, Unauthorized, NotEnoughCredits,   // instanceof, not err.name
  LocalFiles, LocalTerminals, Terminal,            // a computer's files and shells
  LocalLibrary, AccountLibrary, AgentLibrary,      // skills and sub-agents
  McpClient, MCP_PROTOCOL_VERSION,
  sanitizeSchema, toolNameFor, createMcpTools,     // pure
  parsePrompt, parseTokenCount, storageSlug, PROMPT_OPTIONS,
  MEDIA_OPTIONS,                                   // what the media tools accept
  AGENT_MODES,                                     // ["ask", "auto", "plan", "full"]
} from "iagenify";
from iagenify import (
    IaGenify,
    IaGenifyError, Unauthorized, NotEnoughCredits,   # isinstance(), not error.name
    LocalFiles, LocalTerminals, Terminal,            # a computer's files and shells
    LocalLibrary, AccountLibrary, AgentLibrary,      # skills and sub-agents
    McpClient, MCP_PROTOCOL_VERSION,
    sanitize_schema, tool_name_for, create_mcp_tools,  # pure
    parse_prompt, parse_token_count, storage_slug, PROMPT_OPTIONS,
    MEDIA_OPTIONS,                                   # what the media tools accept
    AGENT_MODES,                                     # ("ask", "auto", "plan", "full")
)

打包工具

SDK 会先检查运行环境,再动态导入 node:fs、node:os、node:path、node:crypto 和 node:child_process,因此浏览器构建不会访问这些模块。静态分析无法得知这一点,所以需要将该软件包排除在打包处理之外。

// next.config.mjs
const nextConfig = {
  serverExternalPackages: ["iagenify"],
};
export default nextConfig;
# A Python web framework needs no bundler setting: Django, Flask or FastAPI
# import the package like any other dependency.
# pyproject.toml
# dependencies = ["iagenify>=0.1.0"]
打包会破坏动态导入

问题会在运行时以模块缺失的形式出现,而不是在构建时出现。如果服务端调用突然找不到 node:fs,原因就在这里。

环境变量

配置涉及两个变量。如果直接传入对应值,则都不必设置。

变量作用
IAGENIFY_API_KEY约定使用的变量名,SDK 不会自动读取。请将其值传给 apiKey。
IAGENIFY_API_URL未直接传入 baseUrl 时使用此配置;默认值为 https://api.iagenify.com。
# .env
IAGENIFY_API_KEY=ia_your_key_here
IAGENIFY_API_URL=https://api.iagenify.com

运行要求

要求
Node18 或更高版本。直接使用 fetch、FormData、Blob 和 AbortController,不提供兼容性补丁。
浏览器任何现代浏览器。会话保存在 localStorage 中。
WorkersCloudflare Workers。会话在隔离实例的生命周期内保存在内存中。
依赖项无。该软件包不引入额外的运行时依赖。

验证安装

import { IaGenify } from "iagenify";

const api = new IaGenify({ apiKey: process.env.IAGENIFY_API_KEY });

console.log(api.env);            // "node"
console.log(api.capabilities);   // { runtime, shell, filesystem, persistentStorage, http }
console.log(await api.getUser());
console.log((await api.catalogue()).length, "models");
import os
from iagenify import IaGenify

api = IaGenify(api_key=os.environ["IAGENIFY_API_KEY"])

print(api.env)            # "python"
print(api.capabilities)   # {"runtime", "shell", "filesystem", "persistentStorage", "http"}
print(api.get_user())
print(len(api.catalogue()), "models")