@@ -21,10 +21,11 @@ Example:
2121 process . exit ( 1 ) ;
2222}
2323
24+ const geminiApiKey = process . env . GEMINI_API_KEY ;
2425const openRouterKey = process . env . OPENROUTER_API_KEY ;
2526
26- if ( ! openRouterKey ) {
27- console . error ( "Error: OPENROUTER_API_KEY environment variable is required." ) ;
27+ if ( ! geminiApiKey && ! openRouterKey ) {
28+ console . error ( "Error: Either GEMINI_API_KEY or OPENROUTER_API_KEY environment variable is required." ) ;
2829 process . exit ( 1 ) ;
2930}
3031
@@ -75,35 +76,59 @@ Provide 2-3 exact TypeScript or motion graphic prompt specifications that can be
7576` ;
7677
7778async function run ( ) {
78- console . log ( `\n🚀 Generating Cleo-style / Better Stack Storyboard for: "${ topic } "\nUsing Gemini 1 .5 Pro...\n` ) ;
79+ console . log ( `\n🚀 Generating Cleo-style / Better Stack Storyboard for: "${ topic } "\nUsing Gemini 2 .5 Pro (Google AI) ...\n` ) ;
7980
8081 try {
81- const response = await fetch ( "https://openrouter.ai/api/v1/chat/completions" , {
82- method : "POST" ,
83- headers : {
84- "Authorization" : `Bearer ${ openRouterKey } ` ,
85- "Content-Type" : "application/json" ,
86- "HTTP-Referer" : "https://codingcat.dev" ,
87- "X-Title" : "CodingCat Video Storyboard Generator" ,
88- } ,
89- body : JSON . stringify ( {
90- model : "google/gemini-pro-1.5" ,
91- messages : [
92- { role : "system" , content : SYSTEM_PROMPT } ,
93- { role : "user" , content : `Create a complete video storyboard and script for: ${ topic } ` } ,
94- ] ,
95- temperature : 0.7 ,
96- } ) ,
97- } ) ;
98-
99- if ( ! response . ok ) {
100- const err = await response . text ( ) ;
101- throw new Error ( `OpenRouter API error (${ response . status } ): ${ err } ` ) ;
82+ let result = "" ;
83+
84+ if ( geminiApiKey ) {
85+ // Use official Google Gemini 2.5 Pro via Google AI
86+ const res = await fetch ( `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-pro:generateContent?key=${ geminiApiKey } ` , {
87+ method : "POST" ,
88+ headers : { "Content-Type" : "application/json" } ,
89+ body : JSON . stringify ( {
90+ system_instruction : { parts : [ { text : SYSTEM_PROMPT } ] } ,
91+ contents : [ { parts : [ { text : `Create a complete video storyboard and script for: ${ topic } ` } ] } ] ,
92+ generationConfig : { temperature : 0.7 }
93+ } )
94+ } ) ;
95+
96+ if ( ! res . ok ) {
97+ const err = await res . text ( ) ;
98+ throw new Error ( `Google Gemini API error (${ res . status } ): ${ err } ` ) ;
99+ }
100+
101+ const data = await res . json ( ) ;
102+ result = data . candidates ?. [ 0 ] ?. content ?. parts ?. [ 0 ] ?. text ;
103+ } else {
104+ // Use OpenRouter with gemini-2.5-pro
105+ const response = await fetch ( "https://openrouter.ai/api/v1/chat/completions" , {
106+ method : "POST" ,
107+ headers : {
108+ "Authorization" : `Bearer ${ openRouterKey } ` ,
109+ "Content-Type" : "application/json" ,
110+ "HTTP-Referer" : "https://codingcat.dev" ,
111+ "X-Title" : "CodingCat Video Storyboard Generator" ,
112+ } ,
113+ body : JSON . stringify ( {
114+ model : "google/gemini-2.5-pro" ,
115+ messages : [
116+ { role : "system" , content : SYSTEM_PROMPT } ,
117+ { role : "user" , content : `Create a complete video storyboard and script for: ${ topic } ` } ,
118+ ] ,
119+ temperature : 0.7 ,
120+ } ) ,
121+ } ) ;
122+
123+ if ( ! response . ok ) {
124+ const err = await response . text ( ) ;
125+ throw new Error ( `OpenRouter API error (${ response . status } ): ${ err } ` ) ;
126+ }
127+
128+ const data = await response . json ( ) ;
129+ result = data . choices ?. [ 0 ] ?. message ?. content ;
102130 }
103131
104- const data = await response . json ( ) ;
105- const result = data . choices ?. [ 0 ] ?. message ?. content ;
106-
107132 console . log ( result ) ;
108133 } catch ( err ) {
109134 console . error ( "Generation failed:" , err . message ) ;
0 commit comments