Stability, BFL, Runway, Luma, Replicate, fal, Ideogram, Recraft, Leonardo, MiniMax, Kling, Higgsfield: call tables checked against vendor specs/SDKs, ImageGenerator/VideoGenerator seam with capped polling, /ai/media demo. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
196 lines
11 KiB
C++
196 lines
11 KiB
C++
#include "vendors/media/common/registry.h"
|
|
|
|
#include <ctime>
|
|
|
|
#include "llm/config.h"
|
|
#include "llm/error.h"
|
|
#include "vendors/media/bfl/bfl.h"
|
|
#include "vendors/media/fal/fal.h"
|
|
#include "vendors/media/higgsfield/higgsfield.h"
|
|
#include "vendors/media/ideogram/ideogram.h"
|
|
#include "vendors/media/kling/kling.h"
|
|
#include "vendors/media/leonardo/leonardo.h"
|
|
#include "vendors/media/luma/luma.h"
|
|
#include "vendors/media/minimax/minimax.h"
|
|
#include "vendors/media/recraft/recraft.h"
|
|
#include "vendors/media/replicate/replicate.h"
|
|
#include "vendors/media/runway/runway.h"
|
|
#include "vendors/media/stability/stability.h"
|
|
|
|
namespace molo::media {
|
|
|
|
const std::vector<ProviderInfo>& MediaRegistry::providers() {
|
|
static const std::vector<ProviderInfo> list = {
|
|
{"stability", "Stability AI", {"STABILITY_API_KEY"}, true, false, Evidence::kOpenApi,
|
|
"https://platform.stability.ai/account/keys", "v1.user.balance",
|
|
"v2beta image (generate, edit, upscale, control), 3D, audio; v1 engines. No video route in the published spec."},
|
|
{"bfl", "Black Forest Labs", {"BFL_API_KEY"}, true, true, Evidence::kOpenApi,
|
|
"https://dashboard.bfl.ai/", "credits", "FLUX models and tools, polling via get_result, fine-tunes."},
|
|
{"replicate", "Replicate", {"REPLICATE_API_TOKEN"}, true, true, Evidence::kOpenApi,
|
|
"https://replicate.com/account/api-tokens", "account.get",
|
|
"Predictions, models, deployments, files, trainings, webhook verification. Any model by owner/name."},
|
|
{"fal", "fal", {"FAL_KEY"}, true, true, Evidence::kOpenApi, "https://fal.ai/dashboard/keys",
|
|
"platform.models.pricing", "Queue API (any endpoint id) and the model-related Platform API."},
|
|
{"ideogram", "Ideogram", {"IDEOGRAM_API_KEY"}, true, true, Evidence::kOpenApi,
|
|
"https://ideogram.ai/manage-api", "account.usage",
|
|
"v2 image, SVG, video and ad tools; dry_run=true gives a free price quote."},
|
|
{"recraft", "Recraft", {"RECRAFT_API_TOKEN"}, true, false, Evidence::kOpenApi,
|
|
"https://www.recraft.ai/profile/api", "users.me", "Generation, vector, background, upscale, styles."},
|
|
{"leonardo", "Leonardo.Ai", {"LEONARDO_API_KEY"}, true, true, Evidence::kDocs,
|
|
"https://app.leonardo.ai/api-access", "v2.models",
|
|
"v2 generations for image, video, audio and 3D models. v1 reference pages are gone from the docs."},
|
|
{"runway", "Runway", {"RUNWAY_API_KEY", "RUNWAYML_API_SECRET"}, true, true, Evidence::kSdk,
|
|
"https://dev.runwayml.com/", "organization.get",
|
|
"Text / image / video generation, tasks, uploads, avatars, voices, documents, routers, workflows."},
|
|
{"luma", "Luma Dream Machine", {"LUMA_API_KEY"}, true, true, Evidence::kSdk,
|
|
"https://lumalabs.ai/api/keys", "credits.get", "Ray video, Photon image, reframe, modify, upscale, audio."},
|
|
{"minimax", "MiniMax Hailuo", {"MINIMAX_API_KEY"}, false, true, Evidence::kDocs,
|
|
"https://platform.minimax.io/user-center/basic-information/interface-key", "",
|
|
"Hailuo video v1 and v2, file retrieval. No free account read exists."},
|
|
{"kling", "Kling AI", {"KLING_ACCESS_KEY", "KLING_SECRET_KEY"}, false, true, Evidence::kProbeOnly,
|
|
"https://app.klingai.com/global/dev/api-key", "",
|
|
"Official API with JWT auth; docs are a JS app with no machine-readable spec: paths are unverified."},
|
|
{"higgsfield", "Higgsfield", {"HF_API_KEY_ID", "HF_API_KEY_SECRET"}, true, true, Evidence::kOpenApi,
|
|
"https://cloud.higgsfield.ai/", "",
|
|
"One lifecycle for every model path; the OpenAPI document is explicitly supplementary."},
|
|
};
|
|
return list;
|
|
}
|
|
|
|
const std::vector<UnsupportedProduct>& MediaRegistry::unsupported() {
|
|
static const std::vector<UnsupportedProduct> list = {
|
|
{"Midjourney",
|
|
"No public API. Midjourney documents only its web and Discord products; third-party relays are unofficial "
|
|
"and violate its terms, so none is implemented."},
|
|
{"Pika",
|
|
"pika.art/api advertises a membership API that resells other vendors' models, but no endpoint, schema or "
|
|
"authentication document was found (2026-10-25), so nothing is implemented. Pika models are reachable "
|
|
"through fal."},
|
|
};
|
|
return list;
|
|
}
|
|
|
|
const ProviderInfo* MediaRegistry::find(const std::string& id) {
|
|
for (const ProviderInfo& p : providers())
|
|
if (p.id == id) return &p;
|
|
return nullptr;
|
|
}
|
|
|
|
const char* MediaRegistry::evidence_name(Evidence e) {
|
|
switch (e) {
|
|
case Evidence::kOpenApi: return "openapi";
|
|
case Evidence::kSdk: return "sdk";
|
|
case Evidence::kDocs: return "docs";
|
|
default: return "probe-only";
|
|
}
|
|
}
|
|
|
|
const CallTable& MediaRegistry::table(const std::string& id) {
|
|
if (id == "stability") return StabilityCalls::table();
|
|
if (id == "bfl") return BflCalls::table();
|
|
if (id == "replicate") return ReplicateCalls::table();
|
|
if (id == "fal") return FalCalls::table();
|
|
if (id == "ideogram") return IdeogramCalls::table();
|
|
if (id == "recraft") return RecraftCalls::table();
|
|
if (id == "leonardo") return LeonardoCalls::table();
|
|
if (id == "runway") return RunwayCalls::table();
|
|
if (id == "luma") return LumaCalls::table();
|
|
if (id == "minimax") return MinimaxCalls::table();
|
|
if (id == "kling") return KlingCalls::table();
|
|
if (id == "higgsfield") return HiggsfieldCalls::table();
|
|
throw llm::ApiError::invalid("media", "unknown provider '" + id + "'");
|
|
}
|
|
|
|
bool MediaRegistry::configured(const std::string& id) {
|
|
const ProviderInfo* p = find(id);
|
|
if (!p) throw llm::ApiError::invalid("media", "unknown provider '" + id + "'");
|
|
if (id == "runway") return !llm::Config::get("RUNWAY_API_KEY").empty() || !llm::Config::get("RUNWAYML_API_SECRET").empty();
|
|
for (const std::string& e : p->env)
|
|
if (llm::Config::get(e.c_str()).empty()) return false;
|
|
return true;
|
|
}
|
|
|
|
std::shared_ptr<MediaService> MediaRegistry::service(const std::string& id, const std::string& key) {
|
|
std::string slot = id;
|
|
if (id == "fal") slot = key.rfind("platform.", 0) == 0 ? "fal.platform" : "fal.queue";
|
|
auto it = services_.find(slot);
|
|
if (it != services_.end()) return it->second;
|
|
std::shared_ptr<MediaService> s;
|
|
if (id == "stability") s = StabilityClient::from_env();
|
|
else if (id == "bfl") s = BflClient::from_env();
|
|
else if (id == "replicate") s = ReplicateClient::from_env();
|
|
else if (id == "fal") s = slot == "fal.platform" ? std::shared_ptr<MediaService>(FalPlatform::from_env())
|
|
: std::shared_ptr<MediaService>(FalQueue::from_env());
|
|
else if (id == "ideogram") s = IdeogramClient::from_env();
|
|
else if (id == "recraft") s = RecraftClient::from_env();
|
|
else if (id == "leonardo") s = LeonardoClient::from_env();
|
|
else if (id == "runway") s = RunwayClient::from_env();
|
|
else if (id == "luma") s = LumaClient::from_env();
|
|
else if (id == "minimax") s = MinimaxClient::from_env();
|
|
else if (id == "kling") s = KlingClient::from_env();
|
|
else if (id == "higgsfield") s = HiggsfieldClient::from_env();
|
|
else throw llm::ApiError::invalid("media", "unknown provider '" + id + "'");
|
|
services_[slot] = s;
|
|
return s;
|
|
}
|
|
|
|
std::shared_ptr<ImageGenerator> MediaRegistry::image(const std::string& id) {
|
|
auto it = images_.find(id);
|
|
if (it != images_.end()) return it->second;
|
|
std::shared_ptr<ImageGenerator> g;
|
|
if (id == "stability") g = std::make_shared<StabilityImageGenerator>(std::static_pointer_cast<StabilityClient>(service(id)));
|
|
else if (id == "bfl") g = std::make_shared<BflImageGenerator>(std::static_pointer_cast<BflClient>(service(id)));
|
|
else if (id == "replicate") g = std::make_shared<ReplicateImageGenerator>(std::static_pointer_cast<ReplicateClient>(service(id)));
|
|
else if (id == "fal") g = std::make_shared<FalImageGenerator>(std::static_pointer_cast<FalQueue>(service(id)));
|
|
else if (id == "ideogram") g = std::make_shared<IdeogramImageGenerator>(std::static_pointer_cast<IdeogramClient>(service(id)));
|
|
else if (id == "recraft") g = std::make_shared<RecraftImageGenerator>(std::static_pointer_cast<RecraftClient>(service(id)));
|
|
else if (id == "leonardo") g = std::make_shared<LeonardoImageGenerator>(std::static_pointer_cast<LeonardoClient>(service(id)));
|
|
else if (id == "runway") g = std::make_shared<RunwayImageGenerator>(std::static_pointer_cast<RunwayClient>(service(id)));
|
|
else if (id == "luma") g = std::make_shared<LumaImageGenerator>(std::static_pointer_cast<LumaClient>(service(id)));
|
|
else if (id == "higgsfield") g = std::make_shared<HiggsfieldImageGenerator>(std::static_pointer_cast<HiggsfieldClient>(service(id)));
|
|
else throw llm::ApiError::invalid("media", "provider '" + id + "' has no image generator");
|
|
images_[id] = g;
|
|
return g;
|
|
}
|
|
|
|
std::shared_ptr<VideoGenerator> MediaRegistry::video(const std::string& id) {
|
|
auto it = videos_.find(id);
|
|
if (it != videos_.end()) return it->second;
|
|
std::shared_ptr<VideoGenerator> g;
|
|
if (id == "bfl") g = std::make_shared<BflVideoGenerator>(std::static_pointer_cast<BflClient>(service(id)));
|
|
else if (id == "replicate") g = std::make_shared<ReplicateVideoGenerator>(std::static_pointer_cast<ReplicateClient>(service(id)));
|
|
else if (id == "fal") g = std::make_shared<FalVideoGenerator>(std::static_pointer_cast<FalQueue>(service(id)));
|
|
else if (id == "ideogram") g = std::make_shared<IdeogramVideoGenerator>(std::static_pointer_cast<IdeogramClient>(service(id)));
|
|
else if (id == "leonardo") g = std::make_shared<LeonardoVideoGenerator>(std::static_pointer_cast<LeonardoClient>(service(id)));
|
|
else if (id == "runway") g = std::make_shared<RunwayVideoGenerator>(std::static_pointer_cast<RunwayClient>(service(id)));
|
|
else if (id == "luma") g = std::make_shared<LumaVideoGenerator>(std::static_pointer_cast<LumaClient>(service(id)));
|
|
else if (id == "minimax") g = std::make_shared<MinimaxVideoGenerator>(std::static_pointer_cast<MinimaxClient>(service(id)));
|
|
else if (id == "kling") g = std::make_shared<KlingVideoGenerator>(std::static_pointer_cast<KlingClient>(service(id)));
|
|
else if (id == "higgsfield") g = std::make_shared<HiggsfieldVideoGenerator>(std::static_pointer_cast<HiggsfieldClient>(service(id)));
|
|
else throw llm::ApiError::invalid("media", "provider '" + id + "' has no video generator");
|
|
videos_[id] = g;
|
|
return g;
|
|
}
|
|
|
|
Json MediaRegistry::account(const std::string& id) {
|
|
const ProviderInfo* p = find(id);
|
|
if (!p) throw llm::ApiError::invalid("media", "unknown provider '" + id + "'");
|
|
if (p->account_key.empty())
|
|
throw llm::ApiError::invalid("media", id + " has no free account read; use a generation poll to prove the credential");
|
|
std::shared_ptr<MediaService> s = service(id, p->account_key);
|
|
CallArgs args;
|
|
if (id == "fal") args.query["endpoint_id"] = "fal-ai/flux/dev";
|
|
if (id == "stability") args.headers["Accept"] = "application/json";
|
|
if (id == "ideogram") { // usage requires start_time (spec: required, date-time)
|
|
std::time_t t = std::time(nullptr) - 24 * 3600;
|
|
std::tm tm{};
|
|
gmtime_r(&t, &tm);
|
|
char buf[32];
|
|
std::strftime(buf, sizeof buf, "%Y-%m-%dT%H:%M:%SZ", &tm);
|
|
args.query["start_time"] = buf;
|
|
}
|
|
return s->call_json(p->account_key, args);
|
|
}
|
|
|
|
} // namespace molo::media
|