feat(openrouter): rebuild provider on OpenRouter's OpenAI-compatible API#88
Merged
Merged
Conversation
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>
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. |
Collaborator
|
@brandomr this looks fine to me. The one place Just an FYI, technically 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_urlfrom provider config in OpenAIModel (matching azure'sendpointpattern), 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.