Explicit anthropic model provider for FlexHarness models and the AI SDK.

Part of the [FlexHarness toolbox](https://code.foss.global/modelprofile.com/flexharness).
Install the components your project uses. Provider adapters are registered explicitly;
the agent and harness do not install or register vendor SDKs.

```sh
pnpm add @modelprofile.com/flexharness-providers
```

See the [toolbox usage and migration guide](https://code.foss.global/modelprofile.com/flexharness#readme)
for composition examples and the SmartAI/SmartAgent migration map.

A subscription rejected with `anthropic-ratelimit-unified-status: rejected` fails as a
`ModelLimitError` of kind `usage_limit` that resets at `anthropic-ratelimit-unified-reset` and
names the `5h` or `7d` window with the same reset; any other 429 or `rate_limit_error` fails as
kind `rate_limit` with the `retry-after` delay. `classifyAnthropicLimit` is exported.

## Claude subscription OAuth

`createAnthropicOAuthResolvingConnection({ expectedIdentity, resolveAccess, fetch? })` is an Anthropic API
connection on a Claude subscription OAuth login an account authority holds. Before every request it resolves the
access, checks that the access names the pinned `accountUuid` and `organizationUuid`, and sends the request to
`https://api.anthropic.com/v1/*` only, with `Authorization: Bearer <access token>`, without any `x-api-key`, with
`oauth-2025-04-20` added once to the request's own `anthropic-beta` list, and with the request's
`anthropic-version` or `2023-06-01`; every other header and the body travel unchanged. A 401 for access that
carries a `generation` resolves once more with `rejectedGeneration` and sends the request again; a second 401, or
one for access without a generation, fails with `AnthropicOAuthAuthError` (`status` 401). Pass the connection as
`connection` to `createAnthropicModelProvider().getModel(...)`, or use `connection.settings.fetch` directly to
forward Messages, `count_tokens` and model requests. `createAnthropicOAuthHeaders` and `mergeAnthropicOAuthBeta`
apply the same header rules.

`listAnthropicOAuthModels(access, { signal, fetch })` reads the models a login may use from `GET /v1/models`
(`limit=1000`, following `has_more` with `after_id` across at most ten pages) with the same authentication, as
`{ providerId, modelId, displayName, createdAt?, maxInputTokens?, maxOutputTokens?, efforts?, adaptiveThinking? }`.
`efforts` lists, lowest first, the levels of `ANTHROPIC_EFFORTS` (`low`, `medium`, `high`, `xhigh`, `max`, the AI SDK's
`effort` option) the model's `capabilities.effort` supports, and is empty when it supports none; `adaptiveThinking`
states `capabilities.thinking.types.adaptive`. Both are absent when the capabilities do not state them. A rejected
token fails with `AnthropicOAuthAuthError` (`status` 401); other failures are `AnthropicOAuthModelListError` with
`NETWORK_FAILED`, `HTTP_ERROR` (and `status`) or `PROTOCOL_ERROR`, also for a capability node it reads that has no
boolean `supported`.

## Anthropic API key

`createAnthropicApiKeyConnection({ apiKey, fetch? })` is an Anthropic API connection on an API key from the Claude
Console, for a gateway that holds the key and forwards requests for its clients. It sends the request to
`https://api.anthropic.com/v1/*` only, with `x-api-key: <key>`, without any `Authorization` header, with
`oauth-2025-04-20` and duplicates removed from the request's own `anthropic-beta` list, and with the request's `anthropic-version`
or `2023-06-01`; every other header and the body travel unchanged. A 401 fails with `AnthropicApiKeyAuthError`
(`status` 401); every other status is the caller's. Use it like the OAuth connection, as `connection` of
`createAnthropicModelProvider().getModel(...)` or through `connection.settings.fetch`. `createAnthropicApiKeyHeaders`
applies the same header rules. A caller that only runs a model on its own key passes `apiKey` to the model options
instead.

`listAnthropicApiKeyModels(access, { signal, fetch })` reads the models a key may use, in the shape, paging and
failures of `listAnthropicOAuthModels`, except that a rejected key fails with `AnthropicApiKeyAuthError` (`status`
401).

## Prices and usage

`ANTHROPIC_MODEL_PRICES` holds the Claude API prices of the models Anthropic lists as available, from
https://platform.claude.com/docs/en/about-claude/pricing, checked 2026-10-21, as `IModelPrice` of
`@modelprofile.com/flexharness-models`: tiers `standard` and, for Claude Opus 5.5, Opus 5 and Opus 4.8,
`fast`; 5-minute and 1-hour write rates; Claude Haiku 5.5's two prompt-size bands (up to 100,000 tokens and
above); web search at $10 per 1,000 and web fetch at an explicit zero fee (code execution has no fee, so a call that
used it is refused); and `inference_geo:us` at 1.1× on Claude 4.6 and later.
Priority Tier has no published per-token price and is absent, so a call it served is refused.
`getAnthropicModelPrice(id)` matches the model id or a dated snapshot the model page lists, exactly; any other
id is `undefined`.

`readAnthropicMessagesUsage(usage)` reads a Messages `usage` object raw (for a stream, merged from
`message_start` and the last `message_delta`): `input_tokens` is the uncached input, `cache_creation` splits
the writes into `5m` and `1h`, and writes it does not split are `unknownLifetimeCacheWriteTokens`. The service
is `service_tier`, or `fast` for a standard call whose `speed` is `fast`; any other speed names a service no price
has (`<tier>:speed:<speed>`), so `priceModelCall` refuses it as `unknownService`. An `inference_geo` other than
`global` becomes the surcharge `inference_geo:<value>`, refused as `unknownSurcharge` where the price lacks it; `server_tool_use` counts become `toolCalls`
(`web_search`, `web_fetch`, ...). A usage without `service_tier`, or with a malformed count, throws
`ModelUsageReadError`, and so does a usage with a `usage.iterations` entry other than `message`: an advisor's
`advisor_message` is billed at the advisor model's rates and left out of the top-level counts, so such an answer
cannot be priced. Pass both to `priceModelCall`.

`ANTHROPIC_SERVER_TOOL_PRICES` prices the server tools of a request by their exact `type`, checked 2026-10-22:
`web_search_20250305`, `web_search_20260209` and `web_search_20260318` at $10 per 1,000 searches;
`web_fetch_20250910`, `web_fetch_20260209`, `web_fetch_20260309` and `web_fetch_20260318` at no fee; the
2026 versions also make code execution in that request free (`code_execution: 0`); and
`tool_search_tool_regex_20251119` and `tool_search_tool_bm25_20251119`, which are not metered and cost only the
definitions they load, as input tokens. Any other type is unpriced: later or undated versions (`tool_search_tool_regex`
resolves to whatever version is latest), code execution on its own (billed by container time), the advisor
(`advisor_20260301`) and the MCP connector. `getAnthropicServerToolPrice(type)` matches exactly and is `undefined`
otherwise. `getAnthropicRequestPrice(price, serverToolTypes)` is the model price with the call fees of the server
tools a request declares, or `undefined` when one of them is unpriced; price the request's answers with it:

```typescript
const serverToolTypes = body.tools.filter(isServerTool).map((tool) => tool.type); // client tools are not passed
const price = getAnthropicRequestPrice(getAnthropicModelPrice(answeredModel)!, serverToolTypes);
if (!price) refuse(); // a server tool without a published price
const cost = priceModelCall(price, readAnthropicMessagesUsage(usage));
```

## Issue Reporting and Security

Report issues and security concerns through [community.foss.global](https://community.foss.global).

## License and Legal Information

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.

**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

### Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

### Company Information

Task Venture Capital GmbH<br>
Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
