
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
AisAPI是一个让你轻松对接多种AI大模型的库,提供统一的接口来调用OpenAI、Claude、Gemini、文心一言等国内外主流大模型服务。
AisAPI is a library that allows you to easily connect to various AI models, providing a unified interface to call mainstream AI services such as OpenAI, Claude, Gemini, ERNIE, and more.
统一接口:用同样的代码调用不同的AI服务
Unified Interface: Use the same code to call different AI services
支持多种AI:
Multiple AI Support:
丰富功能:
Rich Features:
开发友好:完整TypeScript类型支持,简单易用的API
Developer Friendly: Complete TypeScript type support, simple and easy-to-use API
npm install aisapi
import { AisAPI } from 'aisapi';
// 创建实例,配置多个AI服务
// Create an instance with multiple AI services configured
const ai = new AisAPI({
openai: {
apiKey: process.env.OPENAI_API_KEY
},
anthropic: {
apiKey: process.env.ANTHROPIC_API_KEY
},
defaultProvider: 'openai' // 默认用哪个 | Default provider
});
// 用默认AI生成文本
// Generate text using the default AI
const result = await ai.generateText({
prompt: '请解释什么是人工智能',
maxTokens: 100
});
console.log(result.text);
// 切换到不同的AI
// Switch to a different AI
const claudeResult = await ai.generateText({
prompt: '请解释什么是人工智能',
maxTokens: 100
}, 'anthropic');
console.log(claudeResult.text);
import { GPT, Claude, Gemini } from 'aisapi';
// 使用OpenAI
// Using OpenAI
const gpt = new GPT({
apiKey: process.env.OPENAI_API_KEY,
model: 'gpt-4'
});
const result = await gpt.generateText({
prompt: '什么是机器学习?',
temperature: 0.7
});
console.log(result.text);
const chatResult = await gpt.chatCompletion({
model: 'gpt-4',
messages: [
{ role: 'system', content: '你是一个专业的科技顾问。' },
{ role: 'user', content: '请比较React和Vue的优缺点?' }
]
});
console.log(chatResult.text);
const imageResult = await gpt.generateImage({
prompt: '一只宇航员猫咪在太空中漂浮',
size: '1024x1024',
model: 'dall-e-3'
});
console.log('图像URL:', imageResult.urls[0]);
// Image URL: imageResult.urls[0]
const stream = await gpt.createStreamingChatCompletion({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: '讲一个短故事' }]
});
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
// 处理每个返回的数据块
// Process each returned data chunk
const chunk = new TextDecoder().decode(value);
process.stdout.write(chunk);
}
import { Ernie, ErnieModel } from 'aisapi';
const ernie = new Ernie({
apiKey: process.env.ERNIE_API_KEY, // 百度AI平台的API Key
secretKey: process.env.ERNIE_SECRET_KEY, // 百度AI平台的Secret Key
model: ErnieModel.ERNIE_BOT_4 // 使用ERNIE Bot 4模型
});
const result = await ernie.generateText({
prompt: '以"春风"为主题,写一首现代诗',
temperature: 0.8
});
console.log(result.text);
import { Spark, SparkModel } from 'aisapi';
const spark = new Spark({
apiKey: process.env.SPARK_API_KEY,
appId: process.env.SPARK_APP_ID,
apiSecret: process.env.SPARK_API_SECRET,
model: SparkModel.SPARK_MAX // 使用星火MAX模型 | Using Spark MAX model
});
const result = await spark.generateText({
prompt: '解释一下Transformer架构的工作原理'
});
console.log(result.text);
const jsonResult = await gpt.generateJSON({
prompt: '生成三个虚构人物的数据,包含姓名、年龄和职业'
});
console.log(JSON.stringify(jsonResult.data, null, 2));
const embedding = await gpt.createEmbedding({
model: 'text-embedding-3-small',
input: '这是一个示例文本'
});
console.log(`嵌入维度: ${embedding.data[0].embedding.length}`);
// Embedding dimensions: ${embedding.data[0].embedding.length}
const transcription = await gpt.transcribeAudio({
file: audioFile, // 你的音频文件 | Your audio file
model: 'whisper-1',
language: 'zh'
});
console.log('识别结果:', transcription.text);
// Recognition result: transcription.text
const speech = await gpt.textToSpeech({
input: '你好,这是一个文本转语音的示例。',
model: 'tts-1',
voice: 'alloy'
});
// 使用speech.audioData (ArrayBuffer)保存或播放音频
// Use speech.audioData (ArrayBuffer) to save or play audio
| 功能 Features | OpenAI | Claude | Gemini | DeepSeek | ERNIE | Spark | ChatGLM | Moonshot | Doubao | Grok |
|---|---|---|---|---|---|---|---|---|---|---|
| 文本生成 Text Generation | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 图像生成 Image Generation | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| 聊天对话 Chat Dialogue | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 语音识别 Speech Recognition | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| 语音合成 Speech Synthesis | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| 向量嵌入 Vector Embeddings | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| JSON输出 JSON Output | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 流式输出 Streaming Output | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
下表列出了各提供商的配置参数,可选参数前标有"?",并提供默认值。 The table below lists the configuration parameters for each provider, with optional parameters marked with "?" and their default values.
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'gpt-3.5-turbo' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://api.openai.com/v1' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 30000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| ?organization | 组织ID| Organization ID | undefined |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'claude-3-haiku-20240307' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://api.anthropic.com' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'gemini-pro' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 30000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| ?region | API区域| API region | 'us-central1' |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'deepseek-chat' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://api.deepseek.com/v1' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 30000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| secretKey | 密钥| Secret Key | - |
| ?model | 模型名称| Model name | 'ernie-bot-4' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://aip.baidubce.com' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| ?accessTokenLifetime | 访问令牌有效期(秒)| Access token lifetime (seconds) | 2592000 (30天|days) |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| appId | 应用ID| Application ID | - |
| apiSecret | API密钥| API Secret | - |
| ?model | 模型名称| Model name | 'spark-v3.5' |
| ?domain | 服务域名| Service domain | 'general' |
| ?baseURL | 自定义API地址| Custom API URL | 'wss://spark-api.xf-yun.com/v3.5/chat' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'glm-4' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://open.bigmodel.cn/api/paas/v4' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'moonshot-v1-8k' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://api.moonshot.cn/v1' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'doubao-pro' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://api.doubao.com/v1' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 参数 Parameter | 说明 Description | 默认值 Default Value |
|---|---|---|
| apiKey | API密钥| API Key | - |
| ?model | 模型名称| Model name | 'grok-1' |
| ?baseURL | 自定义API地址| Custom API URL | 'https://api.grok.ai/v1' |
| ?timeout | 请求超时时间(毫秒)| Request timeout (ms) | 60000 |
| ?maxRetries | 最大重试次数| Maximum retry attempts | 2 |
| 提供商 Provider | 实现类 Implementation Class | 示例文件 Example File |
|---|---|---|
| OpenAI | OpenAIProvider | example-openai.ts |
| Anthropic | AnthropicProvider | example-anthropic.ts |
| Google Gemini | GeminiProvider | example-gemini.ts |
| DeepSeek | DeepSeekProvider | example-deepseek.ts |
| Grok | GrokProvider | example-grok.ts |
| 文心一言 ERNIE | ErnieProvider | example-ernie.ts |
| 讯飞星火 Spark | SparkProvider | example-spark.ts |
| 智谱AI ChatGLM | ZhipuProvider | example-zhipu.ts |
| Moonshot (Kimi) | MoonshotProvider | example-moonshot.ts |
| 豆包 Doubao | DoubaoProvider | example-doubao.ts |
欢迎贡献!请按照以下步骤:
Contributions are welcome! Please follow these steps:
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)本项目采用MIT许可证 - 详见LICENSE文件。
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A JavaScript/TypeScript API library for multiple AI providers
The npm package aisapi receives a total of 9 weekly downloads. As such, aisapi popularity was classified as not popular.
We found that aisapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.