Skip to content

0.6.0

Choose a tag to compare

@frostming frostming released this 20 Oct 06:41
fdaddc5

Republic 0.6 is a ground-up rewrite. It is now a focused provider library: one async interface over AI services, with gateways, agent loops, and tool execution left to the caller.

This release includes everything from 0.6.0a1 and 0.6.0a2, plus image models and call extensions.

pip install republic==0.6.0
import republic

model = republic.get_model("openai:gpt-6-sol")  # reads REPUBLIC_OPENAI_API_KEY
response = await model.chat("Hello, how are you?")

async with model.stream("Tell me a story", reasoning_effort="high") as stream:
    async for event in stream:
        if isinstance(event, republic.events.TextDelta):
            print(event.chunk, end="")

⚠️ Breaking changes from 0.5.x

  • The 0.5.x API has been removed (#58). Republic no longer wraps any-llm-sdk; it talks to providers directly over httpx2. Code written against 0.5.x needs to be ported. See the quickstart and the Provider API reference.
  • Error classes now live in republic.errors rather than at the package top level.
  • Tool results are tool messages built with republic.tool(call, *content, is_error=False), replacing ToolResult, republic.tool_result(), and assistant(tool_results=...) (#79).

Highlights

  • Provider API (#61): get_model(), get_embedding_model(), get_decision_model(), streaming events, structured output, tool calling, and register_provider() for custom providers. Each model picks a native API format (responses, messages, gemini, chat, …) and lets you override it with api_format=.
  • 17 providers: OpenAI, Anthropic, Google Gemini (alias gemini), OpenRouter, Azure OpenAI, DeepSeek, MiniMax, Mistral, Moonshot, Together AI, Z.ai, Magpie, Ollama, TypeSafe, Codex, GitHub Copilot, and Grok (#61, #72, #69).
  • Authentication: OAuth for Codex, GitHub Copilot, and Grok CLI, plus OpenRouter PKCE login (#61, #69, #70).
  • Model listing: Provider.list_models() returns ModelInfo across all pages (#75).
  • Reliability (#76): retries with jittered exponential backoff and Retry-After support (max_retries, retry_delay, max_retry_delay). headers and request_id are exposed on responses, streams, and errors. Truncated streams raise StreamIncompleteError instead of producing a silently incomplete response.
  • Connection reuse (#78): each Provider keeps a single HTTP client that its models share, with close() and async context-manager support.
  • Multimodal input: images, video, and audio (republic.audio()) parts (#77). Tool results can mix text and media (#79).
  • Serialization: Message.to_dict() / Message.from_dict() round-trip messages through JSON (#79).
  • Ships a py.typed marker for downstream type checking.

New since 0.6.0a2

  • Image models (#82): generate and edit images with get_image_model().

    model = republic.get_image_model("openai:gpt-image-2")  # or "google:MODEL_ID"
    response = await model.generate("A watercolor fox", size="1024x1024", quality="high")
    response = await model.edit("Give it a scarf", [republic.image("fox.png")], mask=republic.image("mask.png"))
    response.image_parts  # list[republic.Image], inline data or URLs
    response.images       # decoded with Pillow (pip install "republic[image]")

    OpenAI and Azure OpenAI use the images format (Azure edits are sent as multipart form data); Google uses the new gemini_image format. Options include n, size, aspect_ratio, quality, background, output_format, output_compression, and moderation. A format raises UnsupportedFeatureError for options it cannot express. Streaming partial images is not supported yet.

  • Call extensions (#83): subclass republic.extensions.Extension and pass instances through extensions= on a Provider or model factory to observe chat, streaming, embedding, image, decision, and model-listing calls. on_start() returns per-call state that is passed to on_retry() and on_finish(), so overlapping calls can be tracked independently. A failing callback is logged and does not change the call's result or error.

    from republic.extensions import Extension
    
    class CallLog(Extension):
        def on_start(self, provider, operation, model):
            return f"{provider}:{model or operation}"
    
        def on_finish(self, context, response, error):
            print(context, "failed" if error else "ok")
    
    model = republic.get_model("openai:gpt-6-sol", extensions=[CallLog()])

Fixes and changes in the pre-releases

  • Messages format keeps assistant block order (#81). Assistant turns that interleave text, tool uses, and round-tripped provider blocks (such as thinking, server_tool_use, and web_search_tool_result) are replayed in their original order. Anthropic-compatible APIs like DeepSeek's reject the old order in thinking mode.
  • Magpie sends a default key. The magpie provider sends Authorization: Bearer magpie by default, so a local gateway works without any key configuration. Pass api_key= or auth= to override it.

Documentation

Documentation lives at https://getrepublic.org, with a page for each provider plus guides to authentication, tool use, a minimal agent loop, structured output, image models, and extensions (#71, #73, #74, #82, #83). The site is built with Zensical (#80).

Full Changelog: 0.5.8...0.6.0


   🚀 Features

   🐞 Bug Fixes

    View changes on GitHub