#setup force code with openrouter

4 messages · Page 1 of 1 (latest)

jolly wingBOT
#

To pick a specific provider and model via OpenRouter using Forge code, you can specify the model slug and prioritize providers with the provider field in your request. Use the order array to list provider slugs in priority order, and set allow_fallbacks to false if you want to restrict to only those providers.

Example JSON body for your request:

{
  "model": "provider/model-name",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "provider": {
    "order": ["provider1", "provider2"],
    "allow_fallbacks": false
  }
}

Replace "provider/model-name" with your desired model slug, and "provider1", "provider2" with the exact provider slugs you want to use (including variants like /turbo if needed).

You can get exact provider slugs from the model pages on OpenRouter.

Here is a TypeScript-style fetch example:

fetch('https://openrouter.ai/api/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <OPENROUTER_API_KEY>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'mistralai/mixtral-8x7b-instruct',
    messages: [{ role: 'user', content: 'Hello' }],
    provider: {
      order: ['openai', 'together'],
      allow_fallbacks: false
    }
  }),
});

This ensures your request uses the specified provider and model with your OpenRouter credits.

Would you like guidance on how to identify your website platform to help with JavaScript snippet installation next?

-# This is an automated response. Use !mute to stop the bot from responding.

vagrant quest
#

can you please provide an example how to configure forgecode with openrouter, model qwen/qwen3-235b-a22b-thinking-2507 provider cerebras

jolly wingBOT
#

Here's an example of a Forge code request configured to use the OpenRouter API with the model qwen/qwen3-235b-a22b-thinking-2507 from the provider cerebras:

fetch('https://openrouter.ai/api/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <OPENROUTER_API_KEY>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'qwen/qwen3-235b-a22b-thinking-2507',
    messages: [
      { role: 'user', content: 'Hello' }
    ],
    provider: {
      order: ['cerebras'],
      allow_fallbacks: false
    }
  }),
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));
  • Replace <OPENROUTER_API_KEY> with your actual API key.
  • The provider.order array specifies the provider priority, here set to cerebras only.
  • Setting allow_fallbacks: false ensures it will not fallback to other providers.

This setup will use your OpenRouter credits to call the Cerebras Qwen3 235B Thinking model specifically.

Would you like help with installing the JavaScript snippet on your website next?

-# This is an automated response. Use !mute to stop the bot from responding.

vagrant quest