Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/openrouter_agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
OpenResponsesResult,
OutputFileSearchCallItem,
OutputFunctionCallItem,
OutputImage,
OutputImageGenerationCallItem,
OutputItems,
OutputMessage,
Expand Down Expand Up @@ -235,6 +234,21 @@ class BeforeCreateRequestHook(Protocol):
def before_create_request(self, hook_ctx: BeforeCreateRequestContext, request: Any) -> Any: ...


# openrouter 1.1.40 renamed OutputImage to CodeInterpreterImageOutput with no
# back-compat alias, and this package's constraint (openrouter>=1.1,<2) spans
# both. The two models are structurally identical (type, url) and this package
# only re-exports the type, so bind whichever name the installed SDK provides
# to keep OutputImage / OutputInputImage stable for consumers.
# Both ignores are load-bearing across the range, not just today: mypy resolves
# against the locked SDK, so exactly one of these two imports is unresolvable at
# any given pin, and which one flips when the lock crosses 1.1.40.
try:
from openrouter.components import OutputImage # type: ignore[attr-defined]
except ImportError: # openrouter >= 1.1.40
from openrouter.components import ( # type: ignore[assignment, no-redef]
CodeInterpreterImageOutput as OutputImage,
)

OutputInputImage = OutputImage

__all__ = [
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_sdk_compat_exports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Guards the public re-exports that the generated SDK has renamed under us.

The package constraint is ``openrouter>=1.1,<2``, so a plain install resolves
whatever 1.1.x is newest. A symbol this package re-exports by name can vanish
inside that range -- openrouter 1.1.40 renamed ``OutputImage`` -- and the
failure mode is an ImportError at ``import openrouter_agent``, i.e. the whole
package, not just the renamed type.
"""

from __future__ import annotations

import openrouter_agent


def test_output_image_is_exported_under_both_names() -> None:
assert openrouter_agent.OutputImage is openrouter_agent.OutputInputImage


def test_output_image_has_the_code_interpreter_image_shape() -> None:
fields = openrouter_agent.OutputImage.model_fields

assert set(fields) == {"type", "url"}


def test_declared_public_api_is_fully_importable() -> None:
missing = [name for name in openrouter_agent.__all__ if not hasattr(openrouter_agent, name)]

assert missing == []
Loading