@@ -978,13 +978,16 @@ export const generateImage = async (
978
978
return runtime . getSetting ( "OPENAI_API_KEY" ) ;
979
979
case ModelProviderName . VENICE :
980
980
return runtime . getSetting ( "VENICE_API_KEY" ) ;
981
+ case ModelProviderName . LIVEPEER :
982
+ return runtime . getSetting ( "LIVEPEER_GATEWAY_URL" ) ;
981
983
default :
982
984
// If no specific match, try the fallback chain
983
985
return ( runtime . getSetting ( "HEURIST_API_KEY" ) ??
984
986
runtime . getSetting ( "TOGETHER_API_KEY" ) ??
985
987
runtime . getSetting ( "FAL_API_KEY" ) ??
986
988
runtime . getSetting ( "OPENAI_API_KEY" ) ??
987
- runtime . getSetting ( "VENICE_API_KEY" ) ) ;
989
+ runtime . getSetting ( "VENICE_API_KEY" ) ) ??
990
+ runtime . getSetting ( "LIVEPEER_GATEWAY_URL" ) ;
988
991
}
989
992
} ) ( ) ;
990
993
try {
@@ -1176,6 +1179,62 @@ export const generateImage = async (
1176
1179
} ) ;
1177
1180
1178
1181
return { success : true , data : base64s } ;
1182
+
1183
+ } else if ( runtime . imageModelProvider === ModelProviderName . LIVEPEER ) {
1184
+ if ( ! apiKey ) {
1185
+ throw new Error ( "Livepeer Gateway is not defined" ) ;
1186
+ }
1187
+ try {
1188
+ const baseUrl = new URL ( apiKey ) ;
1189
+ if ( ! baseUrl . protocol . startsWith ( 'http' ) ) {
1190
+ throw new Error ( "Invalid Livepeer Gateway URL protocol" ) ;
1191
+ }
1192
+ const response = await fetch ( `${ baseUrl . toString ( ) } text-to-image` , {
1193
+ method : "POST" ,
1194
+ headers : {
1195
+ "Content-Type" : "application/json"
1196
+ } ,
1197
+ body : JSON . stringify ( {
1198
+ model_id : data . modelId || "ByteDance/SDXL-Lightning" ,
1199
+ prompt : data . prompt ,
1200
+ width : data . width || 1024 ,
1201
+ height : data . height || 1024
1202
+ } )
1203
+ } ) ;
1204
+ const result = await response . json ( ) ;
1205
+ if ( ! result . images ?. length ) {
1206
+ throw new Error ( "No images generated" ) ;
1207
+ }
1208
+ const base64Images = await Promise . all (
1209
+ result . images . map ( async ( image ) => {
1210
+ console . log ( "imageUrl console log" , image . url ) ;
1211
+ let imageUrl ;
1212
+ if ( image . url . includes ( "http" ) ) {
1213
+ imageUrl = image . url ;
1214
+ } else {
1215
+ imageUrl = `${ apiKey } ${ image . url } ` ;
1216
+ }
1217
+ const imageResponse = await fetch ( imageUrl ) ;
1218
+ if ( ! imageResponse . ok ) {
1219
+ throw new Error (
1220
+ `Failed to fetch image: ${ imageResponse . statusText } `
1221
+ ) ;
1222
+ }
1223
+ const blob = await imageResponse . blob ( ) ;
1224
+ const arrayBuffer = await blob . arrayBuffer ( ) ;
1225
+ const base64 = Buffer . from ( arrayBuffer ) . toString ( "base64" ) ;
1226
+ return `data:image/jpeg;base64,${ base64 } ` ;
1227
+ } )
1228
+ ) ;
1229
+ return {
1230
+ success : true ,
1231
+ data : base64Images
1232
+ } ;
1233
+ } catch ( error ) {
1234
+ console . error ( error ) ;
1235
+ return { success : false , error : error } ;
1236
+ }
1237
+
1179
1238
} else {
1180
1239
let targetSize = `${ data . width } x${ data . height } ` ;
1181
1240
if (
0 commit comments