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

@i1hwan/apex-compatible

v0.1.3

Published

AI SDK provider adapter for ApexRoute — extends @ai-sdk/openai-compatible with cache write token support via MetadataExtractor

Readme

@i1hwan/apex-compatible

AI SDK provider adapter for ApexRoute. Extends @ai-sdk/openai-compatible with cache write token support via MetadataExtractor.

Why

When using Anthropic Claude through an OpenAI-compatible proxy like ApexRoute, the standard @ai-sdk/openai-compatible provider loses cache_creation_input_tokens (cache write) because the OpenAI spec has no field for it. This adapter extracts cache data from the raw response — before Zod strips unknown fields — and injects it into providerMetadata where consumers like OpenCode can read it.

What it fixes

| Token Data | @ai-sdk/openai-compatible | @i1hwan/apex-compatible | |---|---|---| | inputTokens.total | ✅ | ✅ | | inputTokens.cacheRead | ✅ | ✅ | | inputTokens.cacheWrite | ❌ always undefined | ✅ via providerMetadata | | outputTokens.reasoning | ✅ | ✅ |

Install

npm install @i1hwan/apex-compatible

Usage

import { createApexCompatible } from "@i1hwan/apex-compatible";

const provider = createApexCompatible({
  baseURL: "https://your-apexroute-instance.com/v1",
  apiKey: process.env.APEX_API_KEY,
});

const model = provider("claude-sonnet-4-20250514");

With OpenCode

In your opencode.json:

{
  "provider": {
    "apexroute": {
      "npm": "@i1hwan/apex-compatible",
      "options": {
        "baseURL": "https://your-apexroute-instance.com/v1",
        "apiKey": "{env:APEX_API_KEY}"
      }
    }
  }
}

How it works

ApexRoute already emits prompt_tokens_details.cache_creation_tokens in OpenAI-compatible responses. The standard @ai-sdk/openai-compatible provider drops this field during Zod schema validation.

This package uses the official metadataExtractor extension point to:

  1. Read cache_creation_tokens and cached_tokens from raw response data (before Zod parse)
  2. Inject them into providerMetadata under the anthropic key (for OpenCode compatibility)
ApexRoute → { prompt_tokens_details: { cache_creation_tokens: 152 } }
    ↓
MetadataExtractor.processChunk(rawChunk)  ← pre-Zod raw data
    ↓
providerMetadata: { anthropic: { cacheCreationInputTokens: 152 } }
    ↓
OpenCode getUsage() → Cache Write: 152 ✅

No server-side changes required. No fork of @ai-sdk/openai-compatible. ~50 lines of code.

API

createApexCompatible(options)

Creates an OpenAI-compatible provider with ApexRoute metadata extraction pre-configured.

interface ApexCompatibleSettings {
  baseURL: string;
  name?: string;           // default: "apex-compatible"
  apiKey?: string;
  headers?: Record<string, string>;
  queryParams?: Record<string, string>;
  fetch?: FetchFunction;
  supportsStructuredOutputs?: boolean;
  transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
}

createApexMetadataExtractor()

Standalone metadata extractor — use if you want to configure createOpenAICompatible yourself:

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { createApexMetadataExtractor } from "@i1hwan/apex-compatible";

const provider = createOpenAICompatible({
  baseURL: "https://your-proxy.com/v1",
  name: "my-provider",
  includeUsage: true,
  metadataExtractor: createApexMetadataExtractor(),
});

Related

  • ApexRoute — Private OmniRoute fork with lexical rewrite, thinking effort control, and cache token translation
  • Vercel AI SDK — The AI SDK this adapter extends
  • OpenCode — CLI that consumes this provider

License

MIT