npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@autolabz/vercel-llmapi-provider

v0.1.3

Published

Vercel AI SDK provider for AutoLab LLM API

Readme

@autolabz/vercel-llmapi-provider

Vercel AI SDK provider for AutoLab LLM API - 使 AutoLab LLM API 能够通过 Vercel AI SDK 的标准接口使用。

安装

npm install @autolabz/vercel-llmapi-provider @autolabz/llmapi-sdk

兼容性

完全支持 Node.js ESM 模式

本包已针对 Node.js ESM 规范进行优化,可以在 "type": "module" 的项目中无缝使用。

快速开始

基础使用

import { createLLMAPIProvider } from '@autolabz/vercel-llmapi-provider';
import { generateText } from 'ai';

const provider = createLLMAPIProvider({
  baseURL: 'https://api.autolab.example.com/llmapi',
  auth: {
    getAccessToken: () => localStorage.getItem('access_token'),
    getClientId: () => 'your-client-id',
    refreshAccessToken: async () => {
      // 实现 token 刷新逻辑
      return newToken;
    },
    onUnauthorized: () => {
      // 处理未授权情况
    }
  }
});

// 使用 generateText
const { text } = await generateText({
  model: provider('gpt-4o-mini'),
  prompt: 'Hello, world!'
});

console.log(text);

与 Auth SDK 集成

import { createLLMAPIProvider } from '@autolabz/vercel-llmapi-provider';
import { createAuthBridgeFromContext, useAuth } from '@autolabz/auth-sdk';
import { generateText, streamText } from 'ai';

const auth = useAuth();
const provider = createLLMAPIProvider({
  baseURL: '/llmapi',
  auth: createAuthBridgeFromContext(auth)
});

// 非流式生成
const { text } = await generateText({
  model: provider('gpt-4o-mini'),
  prompt: 'Say hello'
});

// 流式生成
const { textStream } = await streamText({
  model: provider('gpt-4o-mini'),
  prompt: 'Tell me a story'
});

for await (const chunk of textStream) {
  process.stdout.write(chunk);
}

使用工具调用(Tools)

import { createLLMAPIProvider } from '@autolabz/vercel-llmapi-provider';
import { generateObject } from 'ai';
import { z } from 'zod';

const provider = createLLMAPIProvider({
  baseURL: '/llmapi',
  auth: createAuthBridgeFromContext(auth)
});

const { object } = await generateObject({
  model: provider('gpt-4o-mini'),
  schema: z.object({
    name: z.string(),
    age: z.number(),
  }),
  prompt: 'Generate a person object'
});

使用工具(Tools)

import { createLLMAPIProvider } from '@autolabz/vercel-llmapi-provider';
import { generateText, tool } from 'ai';
import { z } from 'zod';

const provider = createLLMAPIProvider({
  baseURL: '/llmapi',
  auth: createAuthBridgeFromContext(auth)
});

const { text, toolCalls } = await generateText({
  model: provider('gpt-4o-mini'),
  tools: {
    getWeather: tool({
      description: 'Get the weather for a location',
      parameters: z.object({
        location: z.string().describe('The city and state'),
      }),
      execute: async ({ location }) => {
        // 实现获取天气的逻辑
        return { temperature: 72, condition: 'sunny' };
      },
    }),
  },
  prompt: 'What is the weather in San Francisco?'
});

API 参考

createLLMAPIProvider(settings)

创建 LLM API provider 实例。

参数:

interface LLMAPIProviderSettings {
  baseURL: string;                    // llmapi-service 基础 URL
  auth: AuthBridge;                   // 认证桥接器
  defaultHeaders?: Record<string, string>;  // 可选的默认请求头
  fetch?: typeof fetch;               // 可选的自定义 fetch 函数
}

返回值:

返回一个 LLMAPIProvider 实例,可以作为 Vercel AI SDK 的 provider 使用。

Provider 使用方式

// 方式 1: 直接调用
const model = provider('gpt-4o-mini');

// 方式 2: 使用 chat 方法
const model = provider.chat('gpt-4o-mini');

// 方式 3: 覆盖配置
const model = provider('gpt-4o-mini', {
  baseURL: 'https://custom-url.com/llmapi',
  auth: customAuthBridge
});

功能特性

  • 完全兼容 Vercel AI SDK - 实现标准的 ProviderV2 接口
  • 支持流式和非流式调用 - 支持 generateTextstreamText 等所有 Vercel AI SDK 功能
  • 工具调用支持 - 完整支持工具调用(tools)和结构化输出
  • 自动认证处理 - 集成 AutoLab Auth SDK,自动处理 token 刷新
  • 错误处理 - 将 LLM API 错误转换为 Vercel AI SDK 标准错误格式
  • 类型安全 - 完整的 TypeScript 类型支持

与 Vercel AI SDK 的集成

本 provider 完全兼容 Vercel AI SDK 的所有功能,包括:

  • generateText() - 生成文本
  • streamText() - 流式生成文本
  • generateObject() - 生成结构化对象
  • streamObject() - 流式生成结构化对象
  • generateImage() - 生成图片(如果后端支持)
  • embed() - 生成嵌入向量(如果后端支持)
  • 工具调用(Tools)
  • 结构化输出(Structured Outputs)

依赖

  • @ai-sdk/provider - Vercel AI SDK 核心接口
  • @ai-sdk/provider-utils - Vercel AI SDK 工具函数
  • @autolabz/llmapi-sdk - AutoLab LLM API 客户端
  • zod - 类型验证(peer dependency)

许可证

MIT