Crates.io | openrouter |
lib.rs | openrouter |
version | 0.2.0 |
created_at | 2025-01-26 19:11:48.212843+00 |
updated_at | 2025-05-28 19:24:06.49842+00 |
description | A library to interact with the OpenRouter API. |
homepage | |
repository | https://gitlab.com/bit-refined/openrouter |
max_upload_size | |
id | 1531667 |
size | 711,644 |
This project was created due to a personal need for it. My use-case may not reflect that of everyone else, so features may be missing or could be untested.
Please leave issues if something does not work as expected. You're also encouraged to contribute code if you can!
While OpenRouter can be used with OpenAI compatible clients, those do not offer the whole feature spectrum OpenRouter provides.
Compared to those, this library might have a more opinionated structure though, to make use of compile time features of Rust and generally provide a more ergonomic approach.
Option<T>
have the fields the same defaults as the spec and don't send them if they're the defaultBasically the given OpenAPI and TypeScript definitions that can be found in OpenRouters docs have been converted into Rust types, but there are no extensive tests. There's also a helper type for when you don't have your own HTTP client.
OpenRouter has some usage related documentation, but it isn't perfect yet. I've been informed that this will change soon-ish. In the meantime some implementation or types could be wrong. Where possible tests have been added to verify we receive from the API what the specs say, but that isn't perfect.
All tests that interact with OpenRouter require an OPENROUTER_API_KEY
variable.
It can also be configured in a .env
file.
If possible free endpoints are used, but that may not always be possible
in which case the test will fail for cost reasons.
It is recommended to set up a key with a low credit limit.
The ./responses
directory contains response json either directly
found in the docs or returned by the API. It is either a legacy named json,
or is correctly sorted in the respective directory and given a timestamp name.
Usually there should be a unit test somewhere using it to test parsing.
This library is a private project and not affiliated with OpenRouter, Inc.