Skip to content

feat(openrouter): rebuild provider on OpenRouter's OpenAI-compatible API#88

Merged
mattprintz merged 1 commit into
mainfrom
feat/openrouter-openai-compatible
Jul 13, 2026
Merged

feat(openrouter): rebuild provider on OpenRouter's OpenAI-compatible API#88
mattprintz merged 1 commit into
mainfrom
feat/openrouter-openai-compatible

Conversation

@brandomr

@brandomr brandomr commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

The previous OpenRouter provider was a bespoke REST adapter built on toki's old API (toki.Model, toki.openrouter_models), which no longer exists -- the module failed to import, so OpenRouter silently disappeared from provider discovery. OpenRouter speaks the OpenAI chat-completions API (tool calling included), so replace the 219-line adapter with a thin OpenAIModel subclass pointed at the OpenRouter base URL. Context sizes come from OpenRouter's public model listing (cached, with a conservative fallback), and the key is used explicitly -- never round-tripped through OPENAI_API_KEY.

Also forward an optional base_url from provider config in OpenAIModel (matching azure's endpoint pattern), enabling LiteLLM, org gateways, and other OpenAI-compatible endpoints without a dedicated provider class.

toki was only consumed by the old adapter, so the dependency is dropped.

The previous OpenRouter provider was a bespoke REST adapter built on toki's
old API (toki.Model, toki.openrouter_models), which no longer exists -- the
module failed to import, so OpenRouter silently disappeared from provider
discovery. OpenRouter speaks the OpenAI chat-completions API (tool calling
included), so replace the 219-line adapter with a thin OpenAIModel subclass
pointed at the OpenRouter base URL. Context sizes come from OpenRouter's
public model listing (cached, with a conservative fallback), and the key is
used explicitly -- never round-tripped through OPENAI_API_KEY.

Also forward an optional `base_url` from provider config in OpenAIModel
(matching azure's `endpoint` pattern), enabling LiteLLM, org gateways, and
other OpenAI-compatible endpoints without a dedicated provider class.

toki was only consumed by the old adapter, so the dependency is dropped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@mattprintz mattprintz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@brandomr

brandomr commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

@david-andrew when you get a chance, could you scope this out? Can wait til next week just want your eyes on this for any possible issues it may cause your work before we merge it.

@david-andrew

Copy link
Copy Markdown
Collaborator

@brandomr this looks fine to me. The one place archytas.models.openrouter.OpenRouterModel is used is in the OPORD Assistant app, but as long as the interface is the same, it shouldn't matter.

Just an FYI, technically toki still supports openrouter, just a bunch of things got refactored for the 1.0.0 release.
To use, you just need pip install 'toki[openrouter]' (or an entry in the pyproject.toml), and then it can be called like so:

from toki import Agent, OpenRouterModel, get_openrouter_api_key

model = OpenRouterModel("deepseek/deepseek-v3.2", api_key=get_openrouter_api_key())
agent = Agent(model)
agent.add_user_message("Say hello in 5 words")
print(f'openrouter says {agent.execute()}')

But it's probably fine to let archytas stay separate

@mattprintz
mattprintz merged commit dce0ded into main Jul 13, 2026
1 check passed
@mattprintz
mattprintz deleted the feat/openrouter-openai-compatible branch July 13, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants