Migrate from OpenRouter
Verification pending
This setup is not yet verified on the deployed MUSCLE Flex beta. Treat it as a starting point. The compatibility matrix records the client version and Flex build once it passes.
Moving an OpenRouter integration to MUSCLE Flex by Adhibita is mostly a base URL and key change. The larger difference is the model field. On OpenRouter you pick a model and can steer the provider. On Flex you send muscle/auto and Flex chooses the best qualified route for each task, so the routing settings go away.
The change
Two lines move the client, and one more changes the model string:
diff
- baseURL: "https://openrouter.ai/api/v1",
- apiKey: process.env.OPENROUTER_API_KEY,
+ baseURL: `${process.env.FLEX_BASE_URL}/v1`,
+ apiKey: process.env.MUSCLE_FLEX_API_KEY,
- model: "<your OpenRouter model id>",
+ model: "muscle/auto",FLEX_BASE_URL holds the base URL from your invitation, without /v1. MUSCLE_FLEX_API_KEY holds a key from the API keys page of the portal.
What maps to what
| On OpenRouter | On Flex |
|---|---|
Base URL https://openrouter.ai/api/v1 | <FLEX_BASE_URL>/v1 |
OPENROUTER_API_KEY | MUSCLE_FLEX_API_KEY |
Any model string, such as vendor/model | muscle/auto |
A models fallback list | Remove it. Flex chooses the route and handles fallback itself. |
The provider object (order, allow_fallbacks, only, ignore, sort) | Remove it. Not needed: Flex routes each request. |
route, transforms | Remove them. |
HTTP-Referer and X-Title headers | Drop them. Flex does not read them. |
response_format | Not offered in the beta. Flex returns 400 unsupported_field for any value, even {"type": "text"}. Omit the field. |
seed, logprobs, frequency_penalty, presence_penalty, n above 1 | Not offered in the beta. Flex returns 400 unsupported_field, even for 0 or false, so omit these fields entirely. n: 1 is accepted. |
stop | Accepted, but not yet guaranteed on every route. See the compatibility matrix. |
| Per-model prices and credits | One prepaid Flex service balance. |
Flex also serves the Anthropic Messages shape at /v1/messages. If part of your code uses an Anthropic SDK, see the Claude Code guide for the base URL and auth pattern.
Steps
1. Set the new variables
bash
# Remove: OPENROUTER_API_KEY
export FLEX_BASE_URL="<FLEX_BASE_URL>"
export MUSCLE_FLEX_API_KEY="<FLEX_API_KEY>"2. Update the client
With the OpenAI SDK:
ts
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: `${process.env.FLEX_BASE_URL}/v1`,
apiKey: process.env.MUSCLE_FLEX_API_KEY,
});
const completion = await client.chat.completions.create({
model: 'muscle/auto',
messages: [{ role: 'user', content: 'Hello!' }],
});With fetch, drop the attribution headers along with the old URL and key:
ts
const response = await fetch(`${process.env.FLEX_BASE_URL}/v1/chat/completions`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.MUSCLE_FLEX_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'muscle/auto',
messages: [{ role: 'user', content: 'Hello!' }],
}),
});Streaming uses the same request with stream: true.
3. Remove what Flex does not use
Delete the routing settings and headers listed in the table above. Where your code depends on a field Flex does not offer in the beta, such as response_format, keep the feature and flag it for follow-up instead of deleting it silently.
4. Verify
Send one small request and read the headers:
bash
curl -i "$FLEX_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $MUSCLE_FLEX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "muscle/auto", "messages": [{"role": "user", "content": "ping"}], "max_tokens": 16}'A 200 with a reply and an X-Request-Id header means the client, key and balance are in place. Keep the request ID if you contact support.
Let your agent do the migration
Copy this prompt into the coding agent that works on the codebase:
text
Migrate this codebase from OpenRouter to MUSCLE Flex.
The migration guide is at https://docs.adhibita.com/migrate/openrouter. Read it first if you can reach it.
1. Find every OpenRouter usage: the base URL https://openrouter.ai/api/v1, the OPENROUTER_API_KEY variable, and the HTTP-Referer and X-Title headers.
2. Point each client at the Flex base URL with /v1 appended. Read the base URL from the FLEX_BASE_URL variable and the key from MUSCLE_FLEX_API_KEY. Drop the HTTP-Referer and X-Title headers.
3. Replace every model string with muscle/auto. Flex chooses the route, so remove OpenRouter routing settings: the provider object, models fallback lists, route and transforms.
4. Find request fields Flex does not accept in the beta: response_format, seed, logprobs, frequency_penalty, presence_penalty, and n greater than 1. Flex rejects them with any value, even 0, false or a default, so remove the field entirely rather than setting it to a default. List each feature that depended on it for manual follow-up instead of deleting that feature.
5. Update .env.example and any README or docs that mention OpenRouter.
When you are done, list every file you changed and anything that needs manual follow-up, such as creating a Flex API key in the portal and revoking the old OpenRouter key. Do not refactor unrelated code.The copy button in the corner of the block copies the whole prompt.