Coding & Development✨geminiπŸ€–claudeπŸ’¬gpt🌐universal

Qiniu AI SDK

TypeScript SDK for Qiniu Cloud AI Token API

Quick Start

Install this Skill

npx skills add bowenQT/qiniu-ai-sdk
# Qiniu AI SDK

<div align="center">

[![npm version](https://img.shields.io/npm/v/@bowenqt/qiniu-ai-sdk.svg?style=flat-square)](https://www.npmjs.com/package/@bowenqt/qiniu-ai-sdk)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg?style=flat-square)](https://nodejs.org/)

**TypeScript SDK for Qiniu Cloud AI Services**

[English](./README.md) | [δΈ­ζ–‡](./README.zh-CN.md) | [COOKBOOK](./COOKBOOK.md)

</div>

---

## ✨ Features

### Core AI Modules
- πŸš€ **Chat Completions** β€” OpenAI-compatible interface with streaming support
- πŸ–ΌοΈ **Image Generation** β€” Kling, Gemini models with unified sync/async API
- πŸŽ₯ **Video Generation** β€” Kling, Sora, Veo models with first/last frame control
- πŸ” **Web Search** β€” Real-time web search integration
- πŸ“ **OCR** β€” High-precision text recognition for images and PDFs
- 🎀 **ASR** β€” Multi-language speech recognition (95%+ accuracy in noisy environments)
- πŸ”Š **TTS** β€” Text-to-speech synthesis with multiple voice options
- πŸ›‘οΈ **Content Moderation** β€” Image and video censorship with scene-based detection

### Agentic Layer
- πŸ€– **generateText** β€” Multi-step tool execution with Zod schema support
- πŸ“Š **generateObject/streamObject** β€” Structured JSON output with streaming
- 🧠 **AgentGraph** β€” State machine-based graph execution
- 🏭 **createAgent** β€” Reusable agent factory with configurable behaviors

### Advanced Capabilities
- πŸ“‹ **Skills Injection** β€” Markdown-based agent knowledge (Claude Skills compatible)
- πŸ”— **MCP Client** β€” Model Context Protocol with stdio + HTTP + OAuth 2.0 support
- πŸ–₯️ **MCP Server** β€” Built-in Qiniu MCP server for OCR/Censor/Vframe tools
- πŸ’Ύ **Checkpointer** β€” State persistence (Memory, Redis, PostgreSQL, Kodo)
- 🧠 **Memory Manager** β€” Short-term + long-term memory with LLM summarization
- βœ… **Tool Approval (HITL)** β€” Human-in-the-loop for sensitive operations
- ⏸️ **Interrupt/Resume** β€” Resumable execution with checkpoint-based restore
- πŸ“Š **OpenTelemetry Tracing** β€” Distributed tracing with per-node spans
- πŸ”Œ **Vercel AI SDK Adapter** β€” Drop-in replacement for Vercel AI SDK

---

## πŸ“¦ Installation

```bash
npm install @bowenqt/qiniu-ai-sdk
```

### Optional Peer Dependencies

```bash
# For Vercel AI SDK integration
npm install @ai-sdk/provider ai

# For Zod schema validation
npm install zod

# For Redis checkpointer
npm install ioredis

# For PostgreSQL checkpointer
npm install pg
```

---

## πŸš€ Quick Start

```typescript
import { QiniuAI } from '@bowenqt/qiniu-ai-sdk';

const client = new QiniuAI({
  apiKey: 'Sk-xxxxxxxxxxxxxxxx',
});

// Chat completion
const chat = await client.chat.create({
  model: 'gemini-2.5-flash',
  messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(chat.choices[0].message.content);

// Streaming chat
const stream = await client.chat.createStream({
  model: 'gemini-2.5-flash',
  messages: [{ role: 'user', content: 'Explain AI briefly' }],
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
```

---

## πŸ€– Agentic Usage

### Tool Execution with generateText

```typescript
import { QiniuAI, generateText } from '@bowenqt/qiniu-ai-sdk';
import { z } from 'zod';

const client = new QiniuAI({ apiKey: process.env.QINIU_API_KEY || '' });

const result = await generateText({
  client,
  model: 'gemini-2.5-flash',
  prompt: 'What is 42 * 17?',
  tools: {
    calculate: {
      description: 'Perform calculation',
      parameters: z.object({
        operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
        a: z.number(),
        b: z.number(),
      }),
      execute: async ({ operation, a, b }) => {
        const ops = { add: a + b, subtract: a - b, multiply: a * b, divide: a / b };
        return ops[operation];
      },
    },
  },
  maxSteps: 3,
});

console.log(result.text);       // Final answer
console.log(result.toolCalls);  // Tool calls made
```

### Structured Output

```typescript
import { generateObject } from '@bowenqt/qiniu-ai-sdk';
import { z } from 'zod';

const result = await generateObject({
  client,
  model: 'gemini-2.5-flash',
  prompt: 'Generate a product listing',
  schema: z.object({
    name: z.string(),
    price: z.number(),
    category: z.string(),
  }),
});

console.log(result.object); // Typed object
```

---

## πŸ–ΌοΈ Image & Video Generation

```typescript
// Image generation (async task)
const imageResult = await client.image.generate({
  model: 'kling-v2',
  prompt: 'A futuristic city at sunset',
});
const finalImage = await client.image.waitForResult(imageResult);
console.log(finalImage.data?.[0].url);

// Video generation with first/last frame
const videoTask = await client.video.create({
  model: 'kling-video-o1',
  prompt: 'A cat jumps from one ledge to another',
  frames: {
    first: { url: 'https://example.com/start.jpg' },
    last: { url: 'https://example.c

... (truncated)
Repository
3stars
0forks
View on GitHub
Details
DiscoveredJan 21, 2026
Last UpdatedJan 21, 2026
Author@bowenQT
Quality Score
30/100