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

opencode-sub2api-haiku-fix

v1.0.3

Published

OpenCode plugin for Haiku-specific Anthropic request compatibility through Sub2API.

Readme

opencode-sub2api-haiku-fix

npm Release License OpenCode Dependencies

A focused OpenCode plugin that fixes Claude Haiku request-shape failures through Sub2API without changing Sub2API, OpenCode core, or OMO.

It is intentionally narrow: it only applies to the built-in anthropic provider when the model id contains haiku.

Why

In this setup, Opus and Sonnet can work through the same Sub2API account while Haiku fails with:

You're out of extra usage. Add more at claude.ai/settings/usage and keep going.

That message is misleading here. The account and Sub2API route are usable; Haiku is being rejected because the final request fingerprint does not look enough like Claude Code.

This plugin restores the missing Claude Code-style request shape on the OpenCode side.

What It Changes

  • Preserves Haiku thinking with thinking: { type: "enabled", budget_tokens }.
  • Rewrites the final Haiku wire body into a Claude Code-style 3-block system shape:
    • billing attribution
    • Claude Code identity
    • cached general CLI prompt block
  • Moves the original OpenCode system prompt into the opening messages so local instructions are not lost.
  • Adds Claude Code-style metadata.user_id, x-client-request-id, and x-claude-code-session-id.
  • Rewrites Haiku headers to the current Claude Code-compatible Anthropic shape.
  • Adds ?beta=true to Haiku /v1/messages URLs.
  • Removes fields that break this Haiku path, including context_management and output_config.effort.
  • Caps Haiku tool definitions to OPENCODE_HAIKU_MAX_TOOLS, defaulting to 32.

It does not rewrite Sonnet or Opus requests. It does not implement auth, OAuth, token refresh, keychain access, account switching, or a proxy.

Install

Add the npm package to ~/.config/opencode/opencode.jsonc:

{
  "plugin": [
    "opencode-sub2api-haiku-fix@latest"
  ]
}

Restart OpenCode after changing the plugin list.

Verify

npm test

The test suite covers:

  • current OpenCode chat.params shape
  • final Anthropic fetch-body rewrite
  • Haiku thinking preservation
  • non-Haiku requests staying untouched

Links

  • npm: https://www.npmjs.com/package/opencode-sub2api-haiku-fix
  • Project site: https://mjshao.fun/opencode-sub2api-haiku-fix/
  • Portfolio entry: https://mjshao.fun/work/opencode-sub2api-haiku-fix
  • Release: https://github.com/nxxxsooo/opencode-sub2api-haiku-fix/releases/tag/v1.0.3

Credits

Inspired by:


这是什么

opencode-sub2api-haiku-fix 是一个聚焦的 OpenCode 插件,用来修复 OpenCode 通过 Sub2API 调用 Claude Haiku 时的请求形状问题。

它不改 Sub2API,不改 OpenCode core,不改 OMO,也不处理任何账号或鉴权。它只在 OpenCode 侧,把已经要发给 anthropic provider 的 Haiku 请求改成更接近 Claude Code CLI 的 wire shape。

为什么需要

同一个 Sub2API 账号、同一个后端下,Opus 和 Sonnet 可以正常工作,但 Haiku 可能报:

You're out of extra usage. Add more at claude.ai/settings/usage and keep going.

在这个场景里,这句话不是额度结论,而是请求指纹被上游判进了错误路径。Haiku 的 system body、metadata、thinking shape 和 beta/header 组合需要更像 Claude Code。

它具体做什么

  • 保住 Haiku 的 manual thinking。
  • 把 Haiku 最终请求改成 Claude Code 风格的三段 system:
    • billing attribution
    • Claude Code identity
    • 带缓存断点的通用 CLI prompt block
  • 把原始 OpenCode system prompt 移进开头 messages,避免本地指令丢失。
  • 注入 metadata.user_idx-client-request-idx-claude-code-session-id
  • 对齐 Claude Code 风格 headers 和 beta flags。
  • /v1/messages 增加 ?beta=true
  • 去掉这条 Haiku 路径上会出问题的 context_managementoutput_config.effort
  • 将 Haiku tools 数量限制到 OPENCODE_HAIKU_MAX_TOOLS,默认 32

它不会改 Sonnet 或 Opus 请求。

安装

~/.config/opencode/opencode.jsonc 里添加:

{
  "plugin": [
    "opencode-sub2api-haiku-fix@latest"
  ]
}

改完后重启 OpenCode。

验证

npm test

测试覆盖 current OpenCode hook 形状、最终 fetch body 改写、Haiku thinking 保留,以及非 Haiku 请求不被改动。

License

MIT