Files
moloapp/src/vendors/media/bfl/bfl.h
T
retoorandClaude Sonnet 5.5 5a0c18d0e0 feat(clients): media: image and video generation across 12 providers behind one job seam
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>
2026-10-25 15:19:43 +01:00

77 lines
3.3 KiB
C++

#pragma once
// Black Forest Labs (FLUX): submit to a model endpoint, poll /v1/get_result.
// Auth is the x-key header. Models are endpoints (flux-2-pro, flux-kontext-pro,
// flux-pro-1.1-ultra, ...), tools are endpoints under /v1/flux-tools/.
#include "vendors/media/bfl/calls.h"
#include "vendors/media/common/client_factory.h"
#include "vendors/media/common/job.h"
#include "vendors/media/common/media_service.h"
namespace molo::media {
class BflClient : public MediaService {
public:
static constexpr const char* kHost = "https://api.bfl.ai";
static constexpr const char* kKeyEnv = "BFL_API_KEY";
explicit BflClient(std::shared_ptr<llm::ApiClient> client) : MediaService(std::move(client), BflCalls::table()) {}
static llm::ApiClientConfig config() { return ClientFactory::header("bfl", kHost, kKeyEnv, "x-key"); }
static std::shared_ptr<BflClient> from_env() {
return std::make_shared<BflClient>(ClientFactory::real(config(), ClientFactory::env({kKeyEnv})));
}
static std::shared_ptr<BflClient> with(std::unique_ptr<clients::Transport> t, const std::string& key) {
return std::make_shared<BflClient>(ClientFactory::with(std::move(t), config(), key));
}
// key = a POST model / tool row ("flux-2-pro", "tools.erase-v1"). Returns {id, polling_url, cost, ...}.
Json submit(const std::string& key, const Json& body, bool confirm);
PreparedCall plan(const std::string& key, const Json& body) const;
Json get_result(const std::string& id);
Json credits();
Json my_finetunes();
Json finetune_details(const std::string& finetune_id);
// Destructive: no default for confirm.
Json delete_finetune(const std::string& finetune_id, bool confirm);
};
class BflImageGenerator : public ImageGenerator {
public:
explicit BflImageGenerator(std::shared_ptr<BflClient> c) : client_(std::move(c)) {}
std::string provider() const override { return "bfl"; }
bool configured() const override { return client_->configured(); }
std::vector<std::string> models() const override;
Json plan(const ImageRequest& request) const override;
JobTicket submit(const ImageRequest& request, bool confirm) override;
JobStatus poll(const JobTicket& ticket) override;
bool cancel(const JobTicket&, bool) override { return false; } // no cancel endpoint
int suggested_poll_ms() const override { return 1500; }
// Maps the BFL status word onto JobState (shared with the video adapter).
static JobState state_of(const std::string& status);
private:
Json body(const ImageRequest& request, std::string& key) const;
std::shared_ptr<BflClient> client_;
};
class BflVideoGenerator : public VideoGenerator {
public:
explicit BflVideoGenerator(std::shared_ptr<BflClient> c) : client_(std::move(c)) {}
std::string provider() const override { return "bfl"; }
bool configured() const override { return client_->configured(); }
std::vector<std::string> models() const override { return {"flux-3-video"}; }
Json plan(const VideoRequest& request) const override;
JobTicket submit(const VideoRequest& request, bool confirm) override;
JobStatus poll(const JobTicket& ticket) override;
bool cancel(const JobTicket&, bool) override { return false; }
int suggested_poll_ms() const override { return 4000; }
private:
Json body(const VideoRequest& request) const;
std::shared_ptr<BflClient> client_;
};
} // namespace molo::media