Skip to content

Commit d7cba24

Browse files
committed
minor #941 [Platform] Add OpenRouter documentation and examples (lochmueller)
This PR was merged into the main branch. Discussion ---------- [Platform] Add OpenRouter documentation and examples | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Docs? | yes | Issues | | License | MIT Add OpenRouter for relevant model companies and add two more examples: - Example for setting App-Name and App URI for OpenRouter Activity feed - Add example using Websearch with OpenRouter (`:online` modifier) Commits ------- f52facc feat: Add OpenRouter documentation and examples
2 parents 87f0d31 + f52facc commit d7cba24

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

docs/components/platform.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,23 @@ Supported Models & Platforms
109109
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110110

111111
* **Language Models**
112-
* `OpenAI's GPT`_ with `OpenAI`_ and `Azure`_ as Platform
112+
* `OpenAI's GPT`_ with `OpenAI`_, `Azure`_ and `OpenRouter`_ as Platform
113113
* `Anthropic's Claude`_ with `Anthropic`_ and `AWS Bedrock`_ as Platform
114-
* `Meta's Llama`_ with `Azure`_, `Ollama`_, `Replicate`_ and `AWS Bedrock`_ as Platform
114+
* `Meta's Llama`_ with `Azure`_, `Ollama`_, `Replicate`_, `AWS Bedrock`_ and `OpenRouter`_ as Platform
115115
* `Gemini`_ with `Google`_, `Vertex AI`_ and `OpenRouter`_ as Platform
116116
* `Vertex AI Gen AI`_ with `Vertex AI`_ as Platform
117117
* `DeepSeek's R1`_ with `OpenRouter`_ as Platform
118118
* `Amazon's Nova`_ with `AWS Bedrock`_ as Platform
119-
* `Mistral's Mistral`_ with `Mistral`_ as Platform
119+
* `Mistral's Mistral`_ with `Mistral`_ and `OpenRouter`_ as Platform
120120
* `Albert API`_ models with `Albert`_ as Platform (French government's sovereign AI gateway)
121121
* `LiteLLM`_ as unified Platform
122122
* **Embeddings Models**
123-
* `Gemini Text Embeddings`_ with `Google`_
123+
* `Gemini Text Embeddings`_ with `Google`_ and `OpenRouter`_
124124
* `Vertex AI Text Embeddings`_ with `Vertex AI`_
125-
* `OpenAI's Text Embeddings`_ with `OpenAI`_ and `Azure`_ as Platform
125+
* `OpenAI's Text Embeddings`_ with `OpenAI`_, `Azure`_ and `OpenRouter`_ as Platform
126126
* `Voyage's Embeddings`_ with `Voyage`_ as Platform
127-
* `Mistral Embed`_ with `Mistral`_ as Platform
127+
* `Mistral Embed`_ with `Mistral`_ and `OpenRouter`_ as Platform
128+
* `Qwen`_ with `OpenRouter`_ as Platform
128129
* **Other Models**
129130
* `OpenAI's Dall·E`_ with `OpenAI`_ as Platform
130131
* `OpenAI's Whisper`_ with `OpenAI`_ and `Azure`_ as Platform
@@ -532,6 +533,7 @@ Code Examples
532533
.. _`DeepSeek's R1`: https://www.deepseek.com/
533534
.. _`Amazon's Nova`: https://nova.amazon.com
534535
.. _`Mistral's Mistral`: https://www.mistral.ai/
536+
.. _`Qwen`: https://qwen.ai/
535537
.. _`Albert API`: https://github.com/etalab-ia/albert-api
536538
.. _`Albert`: https://alliance.numerique.gouv.fr/produit/produits-interminist%C3%A9rielles/albert-api/
537539
.. _`Mistral`: https://www.mistral.ai/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\AI\Platform\Bridge\OpenRouter\PlatformFactory;
13+
use Symfony\AI\Platform\Message\Message;
14+
use Symfony\AI\Platform\Message\MessageBag;
15+
16+
require_once dirname(__DIR__).'/bootstrap.php';
17+
18+
$platform = PlatformFactory::create(env('OPENROUTER_KEY'), http_client());
19+
20+
$messages = new MessageBag(
21+
Message::forSystem('Check the web for details that the user ask.'),
22+
Message::ofUser('Who win the Formula1 GP in Brasilia at 2025-11-09?'),
23+
);
24+
25+
// ":online" add web search tooling to the OpenRouter model
26+
$result = $platform->invoke('google/gemini-2.5-flash-lite:online', $messages);
27+
28+
// Example result:
29+
// Lando Norris won the Formula 1 Grand Prix in Brasilia on November 9, 2025. This victory significantly extended his lead
30+
// in the Drivers' Championship [planetf1.com]. Max Verstappen finished third after starting from the pit lane [motorsportweek.com].
31+
32+
echo $result->asText().\PHP_EOL;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\AI\Platform\Bridge\OpenRouter\PlatformFactory;
13+
use Symfony\AI\Platform\Message\Message;
14+
use Symfony\AI\Platform\Message\MessageBag;
15+
16+
require_once dirname(__DIR__).'/bootstrap.php';
17+
18+
// Set title AND uri to track the calls in the OpenRouter Activity feed
19+
$client = http_client()->withOptions([
20+
'headers' => [
21+
'HTTP-Referer' => 'https://ai.symfony.com/',
22+
'X-Title' => 'My Special Symfony AI App',
23+
],
24+
]);
25+
26+
$platform = PlatformFactory::create(env('OPENROUTER_KEY'), $client);
27+
28+
$messages = new MessageBag(
29+
Message::forSystem('Output two sentences related to the user topic.'),
30+
Message::ofUser('Chess'),
31+
);
32+
33+
$result = $platform->invoke('google/gemini-2.5-flash-lite', $messages);
34+
35+
echo $result->asText().\PHP_EOL;

0 commit comments

Comments
 (0)