Skip to content

Commit 6bbfa67

Browse files
docs: add a combined oauth2 + models-info example (#23)
Show one provider authenticated by @vymalo/opencode-oauth2 and enriched by @vymalo/opencode-models-info, with the key gotcha called out: list the oauth2 plugin first so its config hook stamps the bearer onto the provider headers before models-info runs its fetch. Added to the top-level README companion section and the package README's Auth composition section. Uses the absolute modelsInfoUrl form for clarity; no models block / Authorization header needed. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4f564f6 commit 6bbfa67

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,32 @@ The expected JSON is commonly called the **OpenRouter shape** (it's what OpenRou
114114

115115
It doesn't depend on the oauth2 plugin — it runs as a `config` hook *after* other plugins, composing with oauth2, static API keys, or no auth. When paired with `@vymalo/opencode-oauth2` ≥ 0.4.0, an OAuth2-protected metadata endpoint works with zero extra config: the oauth2 plugin stamps the cached bearer onto the provider's headers at config time and the metadata fetch inherits it.
116116

117+
### Both plugins together
118+
119+
One provider, authenticated by oauth2 and enriched by models-info. List `@vymalo/opencode-oauth2` **first** so its `config` hook runs before models-info and the bearer is already in place when the metadata fetch happens:
120+
121+
```jsonc
122+
{
123+
"plugin": ["@vymalo/opencode-oauth2", "@vymalo/opencode-models-info"],
124+
"provider": {
125+
"my-provider": {
126+
"npm": "@ai-sdk/openai-compatible",
127+
"options": {
128+
"baseURL": "https://api.example.com/v1",
129+
"oauth2": {
130+
"issuer": "https://auth.example.com",
131+
"clientId": "opencode-client",
132+
"scopes": ["openid", "profile", "offline_access"]
133+
},
134+
"meta": { "modelsInfoUrl": "https://api.example.com/v1/models" }
135+
}
136+
}
137+
}
138+
}
139+
```
140+
141+
What happens on boot: oauth2 authenticates, discovers models from `/v1/models`, and stamps the access token onto the provider's headers; models-info then fetches `modelsInfoUrl` with that token and merges the richer metadata onto the discovered models. No `models` block needed — oauth2 populates it. No `Authorization` header to manage — it's automatic.
142+
117143
Full reference: [`packages/opencode-models-info/README.md`](packages/opencode-models-info/README.md). Behavior, caching, and composition details: [`docs/models-info.md`](docs/models-info.md).
118144

119145
## Federated identity (CI / Kubernetes)

packages/opencode-models-info/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ The plugin sends the union of `options.headers` and `meta.modelsInfoHeaders` (me
8989

9090
If you need a different token for the metadata endpoint than for inference (e.g. a service-account bearer), set it explicitly under `meta.modelsInfoHeaders.Authorization` — it'll override whatever the provider has set.
9191

92+
#### Example: with `@vymalo/opencode-oauth2`
93+
94+
List the oauth2 plugin **first** so its `config` hook runs before this one — that's what puts the bearer on `options.headers` in time for the metadata fetch:
95+
96+
```jsonc
97+
{
98+
"plugin": ["@vymalo/opencode-oauth2", "@vymalo/opencode-models-info"],
99+
"provider": {
100+
"my-provider": {
101+
"npm": "@ai-sdk/openai-compatible",
102+
"options": {
103+
"baseURL": "https://api.example.com/v1",
104+
"oauth2": {
105+
"issuer": "https://auth.example.com",
106+
"clientId": "opencode-client",
107+
"scopes": ["openid", "profile", "offline_access"]
108+
},
109+
"meta": { "modelsInfoUrl": "https://api.example.com/v1/models" }
110+
}
111+
}
112+
}
113+
}
114+
```
115+
116+
oauth2 authenticates the provider and discovers its models; this plugin then fetches `modelsInfoUrl` using the token oauth2 stamped onto the provider headers, and enriches those discovered models. No `models` block and no `Authorization` header to manage — both are handled for you.
117+
92118
### Expected response shape (OpenRouter)
93119

94120
```json

0 commit comments

Comments
 (0)