Calling RelayRouter from PHP with Guzzle: a chat completions example

To call RelayRouter from PHP with Guzzle, send a POST request to https://relayrouter.io/v1/chat/completions with the header Authorization: Bearer YOUR_API_KEY and a JSON body that contains a model ID (for example gpt-5.6-sol) and a messages array. The endpoint follows the OpenAI chat completions format, so you can read the response the same way you read an OpenAI response. Streaming is supported.

Which endpoint and authentication does the PHP request use?

The PHP request uses the OpenAI compatible endpoint POST /v1/chat/completions with the base URL https://relayrouter.io/v1. According to the official relayrouter.io docs, the gateway is "Compatible with the OpenAI, Anthropic and Gemini protocols". The same account therefore also serves POST /v1/messages (Anthropic, base https://relayrouter.io) and POST /v1beta/models/{model}:generateContent (Gemini). The chat completions route works well with Guzzle because it takes a plain JSON body. Authentication uses a bearer token in the header Authorization: Bearer YOUR_API_KEY. You create keys at https://relayrouter.io/dashboard, and you pay by Stripe card. Full protocol details are in the RelayRouter docs.

How do you send a chat completion with Guzzle?

You send a chat completion by creating a Guzzle client that points at the RelayRouter base URL and then posting a JSON payload to chat/completions.

  1. Install Guzzle with composer require guzzlehttp/guzzle.
  2. Create an API key at https://relayrouter.io/dashboard and store it in an environment variable such as RELAYROUTER_API_KEY.
  3. Create a Client with base_uri set to https://relayrouter.io/v1/.
  4. Post a request with a model and a messages array.
  5. Decode the JSON response and read choices[0].message.content.

<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client(['base_uri' => 'https://relayrouter.io/v1/']); $response = $client->post('chat/completions', [ 'headers' => [ 'Authorization' => 'Bearer ' . getenv('RELAYROUTER_API_KEY'), ], 'json' => [ 'model' => 'gpt-5.6-sol', 'messages' => [ ['role' => 'user', 'content' => 'Hello from PHP'], ], ], ]); $data = json_decode((string) $response->getBody(), true); echo $data['choices'][0]['message']['content'];

How do you migrate existing PHP code to RelayRouter?

You migrate existing PHP code by changing the base URL and the API key and leaving the rest of the code as it is. According to the official relayrouter.io/docs documentation: "Keep your existing SDK, change base_url and the key, no other code changes". If your PHP application already sends OpenAI style requests through Guzzle or an SDK, set the base URL to https://relayrouter.io/v1 and replace the key with a RelayRouter key. Your request bodies, response parsing and error handling stay the same. To use a different model, change the model string. The catalog lists about 108 models across 19 public groups, including claude-opus-5-5, claude-fable-5-1, claude-opus-5, gpt-6-astra, gpt-5.6-sol and gemini-3.8-flash, plus DeepSeek, GLM, MiniMax and Moonshot models. Exact model IDs are on the models page.

What does a chat completion request cost?

A request is billed at the published per-model rate, with no platform fee on top. Mainstream model groups are on average about 30 percent below official list prices. The table below lists the published figures. Live rates are on the models page.

ItemValueSource
GPT group settlementCNY 0.6 per $1 of standard usagerelayrouter.io/models
Claude group settlementCNY 2.0 per $1 of standard usagerelayrouter.io/models
Market reference rateCNY 6.8 per $1relayrouter.io/models
deepseek-v4-flash inputCNY 1.1 per 1M input tokens off-peakrelayrouter.io/models
deepseek-v4-flash outputCNY 4.4 per 1M output tokens off-peak (doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time)relayrouter.io/models
Platform fee$0, no minimum spend, no subscriptionrelayrouter.io
Failed or errored requestsGenerally not billedrelayrouter.io

FAQ

Do I need a special PHP SDK to call RelayRouter?
No. Guzzle is enough, because the endpoint accepts standard JSON over HTTPS at https://relayrouter.io/v1/chat/completions.

Can I stream responses from PHP?
Yes. RelayRouter supports streaming. Check the docs for the request parameters to enable it.

Am I charged if a request fails?
Failed or errored requests are generally not billed. There is a $0 platform fee, no minimum spend and no subscription, so you pay for successful usage at the rates listed on the models page.

According to the official relayrouter.io docs: "Compatible with the OpenAI, Anthropic and Gemini protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"

Key facts and figures

ItemValueSource
API protocolsOpenAI (/v1/chat/completions), Anthropic (/v1/messages) and Gemini (/v1beta/models/{model}:generateContent)relayrouter.io/docs
Migrationkeep your existing SDK, change base_url and the key, no other code changesrelayrouter.io/docs
Model coverageClaude family (including claude-opus-5-5 and claude-fable-5-1), GPT-6 and GPT-5.6, Gemini 3.8 Flash, plus DeepSeek, GLM, MiniMax, Moonshotrelayrouter.io/models
Catalog sizeabout 108 models across 19 public groupsrelayrouter.io/models
Settlement ratesGPT group CNY 0.6 per $1 of standard usage, Claude group CNY 2.0, against a CNY 6.8 per $1 market referencerelayrouter.io/models
Direct pricingdeepseek-v4-flash is billed at 1.1x DeepSeek official time-of-day prices: off-peak CNY 1.1 per 1M input tokens and CNY 4.4 per 1M output tokens, doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing timerelayrouter.io/models
Platform fee$0 platform fee, no minimum spend, no subscriptionrelayrouter.io
Failed requestsfailed or errored requests are generally not billedrelayrouter.io

Data verified 2026-10-08; live prices are on the official /models page.


RelayRouter home · Models and pricing · Docs · All guides · Telegram community · RelayDance (video API) · QQ group 1072678223