vault backup: 2026-04-24 18:06:45

This commit is contained in:
Vadym Samoilenko 2026-04-24 18:06:45 +01:00
parent 690a24688d
commit 0f51bf0525
4 changed files with 187 additions and 0 deletions

View file

@ -89,6 +89,10 @@ cd backend && composer install && php -S localhost:5015 # :5015
```
## Sessions
### 2026-04-24 Fix generation failures for Veo and
**Asked:** Fix generation failures for Veo and Kling API errors and push changes to git.
**Done:** Committed and pushed all changes to git, then updated Obsidian wiki in parallel.
### 2026-04-24 Fix API validation check for generated
**Asked:** Fix API validation check for generated videos endpoint in VideoGenTab.
**Done:** Updated validation logic to match corrected API URL path and pushed changes to git.
@ -201,6 +205,7 @@ cd backend && composer install && php -S localhost:5015 # :5015
## Change Log
| Date | Requested | Changed | Files |
|------|-----------|---------|-------|
| 2026-04-24 | API error fixes, git push | JSON parsing error handling, rate limit handling, wiki documentation | veo-generation.ts, kling-api.ts, wiki-docs.md |
| 2026-04-24 | Logo update | API endpoint validation check, frontend rebuild | VideoGenTab.jsx, deploy-optical.sh |
| 2026-04-24 | Fix nginx 502 and add GD extension | Dockerfile GD extension, deploy script setup, environment variables | Dockerfile, deploy-optical.sh, backend/.env.optical |
| 2026-04-24 | Docker configuration fixes | Added GD extension (libpng), PHP container rebuild required | docker/Dockerfile |

View file

@ -299,3 +299,6 @@ tags: [daily]
- 17:58 (6min) | `semblance`
- **Asked:** Check if the codebase has user management and token cost tracking by project/user, and create an implementation plan if missing.
- **Done:** Analyzed codebase structure and identified missing token cost tracking; created implementation plan requiring cost configuration for supported models.
- 18:05 | `cinema-studio-pro-kling`
- **Asked:** Fix generation failures for Veo and Kling API errors and push changes to git.
- **Done:** Committed and pushed all changes to git, then updated Obsidian wiki in parallel.

View file

@ -23,6 +23,7 @@ Recurring technology stacks used across Oliver Agency projects. Each article cov
| [[wiki/tech-patterns/box-api-integration\|box-api-integration]] | Box API for client asset workflows | Ford QC, Ford SFTP, L'Oréal, Ferrero |
| [[wiki/tech-patterns/one2edit-api\|one2edit-api]] | One2Edit translation platform API | 3M Portal, H&M O2E Tool |
| [[wiki/tech-patterns/nodejs-vanilla-proxy\|nodejs-vanilla-proxy]] | Node.js + Vanilla JS lightweight proxy tools | 3M Portal, Ferrero, Homepage |
| [[wiki/tech-patterns/kling-veo-video-api\|kling-veo-video-api]] | Kling AI + Google Veo 3.1 video generation — camera control, I2V, polling | Cinema Studio Pro |
## Quick Decision Guide

View file

@ -0,0 +1,178 @@
---
title: Kling AI & Veo 3.1 Video Generation API
tags: [kling, veo, video-generation, php, api]
updated: 2026-04-24
---
# Kling AI & Google Veo 3.1 — API Integration Patterns
Used in: **cinema-studio-pro-kling** (optical-prod.oliver.solutions/lux-studio/)
---
## Kling AI API
**Base URL:** `https://api-singapore.klingai.com`
**Auth:** HS256 JWT — `{ iss: accessKey, exp: now+1800, nbf: now-5 }` signed with secretKey
### Text-to-Video — `/v1/videos/text2video`
```json
{
"prompt": "string (required)",
"model_name": "kling-v2-6",
"mode": "std",
"duration": 5,
"aspect_ratio": "16:9",
"cfg_scale": 0.5,
"negative_prompt": "...",
"sound": "on",
"camera_control": { ... }
}
```
### Image-to-Video — `/v1/videos/image2video`
```json
{
"model_name": "kling-v2-6",
"mode": "std",
"duration": 5,
"aspect_ratio": "16:9",
"cfg_scale": 0.5,
"prompt": "optional",
"image_url": "data:image/jpeg;base64,<base64>",
"image_tail_url": "data:image/jpeg;base64,<base64>"
}
```
> **Critical:** field names are `image_url` / `image_tail_url`, NOT `image` / `image_tail`.
> Value must be a data URI (`data:mime;base64,...`), not plain base64.
### Camera Control
```json
"camera_control": {
"type": "down_back",
"config": { "horizontal": 0, "vertical": 0, "pan": 0, "tilt": 0, "roll": 0, "zoom": 0 }
}
```
**Valid `type` values:** `simple`, `down_back`, `forward_up`, `right_turn_forward`, `left_turn_forward`
> **Bug trap:** `type: "predefined"` is INVALID — the API returns error 1200.
> The preset name IS the type. For preset types, config must still include all 6 fields (set to 0).
> For `simple` type, config values drive actual movement (range -10 to +10).
### Duration
- Always **integer**, never string: `5` or `10` (v1/v2 models)
- Kling v3 supports 315 seconds
### Valid Model Names (official API)
`kling-v1-6`, `kling-v2-6`, `kling-v2-5-turbo`, `kling-v2-1-master`, `kling-v3`
### Status Polling — `/v1/videos/{type}/{taskId}`
- `task_status`: `submitted``processing``succeed` / `failed`
- On `succeed`: `task_result.videos[0].url` — CDN URL (temporary, must download immediately)
- Downloaded videos stored at `/var/www/html/lux-studio/api/generated_videos/`
- URL returned to frontend: `/lux-studio/api/generated_videos/<filename>`
(nginx serves this path via `try_files` in the `/lux-studio/` location block)
### Lip Sync — `/v1/videos/lip-sync`
```json
{
"input": {
"mode": "audio2video",
"audio_type": "file",
"audio_file": "<base64>",
"video_id": "task_id_of_kling_video"
}
}
```
### Error Codes
| Code | Meaning |
|------|---------|
| 10001004 | Auth failure — check access/secret keys |
| 12001201 | Invalid parameters — check field names and types |
| 13021304 | Rate limit / concurrent task limit / daily limit |
| HTTP 429 | Rate limit |
---
## Google Veo 3.1 API (via Gemini)
**Base URL:** `https://generativelanguage.googleapis.com/v1beta/models`
**Models:** `veo-3.1-generate-preview`, `veo-3.1-fast-generate-preview`
**Auth:** `?key=GEMINI_API_KEY` query param
**Pattern:** Start long-running op → poll until done
### Request Structure
```json
{
"instances": [{
"prompt": "string",
"image": {
"inlineData": { "mimeType": "image/jpeg", "data": "<base64>" }
},
"lastFrame": {
"inlineData": { "mimeType": "image/jpeg", "data": "<base64>" }
}
}],
"parameters": {
"aspectRatio": "16:9",
"durationSeconds": "8",
"resolution": "720p",
"sampleCount": 1,
"personGeneration": "allow_adult"
}
}
```
> **Critical:** Use `inlineData` format (Gemini API), NOT `bytesBase64Encoded` (Vertex AI format).
> `durationSeconds` must be a **string** (`"4"`, `"6"`, `"8"`), not an integer.
### I2V Image Requirements
- `image` field: start frame (first frame)
- `lastFrame` field: end frame for A→B interpolation (requires `durationSeconds: "8"`)
- Image should match requested `aspectRatio` — mismatch can cause `INVALID_ARGUMENT`
- Supported MIME: `image/jpeg`, `image/png`
- The server resizes uploaded images to match aspect ratio using PHP GD before sending
### Person Generation
| Mode | Valid value |
|------|------------|
| T2V | `allow_all` |
| I2V / interpolation | `allow_adult` |
### Duration / Resolution Constraints
- 1080p and 4K require `durationSeconds: "8"`
- `lastFrame` interpolation requires `durationSeconds: "8"`
---
## Docker / PHP Notes
PHP's `post_max_size` and `upload_max_filesize` **cannot** be changed with `ini_set()` at runtime — they must be in `php.ini` / a conf.d file read by php-fpm before request processing.
Set in `docker/Dockerfile`:
```dockerfile
RUN printf "post_max_size = 100M\nupload_max_filesize = 100M\nmemory_limit = 512M\n" \
> /usr/local/etc/php/conf.d/uploads.ini
```
GD extension is required for Veo I2V image resizing:
```dockerfile
RUN apk add --no-cache libpng-dev libjpeg-turbo-dev \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
```