Skip to content

[All SDKs] Integration tests for OpenRouter media generation #470

@santoshkumarradha

Description

@santoshkumarradha

Summary

Add integration tests for the new OpenRouter media generation features across all three SDKs. Tests should be runnable with a real API key and skipped gracefully when no key is available.

Test Matrix

Modality Model (cheap) SDK Expected Result
Video (text-to-video) alibaba/wan-2.6 ($0.04/s) Python, TS, Go MP4 file in response
Video (image-to-video) alibaba/wan-2.7 Python MP4 from first_frame
Image google/gemini-2.5-flash-image Python, TS, Go PNG/base64 in response
Audio output openai/gpt-audio Python, TS, Go WAV/MP3 audio data

Test Structure

Python (sdk/python/tests/test_openrouter_media.py)

import pytest
import os

pytestmark = [
    pytest.mark.integration,
    pytest.mark.skipif(
        not os.getenv("OPENROUTER_API_KEY"),
        reason="OPENROUTER_API_KEY not set"
    ),
]

@pytest.mark.asyncio
async def test_video_text_to_video():
    """Generate a short video from text prompt."""
    provider = OpenRouterProvider(api_key=os.environ["OPENROUTER_API_KEY"])
    result = await provider.generate_video(
        "A simple red ball bouncing",
        model="alibaba/wan-2.6",
        duration=4,
        resolution="480p",
    )
    assert result.has_video or len(result.files) > 0
    assert result.files[0].mime_type == "video/mp4"

@pytest.mark.asyncio
async def test_video_timeout_handling():
    """Verify timeout raises appropriate error."""
    provider = OpenRouterProvider(api_key=os.environ["OPENROUTER_API_KEY"])
    with pytest.raises((TimeoutError, asyncio.TimeoutError)):
        await provider.generate_video(
            "A complex scene",
            model="alibaba/wan-2.6",
            timeout=1.0,  # Impossibly short
        )

@pytest.mark.asyncio
async def test_image_generation():
    """Generate image via OpenRouter."""
    provider = OpenRouterProvider(api_key=os.environ["OPENROUTER_API_KEY"])
    result = await provider.generate_image(
        "A simple red circle on white background",
        model="google/gemini-2.5-flash-image",
    )
    assert len(result.images) > 0

@pytest.mark.asyncio 
async def test_audio_generation():
    """Generate audio via OpenRouter."""
    provider = OpenRouterProvider(api_key=os.environ["OPENROUTER_API_KEY"])
    result = await provider.generate_audio(
        "Hello world",
        model="openai/gpt-audio",
        voice="alloy",
        format="wav",
    )
    assert result.audio is not None

TypeScript (sdk/typescript/src/ai/__tests__/openrouter-media.test.ts)

Same test cases using vitest/jest with describe.skipIf(!process.env.OPENROUTER_API_KEY).

Go (sdk/go/ai/openrouter_media_test.go)

Same test cases using testing.T with t.Skip("OPENROUTER_API_KEY not set").

Dependencies

Files

File SDK
sdk/python/tests/test_openrouter_media.py Python
sdk/typescript/src/ai/__tests__/openrouter-media.test.ts TypeScript
sdk/go/ai/openrouter_media_test.go Go

Acceptance Criteria

  • Tests skip gracefully when OPENROUTER_API_KEY not set
  • Video gen test produces valid MP4 (check first 4 bytes for ftyp header or non-zero size)
  • Image gen test produces image data (URL or base64)
  • Audio gen test produces audio data
  • Timeout test verifies error handling
  • Tests use cheapest models to minimize cost
  • CI can run these with a secrets-injected API key

Notes for Contributors

Severity: MEDIUM

Use the cheapest models for testing: alibaba/wan-2.6 for video ($0.04/sec, ~4 sec clip = $0.16), google/gemini-2.5-flash-image for images. Keep video prompts simple and durations short (4 seconds max) to minimize cost and generation time.

Mark all tests as @pytest.mark.integration (Python), or equivalent in TS/Go, so they don't run in unit test CI by default.

Metadata

Metadata

Labels

ai-friendlyWell-documented task suitable for AI-assisted developmentarea:aiAI/LLM integrationarea:sdkCross-SDK (Python + Go + TS) parity workenhancementNew feature or requesttestsUnit test improvements and coverage

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions