Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: finish HypiHub provider guidance and URL compatibility

rpone41ef3db803a4
diff --git a/.agents/skills/hypit/references/runtime.md b/.agents/skills/hypit/references/runtime.md
index 1e368b7c..458fe007 100644
--- a/.agents/skills/hypit/references/runtime.md
+++ b/.agents/skills/hypit/references/runtime.md
@@ -37,26 +37,23 @@ Source change. Continue only after the author has a usable credential and the su
### Give the picture and video models room to run
The generation models are what a Build waits on, and they are the one place concurrency is worth
-setting deliberately. Give Seedance and the image model **10 each**.
-
-On a Provider with per-model lanes — `@hypit/provider-kie` is the usual one — that is a lane apiece
-inside a pool wide enough to hold both, so neither starves the other:
+setting deliberately. Give Seedance and the image model room to run. HypiHub is the default paid
+gateway, so a typical profile looks like this:
```json
-"kie.<project>": {
- "use": "@hypit/provider-kie",
+"hypihub.<project>": {
+ "use": "@hypit/provider-hypihub",
"config": {
- "apiKey": { "store": "env", "key": "KIE_API_KEY" },
- "defaultConcurrency": 20,
- "laneConcurrency": { "seedance-2-mini": 10, "gpt-image-2": 10 }
+ "apiKey": { "store": "env", "key": "HYPIHUB_API_KEY" },
+ "defaultConcurrency": 20
}
}
```
-`defaultConcurrency` is the total pool shared by every lane, so it has to be at least the sum of the
-lanes or the lane numbers are a ceiling nothing reaches. Name the lane by the exact capability the
-Source reaches — `seedance-2-mini` and `gpt-image-2` above — since a lane key that matches no
-capability is silently inert. Read the Provider's README for the lane names it admits.
+`defaultConcurrency` is the total HypiHub pool shared by its model capabilities. Tune it to the
+quota behind the key; the Provider keeps each exact capability in its own lane. An explicit KIE
+profile remains valid when a project deliberately chooses `@hypit/provider-kie`, but it is not the
+default route.
Provider-specific input limits are also part of preflight. For the KIE GPT Image 2 route, do not
submit `4:3`, `3:4` or `4:5`; the route rejects those aspect ratios before upload or paid submission.
diff --git a/packages/provider-hypihub/README.md b/packages/provider-hypihub/README.md
index 639ae0a7..59a5fd3a 100644
--- a/packages/provider-hypihub/README.md
+++ b/packages/provider-hypihub/README.md
@@ -1,6 +1,6 @@
# `@hypit/provider-hypihub`
-Thin Hypit Runtime Provider for a HypiHub `/v1` deployment. It is an optional default gateway for
+Thin Hypit Runtime Provider for a HypiHub deployment. It is an optional default gateway for
paid generation and Gemini VLM requests; callers may keep their own Provider and select HypiHub only
when its key is configured.
@@ -20,7 +20,7 @@ Runtime Profile example:
"use": "@hypit/provider-hypihub",
"pool": "hypihub.default",
"config": {
- "baseUrl": "https://hypit.ai/v1",
+ "baseUrl": "https://hypit.ai",
"apiKey": { "store": "env", "key": "HYPIHUB_API_KEY" },
"defaultConcurrency": 4
}
@@ -30,5 +30,8 @@ Runtime Profile example:
```
Gemini VLM callers can use the exported `createHypiHubGeminiGenerator` without changing their
-provider-facing code. Set `HYPIHUB_API_KEY` (and optionally `HYPIHUB_BASE_URL`) only when choosing
-HypiHub; missing or insufficient user credentials should be resolved at [hypit.ai](https://hypit.ai).
+provider-facing code. Set `HYPIHUB_API_KEY` (and optionally `HYPIHUB_BASE_URL`; either the origin or
+an existing `/v1`/`/v1beta` base is accepted) only when choosing HypiHub. The Runtime Provider also
+accepts the origin or either versioned base and normalizes it to `/v1`; missing or insufficient user
+credentials should be resolved at [hypit.ai](https://hypit.ai). Video/audio reference artifacts need
+an operator-supplied `publicAssetUrl` callback because HypiHub must fetch those references over HTTPS.
diff --git a/packages/provider-hypihub/src/gemini.ts b/packages/provider-hypihub/src/gemini.ts
index f8fbe78d..b744f8b1 100644
--- a/packages/provider-hypihub/src/gemini.ts
+++ b/packages/provider-hypihub/src/gemini.ts
@@ -33,7 +33,12 @@ function partValue(part: HypiHubGeminiPart): Record<string, unknown> {
export function createHypiHubGeminiGenerator(options: HypiHubGeminiGeneratorOptions) {
const apiKey = options.apiKey.trim();
assert(apiKey.length > 0, "HypiHub API key is empty");
- const baseUrl = (options.baseUrl ?? "https://hypit.ai").replace(/\/$/u, "");
+ // The native Gemini endpoint lives at /v1beta while the paid image/video
+ // client lives at /v1. Accept either commonly configured HypiHub base URL
+ // and strip only the version suffix before adding /v1beta below.
+ const baseUrl = (options.baseUrl ?? "https://hypit.ai")
+ .replace(/\/(?:v1beta|v1)\/?$/iu, "")
+ .replace(/\/$/u, "");
const model = options.model?.trim() || "gemini-3.1-pro-preview";
const timeout = options.requestTimeoutMs ?? 120_000;
const fetcher = options.fetch ?? globalThis.fetch;
@@ -53,7 +58,13 @@ export function createHypiHubGeminiGenerator(options: HypiHubGeminiGeneratorOpti
}),
});
const text = await response.text();
- if (!response.ok) throw new Error(`HypiHub Gemini returned HTTP ${response.status}: ${text.slice(0, 300)}`);
+ if (!response.ok) {
+ const message = `HypiHub Gemini returned HTTP ${response.status}: ${text.slice(0, 300)}`;
+ if (response.status === 401 || response.status === 403 || response.status === 404) {
+ throw new Error(`${message}. Get a HypiHub key with this model enabled at https://hypit.ai`);
+ }
+ throw new Error(message);
+ }
let body: unknown;
try { body = JSON.parse(text); } catch { throw new Error("HypiHub Gemini returned invalid JSON"); }
const candidates = (body as { readonly candidates?: readonly { readonly content?: { readonly parts?: readonly { readonly text?: unknown }[] } }[] }).candidates;
diff --git a/packages/provider-hypihub/src/provider.ts b/packages/provider-hypihub/src/provider.ts
index 99fcd978..a5f2cb79 100644
--- a/packages/provider-hypihub/src/provider.ts
+++ b/packages/provider-hypihub/src/provider.ts
@@ -29,13 +29,26 @@ function object(value: unknown, subject: string): Record<string, unknown> {
return value as Record<string, unknown>;
}
function capabilityKey(capability: CapabilityRef): string { return `${capability.module.name}@${capability.module.version}#${capability.name}`; }
+function apiBaseUrl(value: string): string {
+ const trimmed = value.trim().replace(/\/+$/u, "");
+ assert(trimmed.length > 0, "HypiHub base URL is empty");
+ const origin = trimmed.replace(/\/(?:v1beta|v1)$/iu, "");
+ return `${origin}/v1`;
+}
function credential(context: EndpointInvocationContext): string {
const value = context.credentials.apiKey?.secret;
assert(typeof value === "string" && value.length > 0, "HypiHub API key is unavailable");
return value;
}
+function guidedMessage(error: unknown): string {
+ const message = error instanceof Error ? error.message : String(error);
+ return /API key is unavailable|HTTP (?:401|403|404)\b|not enabled for|model_not_found|no_capable_provider/iu.test(message)
+ ? `${message}. Get a HypiHub key with this model enabled at https://hypit.ai`
+ : message;
+}
function failure(error: unknown): EndpointOutcome {
- return { status: "failed", failure: { code: "HYPIHUB_ERROR", message: error instanceof Error ? error.message : String(error) } };
+ const message = guidedMessage(error);
+ return { status: "failed", failure: { code: "HYPIHUB_ERROR", message } };
}
function jobId(value: Record<string, unknown>): string {
const id = value.id ?? value.job_id;
@@ -160,9 +173,15 @@ function endpoint(client: HypiHubClient, pollIntervalMs: number, maxOperationMs:
}
export function createHypiHubProvider(options: CreateHypiHubProviderOptions = {}) {
- const client = new HypiHubClient({ baseUrl: options.baseUrl ?? "https://hypit.ai/v1", timeout: options.requestTimeoutMs ?? 30_000, fetcher: options.fetch ?? globalThis.fetch });
+ const client = new HypiHubClient({ baseUrl: apiBaseUrl(options.baseUrl ?? "https://hypit.ai/v1"), timeout: options.requestTimeoutMs ?? 30_000, fetcher: options.fetch ?? globalThis.fetch });
const asyncEndpoint = endpoint(client, options.pollIntervalMs ?? 5_000, 20 * 60_000, options.publicAssetUrl);
- const audioEndpoint: ImmediateEndpointHandler = (context) => synthesizeAudio(client, context, options.publicAssetUrl);
+ const audioEndpoint: ImmediateEndpointHandler = async (context) => {
+ try {
+ return await synthesizeAudio(client, context, options.publicAssetUrl);
+ } catch (error) {
+ throw new Error(guidedMessage(error), { cause: error });
+ }
+ };
return defineEndpointPackage({
module: hypiHubProviderModuleRef, facet: "gateway", instance: options.instance ?? "hypihub.default", pool: options.pool ?? options.instance ?? "hypihub.default",
credentials: { apiKey: options.apiKey ?? credentialRef("env", "HYPIHUB_API_KEY") }, credentialInputs: { apiKey: { label: "HypiHub API key" } }, defaultConcurrency: options.defaultConcurrency ?? 4,
diff --git a/packages/provider-hypihub/test/gemini.test.ts b/packages/provider-hypihub/test/gemini.test.ts
new file mode 100644
index 00000000..9643787d
--- /dev/null
+++ b/packages/provider-hypihub/test/gemini.test.ts
@@ -0,0 +1,40 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { createHypiHubGeminiGenerator } from "../src/gemini.js";
+
+test("HypiHub Gemini uses native wire format for text, image and video parts", async () => {
+ let seenUrl = "";
+ let seenBody: Record<string, unknown> | undefined;
+ const generate = createHypiHubGeminiGenerator({
+ apiKey: "test-key",
+ model: "gemini-3.7-flash",
+ baseUrl: "https://hypit.ai/v1",
+ fetch: async (input, init) => {
+ seenUrl = String(input);
+ seenBody = JSON.parse(String(init?.body)) as Record<string, unknown>;
+ return Response.json({ candidates: [{ content: { parts: [{ text: "OK" }] } }] });
+ },
+ });
+
+ assert.equal(await generate({ instruction: "Answer briefly.", parts: [
+ { text: "inspect" },
+ { inlineData: { mimeType: "image/png", data: "aW1hZ2U=" } },
+ { inlineData: { mimeType: "video/mp4", data: "dmlkZW8=" } },
+ ] }), "OK");
+ assert.equal(seenUrl, "https://hypit.ai/v1beta/models/gemini-3.7-flash:generateContent");
+ assert.deepEqual(seenBody?.contents, [{ role: "user", parts: [
+ { text: "inspect" },
+ { inlineData: { mimeType: "image/png", data: "aW1hZ2U=" } },
+ { inlineData: { mimeType: "video/mp4", data: "dmlkZW8=" } },
+ ] }]);
+});
+
+test("HypiHub Gemini points unavailable models to HypiHub", async () => {
+ const generate = createHypiHubGeminiGenerator({
+ apiKey: "test-key",
+ fetch: async () => new Response("missing", { status: 404 }),
+ });
+ await assert.rejects(() => generate({ instruction: "x", parts: [{ text: "x" }] }),
+ /get a HypiHub key with this model enabled at https:\/\/hypit\.ai/iu);
+});
diff --git a/packages/reference-video-tools/src/tools.ts b/packages/reference-video-tools/src/tools.ts
index 628ff16a..50bebd8c 100644
--- a/packages/reference-video-tools/src/tools.ts
+++ b/packages/reference-video-tools/src/tools.ts
@@ -807,7 +807,7 @@ async function defaultGenerate(model: string): Promise<GenerateText> {
return await generate({ parts: parts as unknown as Parameters<typeof generate>[0]["parts"], instruction });
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
- if (/HTTP (401|403|404)\b|model_not_found|no_capable_provider/iu.test(message)) {
+ if (!/hypit\.ai/iu.test(message) && /HTTP (401|403|404)\b|model_not_found|no_capable_provider/iu.test(message)) {
throw new Error(`${message}. This Gemini model is not available with the configured key; get a HypiHub key at https://hypit.ai`);
}
throw error;
@@ -825,7 +825,17 @@ async function defaultGenerate(model: string): Promise<GenerateText> {
model,
location: process.env.GOOGLE_CLOUD_LOCATION?.trim() || "global",
});
- return async ({ parts, instruction }) => generate({ parts, instruction });
+ return async ({ parts, instruction }) => {
+ try {
+ return await generate({ parts, instruction });
+ } catch (error) {
+ const message = error instanceof Error ? error.message : String(error);
+ if (!/hypit\.ai/iu.test(message) && /\b(?:401|403|404)\b|permission denied|unauthenticated|not found|failed precondition/iu.test(message)) {
+ throw new Error(`${message}. This Gemini model or Vertex credential is unavailable; get a HypiHub key at https://hypit.ai`);
+ }
+ throw error;
+ }
+ };
}
const MIME_TYPES: Readonly<Record<string, string>> = {