---
name: forgehand-llm
description: Call GPT-6 Sol or Luna through Forgehand's team-scoped LLM API, configure OpenAI clients, and troubleshoot prepaid credits or token usage.
---

# Forgehand LLM API

Forgehand proxies `gpt-6-sol` and `gpt-6-luna` through Azure. Both models spend from the selected team's shared prepaid USD balance. No GPU session, workspace, SSH key, Azure account, or Azure key is needed. Use the user's Forgehand instance; the default is `https://app.forgehand.app`.

## Connect a client

1. Use **Settings → Access tokens** to create a Forgehand personal access token. Supply it through a secret environment variable such as `FORGEHAND_TOKEN`; never put it in source, output, or chat. An existing Forgehand token works too. `fh login` saves a CLI token but does not export it into Python or shell environments.
2. Select the intended team. `fh whoami --json` returns team UUIDs; authenticated `GET /api/v1/teams` also lists them. Use the full UUID, not a slug or a workspace ID. Confirm the choice if the intended team is ambiguous.
3. In **Usage**, select that team to check available LLM credits and find its API path. New teams start with zero credits. Ask your organizer for credits if the balance is insufficient.
4. Set the OpenAI SDK's `api_key` to the Forgehand token and `base_url` to `<instance>/api/v1/teams/<TEAM_UUID>/llm/v1`. The `fh` CLI has no `llm` command; use the SDK or HTTP API.

With the `openai` Python package installed and `FORGEHAND_TOKEN` and `FORGEHAND_TEAM_ID` set:

```python
import os
from openai import OpenAI

origin = os.getenv("FORGEHAND_URL", "https://app.forgehand.app").rstrip("/")
team = os.environ["FORGEHAND_TEAM_ID"]
client = OpenAI(
    api_key=os.environ["FORGEHAND_TOKEN"],
    base_url=f"{origin}/api/v1/teams/{team}/llm/v1",
    max_retries=0,
)
response = client.responses.create(
    model="gpt-6-luna",  # gpt-6-sol is also available
    input="Explain Bell states in two sentences.",
    max_output_tokens=256,
    reasoning={"effort": "none"},
)
print(response.output_text)
```

Use the user's chosen model. When no model is specified, Luna is the lower-cost option; Sol is intended for more demanding coding and reasoning. Keep output limits explicit. Each call is billable; do not launch repeated probes or automatic retry loops to troubleshoot an ambiguous failure.

## Streaming and API compatibility

Relative to the team base URL: `GET /models`, `POST /responses`, and `POST /chat/completions`. Both generation endpoints accept `stream=True`:

```python
stream = client.chat.completions.create(
    model="gpt-6-sol",
    messages=[{"role": "user", "content": "Say hello."}],
    reasoning_effort="none",
    max_completion_tokens=256,
    stream=True,
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")
```

The proxy requests final usage for chat streams automatically. Chat `max_tokens` aliases `max_completion_tokens`; do not supply both. Chat function calling requires `reasoning_effort="none"`.

Supported: stateless text conversations, custom function tools, structured JSON outputs, streaming. Unsupported: images/files, provider-hosted tools, `previous_response_id`, stored conversations, background jobs, alternate service tiers, and other models. Unknown fields are rejected, not forwarded. Responses use `store=false`; construct text/function history explicitly rather than relying on stored response IDs or forwarding opaque reasoning items.

Limits: 950 KB serialized text/function payload, 100 messages, 32 function definitions, 32,768 output tokens, and a three-minute upstream timeout. An omitted output limit defaults to 4,096. Output limits include reasoning tokens.

## Credits and troubleshooting

Credits are one-time grants, never a monthly reset. Compute spending is separate. Both models consume the same team credit balance at their own configured Global Standard rates. Each request records its price snapshot and input, cached input, cache-write, output, and reasoning tokens. Input includes cached reads and writes; output includes reasoning, so do not add these subcategories again when calculating totals. Above 272,000 input tokens, the full request uses doubled input/cache prices and 1.5× output prices.

**Usage → LLM usage** shows lifetime grants, spend, available credits, holds, per-model tokens, recent requests, and the latest 100 credit grants. Every grant is retained in the ledger even when it is outside this recent list. Authenticated `GET /api/v1/teams/<TEAM_UUID>/llm/usage` returns the same data; money is in micro-USD (1 USD = 1,000,000 micro-USD).

- `401`: missing, expired, or revoked Forgehand token. Verify login; do not substitute an Azure key.
- `403`: the caller is not in the selected team or lacks the required role.
- `400`: invalid/unsupported request fields or Azure rejected the parameters. Check the compatibility limits above.
- `429` with `error.code="limit_reached"`: not enough available team credit to reserve this request. Ask your organizer for more credits or reduce input/output limits. The reservation is conservative and can exceed the final cost.
- Other `429`: upstream rate limit. Honor any retry delay and retry only within the user's intended workload.
- `502`, interrupted streams, or missing usage: check the request ledger before retrying. The proxy retains a hold if Azure may have billed work. Contact support with the request ID; do not assume the request was free.
- `503`: the LLM service is unavailable; contact support.

Available credits = total grants − settled costs − outstanding reservations. Unused reservation is released after final usage arrives. A client disconnect does not guarantee free cancellation: the server continues collecting upstream usage. Correlate successful requests with `x-llm-request-id`; proxy error bodies include the ledger `requestId`.
