Skip to content

feat(openrouter): add with_app_identity and with_app_categories builders for app attribution#1806

Open
jimmiebfulton wants to merge 2 commits into
0xPlaygrounds:mainfrom
anemnez:pr/openrouter-app-identity
Open

feat(openrouter): add with_app_identity and with_app_categories builders for app attribution#1806
jimmiebfulton wants to merge 2 commits into
0xPlaygrounds:mainfrom
anemnez:pr/openrouter-app-identity

Conversation

@jimmiebfulton
Copy link
Copy Markdown
Contributor

@jimmiebfulton jimmiebfulton commented May 23, 2026

Summary

OpenRouter uses the `X-OpenRouter-Title`, `HTTP-Referer`, and `X-OpenRouter-Categories` request headers to identify the calling application in the dashboard activity feed, public rankings page, and marketplace categories.

Changes

  • `client.rs` — adds `ClientBuilder::with_app_identity(title, url)` that sets `X-OpenRouter-Title` and `HTTP-Referer` on every request. `HTTP-Referer` is the primary app identifier required to create an app page on OpenRouter; `X-OpenRouter-Title` sets the display name in the activity feed and rankings.
  • `client.rs` — adds `ClientBuilder::with_app_categories(categories)` that sets `X-OpenRouter-Categories` as a comma-separated list. Categories must be lowercase and hyphen-separated (e.g. `"cli-agent"`, `"ide-extension"`); unrecognized values are silently ignored by OpenRouter.
  • Invalid (non-ASCII) header values are silently skipped, matching existing header-helper behaviour in the codebase.
  • Five tests: headers present after `with_app_identity`, headers absent without it, categories set and absent, and the existing client-init smoke test.

AI Assistance

This implementation was developed with significant AI assistance (Claude). The design and tests were reviewed and validated by the author before submission.

Issue

Fixes #1805

…Referer headers

OpenRouter uses the X-Title and HTTP-Referer request headers to identify the
calling application in the dashboard activity feed and public rankings page.
Without them, all requests appear under the API key with no named app.

Adds `ClientBuilder::with_app_identity(title, url)` that sets both headers on
every request made by the client. The method is callable at any point in the
builder chain (before or after api_key). Invalid header values (non-ASCII
characters) are silently skipped rather than returning an error, matching
the behaviour of header helpers elsewhere in the codebase.

Three tests: headers present after with_app_identity, headers absent without
it, and the existing client-initialization smoke-test.
@Mnwa
Copy link
Copy Markdown
Contributor

Mnwa commented May 25, 2026

Hi! Can you replace x-title with X-OpenRouter-Title and add the X-OpenRouter-Categories header too?
Official doc with allowed headers here: https://openrouter.ai/docs/app-attribution

@jimmiebfulton
Copy link
Copy Markdown
Contributor Author

Hi! Can you replace x-title with X-OpenRouter-Title and add the X-OpenRouter-Categories header too? Official doc with allowed headers here: https://openrouter.ai/docs/app-attribution

Thanks for pointing this out. I'll take a thorough pass at the docs and put together a more comprehensive approach. I'll update the PR tomorrow some time.

@jimmiebfulton
Copy link
Copy Markdown
Contributor Author

@Mnwa Requested changes incorporated.

@jimmiebfulton jimmiebfulton changed the title feat(openrouter): add with_app_identity builder for X-Title and HTTP-Referer headers feat(openrouter): add with_app_identity and with_app_categories builders for app attribution May 25, 2026
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.

feat(openrouter): add with_app_identity builder for X-Title and HTTP-Referer headers

2 participants