From 36c27f898121c4e48e438fa159152a6c39198ce9 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 30 Oct 2025 17:57:43 -0400 Subject: [PATCH] need to get video id --- .../upload_image_and_generate_video.rs | 9 ++-- .../_metadata/oct_30/requests_from_rust.txt | 14 +++++++ .../grok_video_gen_chat_conversation.rs | 41 +++++++++++++------ 3 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 crates/api_clients/grok_client/src/requests/video_chat/_metadata/oct_30/requests_from_rust.txt diff --git a/crates/api_clients/grok_client/src/recipes/upload_image_and_generate_video.rs b/crates/api_clients/grok_client/src/recipes/upload_image_and_generate_video.rs index ea406c87d6..9f2ba8e1b1 100644 --- a/crates/api_clients/grok_client/src/recipes/upload_image_and_generate_video.rs +++ b/crates/api_clients/grok_client/src/recipes/upload_image_and_generate_video.rs @@ -152,8 +152,11 @@ mod tests { cookies: &cookies, }).await?; - let image_path = "/Users/bt/Pictures/Zelda 64 Art/FCgYX6tWEAEhpsy.jpg"; - let prompt = "our hero link plunges the sword into the pedestal, the temple is glowing with a blue aura"; + //let image_path = "/Users/bt/Pictures/Zelda 64 Art/FCgYX6tWEAEhpsy.jpg"; + //let prompt = "our hero link plunges the sword into the pedestal, the temple is glowing with a blue aura"; + + let image_path = "/Users/bt/Pictures/Zelda 64 Art/7j8baxv9m8u61.jpg"; + let maybe_prompt = Some("The hero shoots an arrow and the camera zooms out to follow the arrow"); println!("Verification Token: {:?}", secrets.verification_token); println!("Sentry Trace: {:?}", secrets.sentry_trace); @@ -166,7 +169,7 @@ mod tests { let video_result = upload_image_and_generate_video(UploadImageAndGenerateVideo { full_credentials: &credentials, file: FileUploadSpec::Path(image_path), - prompt: Some(prompt), + prompt: maybe_prompt, individual_request_timeout: None, }).await?; diff --git a/crates/api_clients/grok_client/src/requests/video_chat/_metadata/oct_30/requests_from_rust.txt b/crates/api_clients/grok_client/src/requests/video_chat/_metadata/oct_30/requests_from_rust.txt new file mode 100644 index 0000000000..1cd895b207 --- /dev/null +++ b/crates/api_clients/grok_client/src/requests/video_chat/_metadata/oct_30/requests_from_rust.txt @@ -0,0 +1,14 @@ +{"result":{"conversation":{"conversationId":"02ff7c84-32b2-4e0c-9f24-303f1ffd3ede","title":"New conversation","starred":false,"createTime":"2025-10-30T21:44:37.430582Z","modifyTime":"2025-10-30T21:44:37.430898Z","systemPromptName":"","temporary":true,"mediaTypes":[],"workspaces":[],"taskResult":null}}} +{"result":{"response":{"userResponse":{"responseId":"afb171f2-0425-4b0c-b7c4-3321e450d7e4","message":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content The hero shoots an arrow and the camera zooms out to follow the arrow --mode=custom","sender":"human","createTime":"2025-10-30T21:44:37.454212976Z","manual":false,"partial":false,"shared":false,"query":"","queryType":"","webSearchResults":[],"xpostIds":[],"xposts":[],"generatedImageUrls":[],"imageAttachments":[],"fileAttachments":["47f9ebba-7709-4b00-b9cb-7404bf84e720"],"cardAttachmentsJson":[],"fileUris":[],"fileAttachmentsMetadata":[],"isControl":false,"steps":[],"imageEditUris":[],"mediaTypes":[],"webpageUrls":[],"metadata":{"modelConfigOverride":{"modelMap":{"videoGenModelConfig":{"parentPostId":"47f9ebba-7709-4b00-b9cb-7404bf84e720"}}}},"citedWebSearchResults":[],"toolResponses":[],"model":"grok-3","ragResults":[],"citedRagResults":[],"searchProductResults":[]},"isThinking":false,"isSoftStop":false,"responseId":"afb171f2-0425-4b0c-b7c4-3321e450d7e4"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":1,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":5,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":14,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":27,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":40,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":53,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":63,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"streamingVideoGenerationResponse":{"videoId":"c2d026ea-7fed-4e7e-b081-e358fa0257dd","progress":95,"audioUrls":[],"videoPrompt":"The hero shoots an arrow and the camera zooms out to follow the arrow","imageReference":"https://assets.grok.com/users/85980643-ffab-4984-a3de-59a608c47d7f/47f9ebba-7709-4b00-b9cb-7404bf84e720/content","audioTranscripts":[],"moderated":false,"mode":"custom","modelName":"imagine_xdit_1"},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"token":"I generated a video with the prompt: 'The hero shoots an arrow and the camera zooms out to follow the arrow'","isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"token":"","isThinking":false,"isSoftStop":true,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"response":{"modelResponse":{"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d","message":"I generated a video with the prompt: 'The hero shoots an arrow and the camera zooms out to follow the arrow'","sender":"ASSISTANT","createTime":"2025-10-30T21:45:00.017434210Z","parentResponseId":"afb171f2-0425-4b0c-b7c4-3321e450d7e4","manual":false,"partial":false,"shared":false,"query":"","queryType":"","webSearchResults":[],"xpostIds":[],"xposts":[],"generatedImageUrls":[],"imageAttachments":[],"fileAttachments":[],"cardAttachmentsJson":[],"fileUris":[],"fileAttachmentsMetadata":[],"isControl":false,"steps":[],"imageEditUris":[],"mediaTypes":[],"webpageUrls":[],"metadata":{"deepsearchPreset":"","request_metadata":{"effort":"low","mode":"fast","model":"grok-3"},"request_trace_id":"4d76908d4346cdfd3285735eaf5ef4cc"},"citedWebSearchResults":[],"toolResponses":[],"model":"grok-3","requestMetadata":{"model":"grok-3","mode":"MODEL_MODE_FAST","effort":"LOW"},"ragResults":[],"citedRagResults":[],"searchProductResults":[]},"isThinking":false,"isSoftStop":false,"responseId":"708d847f-4516-4dee-8d8d-8b59c4afca6d"}}} +{"result":{"title":{"newTitle":"Video: Hero Shoots Arrow, Camera Zooms"}}} \ No newline at end of file diff --git a/crates/api_clients/grok_client/src/requests/video_chat/grok_video_gen_chat_conversation.rs b/crates/api_clients/grok_client/src/requests/video_chat/grok_video_gen_chat_conversation.rs index fc41068e23..bdebc53659 100644 --- a/crates/api_clients/grok_client/src/requests/video_chat/grok_video_gen_chat_conversation.rs +++ b/crates/api_clients/grok_client/src/requests/video_chat/grok_video_gen_chat_conversation.rs @@ -24,6 +24,7 @@ use wreq_util::Emulation; const CHAT_CONVERSATION_URL: &str = "https://grok.com/rest/app-chat/conversations/new"; /// Request builder +/// NOTE: Without sending a "like" request after generation, the video will likely never render! pub struct GrokVideoGenChatConversationBuilder<'a> { pub file_id: &'a FileId, pub media_type: VideoMediaPostType, @@ -83,24 +84,23 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> { let mut request_builder = client.post(CHAT_CONVERSATION_URL) //.header(PRAGMA, "no-cache") // Not on firefox //.header(CACHE_CONTROL, "no-cache") // Not on firefox + //.header("priority", "u=1, i") // Different on firefox + //.header("sec-ch-ua", "") // NB: NOT IN FIREFOX + //.header("sec-ch-ua-mobile", "") // NB: NOT IN FIREFOX + //.header("sec-ch-ua-platform", "") // NB: NOT IN FIREFOX + //.header("traceparent", "") // TODO: Not sure where this originates .header(USER_AGENT, FIREFOX_143_MAC_USER_AGENT) .header(ACCEPT, "*/*") .header(ACCEPT_LANGUAGE, "en-US,en;q=0.5") .header(ACCEPT_ENCODING, "gzip, deflate, br, zstd") .header(REFERER, "https://grok.com/imagine/favorites") - //.header("traceparent", "") // TODO ?? .header(CONTENT_TYPE, "application/json") .header("x-xai-request-id", xai_request_id) .header("x-statsig-id", x_statsig_id) .header("sentry-trace", sentry_trace_header) .header("baggage", &self.baggage.0) - // TODO: Missing header "traceparent" **** .header(ORIGIN, "https://grok.com") - //.header("priority", "u=1, i") // Different on firefox .header("priority", "u=4") - //.header("sec-ch-ua", "") // TODO / NB: NOT IN FIREFOX - //.header("sec-ch-ua-mobile", "") // TODO / NB: NOT IN FIREFOX - //.header("sec-ch-ua-platform", "") // TODO / NB: NOT IN FIREFOX .header("sec-fetch-dest", "empty") .header("sec-fetch-mode", "cors") .header("sec-fetch-site", "same-origin") @@ -164,6 +164,7 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> { info!("Video Generation Enqueue Status: {:?}", status); + /// TODO: Handle anti-bot detection /// Body: {"error":{"code":7,"message":"Request rejected by anti-bot rules.","details":[]}} let response_body = &response.text() .await @@ -172,7 +173,7 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> { GrokGenericApiError::WreqError(err) })?; - // TODO: Handle unsuccessful request + // TODO: Handle unsuccessful request, cloudflare, etc. if !status.is_success() { warn!("Not successful enqueuing video gen (code: {}) : {:?}", status.as_u16(), response_body); // error!("Upload file request returned an error (code {}) : {:?}", status.as_u16(), response_body); @@ -180,7 +181,7 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> { } // TODO: Just for now... - info!("Video Body: {:?}", response_body); + println!("Video Body: {:?}", response_body); let file_id = parse_video_id(&response_body); @@ -192,16 +193,24 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> { #[cfg(test)] mod tests { + use log::LevelFilter; use super::*; use crate::datatypes::file_upload_spec::FileUploadSpec; use crate::recipes::request_client_secrets::{request_client_secrets, RequestClientSecretsArgs}; use crate::test_utils::get_test_cookies::get_typed_test_cookies; use errors::AnyhowResult; + use crate::test_utils::setup_test_logging::setup_test_logging; + use crate::utils::user_and_file_id_to_video_url::user_and_file_id_to_video_url; #[tokio::test] #[ignore] async fn create_video() -> AnyhowResult<()> { - //setup_test_logging(LevelFilter::Trace); + setup_test_logging(LevelFilter::Info); + + //let file_id = FileId("990ddf90-8f34-42b1-81a5-39c509d62ff7".to_string()); // Mochi + + let image_path = "/Users/bt/Pictures/Zelda 64 Art/7j8baxv9m8u61.jpg"; + let maybe_prompt = Some("The hero shoots an arrow and the camera zooms out to follow the arrow"); let cookies = get_typed_test_cookies()?; @@ -209,10 +218,8 @@ mod tests { cookies: &cookies, }).await?; - //let file_id = FileId("990ddf90-8f34-42b1-81a5-39c509d62ff7".to_string()); // Mochi - let upload_request = GrokUploadFile { - file: FileUploadSpec::Path("/Users/bt/dev/storyteller/storyteller-rust/test_data/image/mochi.jpg"), + file: FileUploadSpec::Path(image_path), cookie: cookies.to_string(), request_timeout: None, }; @@ -230,7 +237,7 @@ mod tests { let request = GrokVideoGenChatConversationBuilder { file_id: &file_id, media_type: VideoMediaPostType::UserUploadedImage, - prompt: Some("dog shakes the glasses off"), + prompt: maybe_prompt, cookie: cookies.as_str(), user_id: &secrets.user_id, @@ -246,6 +253,14 @@ mod tests { let result = request.send().await?; println!("Result: {:?}", result); + + let video_id = result.video_file_id.expect("should have video id"); + + // NOTE: WITHOUT A "LIKE" REQUEST, THIS FILE WILL LIKELY CEASE TO EXIST. + let video_url = user_and_file_id_to_video_url(&secrets.user_id, &video_id, false); + + println!("Video URL: {:?}", video_url); + assert_eq!(1, 2); Ok(()) }