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

@anvia/openai

v1.1.5

Published

OpenAI provider adapter for Anvia.

Readme

@anvia/openai

OpenAI provider adapter for Anvia.

Use this package when you want Anvia agents, direct completions, embeddings, image generation, speech generation, or transcription to run on OpenAI models or OpenAI-compatible endpoints.

Installation

pnpm add @anvia/openai @anvia/core

Bun

Bun 1.3.14 is the currently tested and supported runtime baseline:

bun add @anvia/openai@rc @anvia/core@rc

Compatibility tests exercise the OpenAI SDK's JSON, streaming, abort, multipart, and binary media paths without contacting a model provider.

In this monorepo, the package is available through the workspace:

pnpm --filter @anvia/openai build

Usage

import { Agent } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";

const client = new OpenAIClient({
  apiKey,
});

const model = client.completionModel({ modelId: "gpt-5.6", api: "responses" });

const agent = new Agent({
  id: "assistant",
  model: model,
  instructions: "Answer clearly and concisely.",
});

// The model-specific union is inferred: none | low | medium | high | xhigh | max.
await agent.generate({ prompt: "Solve this.", controls: { reasoningEffort: "high" } });

const result = await agent.generate({ prompt: "Summarize Anvia in one sentence." });
if (result.type === "response") console.log(result.output);

OpenAI-Compatible APIs

baseUrl changes only the endpoint. Model handles default to the Chat Completions API; opt into Responses with api: "responses" per handle:

import { OpenAIClient } from "@anvia/openai";

const client = new OpenAIClient({
  apiKey,
  baseUrl,
});

const model = client.completionModel({ modelId: "openai/gpt-5.2", api: "chat" });

The same client can create both { api: "chat" } (the default) and { api: "responses" } handles. Known reasoning models advertise a typed reasoningEffort control. For custom OpenAI-compatible model IDs, pass an explicit controls descriptor to completionModel() when the endpoint supports the same parameter. Canonical controls map to reasoning.effort for Responses and reasoning_effort for Chat Completions, taking precedence over conflicting providerOptions.

Reasoning tool-call providers

Some OpenAI-compatible chat-completions providers return reasoning in provider-specific fields while using normal tool calls. For example, Moonshot Kimi K2.6 returns reasoning_content when thinking is enabled.

The chat-completions adapter preserves this reasoning in assistant history and sends it back as reasoning_content on later turns. This matters after tool calls: providers such as Moonshot can reject the next request if an assistant tool_calls message is missing its prior reasoning_content.

For Moonshot Kimi K2.6 thinking mode:

import { generateCompletion } from "@anvia/core";

const client = new OpenAIClient({
  apiKey: process.env.OPENAI_API_KEY,
  baseUrl: "https://api.moonshot.ai/v1",
});

const model = client.completionModel({ modelId: "kimi-k2.6", api: "chat" });

const response = await generateCompletion({
  model,
  messages: chatHistory,
  tools,
  maxTokens: 16_000,
  providerOptions: {
    thinking: { type: "enabled", keep: "all" },
  },
});

Provider caveat: Moonshot rejects forced/specified tool_choice while thinking is enabled. Let the model choose tools naturally when using Kimi thinking mode.

Other Models

const embeddingModel = client.embeddingModel({ modelId: "text-embedding-3-small" });
const imageModel = client.imageGenerationModel({ modelId: "gpt-image-2" });
const speechModel = client.speechGenerationModel({ modelId: "gpt-4o-mini-tts" });
const transcriptionModel = client.transcriptionModel({ modelId: "gpt-4o-mini-transcribe" });

Use the provider-neutral helpers from @anvia/core to call media models:

import { generateImage, generateSpeech, transcribe } from "@anvia/core";

const image = await generateImage({ model: imageModel, prompt: "A launch poster." });
const speech = await generateSpeech({
  model: speechModel,
  text: "Hello from Anvia.",
  voice: "alloy",
});
const transcript = await transcribe({
  model: transcriptionModel,
  audio: { data: speech.audio.data, filename: "speech.mp3" },
});

Exports

  • OpenAIClient
  • structural completion, embedding, image, speech, and transcription handle types
  • OpenAICompletionModelId and media model-ID types
  • model constants such as GPT_IMAGE_2, GPT_4O_MINI_TTS, and GPT_TRANSCRIBE
  • openai

Development

The package-local typecheck and build scripts build @anvia/core first so core subpath types are available in a fresh worktree.

pnpm --filter @anvia/openai typecheck
pnpm --filter @anvia/openai test
pnpm --filter @anvia/openai build