---
name: anyhost-model-api
description: "Integrate model inference into an application deployed on Anyhost. Use when adding or changing model calls, model selection, streaming, tool calls, structured output, error handling, usage display, or Generation settlement through the Anyhost Model API."
---

# Anyhost Model API

Use this skill in the user's application repository. Use the sibling `anyhost`
skill for Resource creation, budgets, deployment, and operational work.

## Establish The Contract

1. Inspect the application language, framework, existing model client, and tests.
2. Read `references/integration.md` completely before changing application code.
3. If current Anyhost state matters, run `anyhost context` and
   `anyhost model status -e <env>` through the `anyhost` skill.
4. Treat `GET <ANYHOST_MODEL_API_BASE_URL>/models` as the canonical model list.
   Model IDs and display names preserve recognizable developer and model identity,
   but always copy the exact returned ID instead of deriving it from the name.
5. Keep protocol behavior aligned with the released Anyhost endpoints and public
   OpenAPI. Do not add an undocumented compatibility promise.

## Implement

- Read only `ANYHOST_MODEL_API_KEY`, `ANYHOST_MODEL_API_BASE_URL`, and
  `ANYHOST_MODEL_API_RESOURCE_ID` from the runtime environment.
- Configure the application client explicitly. Never alias the Runtime Key to a
  provider-branded variable or place it in source, client-side bundles, logs,
  traces, fixtures, or error messages.
- Choose `/chat/completions`, `/responses`, or `/messages` according to the
  application's existing protocol needs. Preserve supported content, streaming,
  tools, and structured output without converting every protocol to one shape.
- Let the caller decide whether to retry. Do not add an automatic inference retry
  or content-level deduplication unless the user explicitly requests a policy and
  accepts that each retry creates a new billable Generation.
- Preserve `x-anyhost-generation-id`. Display final `usage.cost` and
  `usage.credits` only when `settlement_status` is `settled`; otherwise query the
  Generation endpoint later.
- Keep model input and output out of persistent logs and analytics by default.

## Verify

1. Test request construction, response parsing, stream termination, tool data, and
   both settled and pending usage with local mocks.
2. Verify failures for missing configuration, invalid keys, unavailable models,
   insufficient credits, budgets, upstream failure, and caller cancellation.
3. If the user asks to deploy, return to the `anyhost` skill, obtain required
   production confirmation, deploy, then verify the real application path.
4. Report the protocol and Catalog Model ID used, tests performed, settlement
   handling, and any released capability the application still does not support.
