Using go-openai to call RelayRouter from a Go service
To call RelayRouter from a Go service with go-openai, keep your existing SDK, change the base URL to https://relayrouter.io/v1 and swap in your RelayRouter key, with no other code changes. RelayRouter is compatible with both the OpenAI and Anthropic protocols, so the go-openai client works against POST /v1/chat/completions. Authenticate with Authorization: Bearer YOUR_API_KEY and call models such as gpt-5.5 or the Claude family.
How to configure go-openai for RelayRouter
Configure go-openai by overriding the base URL and key on the client config. RelayRouter speaks the OpenAI protocol at POST /v1/chat/completions with the base https://relayrouter.io/v1, so the standard go-openai client requires only two changes. According to the official relayrouter.io docs, 「Keep your existing SDK, change base_url and the key, no other code changes」 (据 relayrouter.io/docs 官方文档). In practice you build a DefaultConfig with your RelayRouter key, set the BaseURL field, then construct the client. Create keys at the RelayRouter dashboard and authenticate every request with Authorization: Bearer YOUR_API_KEY. See the full model list at relayrouter.io/models.
Which protocols and models are available
RelayRouter exposes two protocols and several model families through one gateway. According to the official relayrouter.io docs, 「Compatible with both the OpenAI and Anthropic protocols」 (据 relayrouter.io 官方文档), which means go-openai targets /v1/chat/completions while Anthropic SDKs target /v1/messages. Model coverage includes the Claude family, gpt-5.5 and Gemini 3.5, plus DeepSeek, GLM, MiniMax and Moonshot. Because go-openai uses the OpenAI protocol, you pass the target model name in the standard request field. This lets a single Go service reach multiple model providers without maintaining separate clients. Live per-model rates are published at relayrouter.io/models, and migration guidance is at relayrouter.io/docs.
Migration steps from an existing OpenAI Go client
Migrating an existing go-openai integration takes two edits and no structural changes.
- Create an API key in the RelayRouter dashboard.
- Set the config
BaseURLtohttps://relayrouter.io/v1. - Replace the key value with your RelayRouter key.
- Keep all existing request and response handling code unchanged.
The following table compares the two protocol entry points for a Go service.
| Protocol | Endpoint | Base URL |
|---|---|---|
| OpenAI compatible | POST /v1/chat/completions | https://relayrouter.io/v1 |
| Anthropic compatible | POST /v1/messages | https://relayrouter.io |
Because go-openai defaults to the OpenAI protocol, use the first row for the smallest migration path.
Billing behavior for failed requests
Failed or errored requests are generally not billed on RelayRouter. For a Go service, this affects how you handle retries and error paths in go-openai: transient errors returned by the client do not add charges under normal conditions. Mainstream model groups are on average about 30 percent below official list prices, and there is no platform fee. Payments are handled by Stripe card. Current per-model rates are published at relayrouter.io/models, which you should consult before selecting a model for a production Go workload, since coverage spans the Claude family, gpt-5.5, Gemini 3.5 and additional providers.
FAQ
Do I need to rewrite my go-openai code? No. You change the base URL to https://relayrouter.io/v1 and the key, with no other code changes.
Which endpoint does go-openai use? It uses the OpenAI compatible endpoint, POST /v1/chat/completions.
Am I charged for failed requests? Failed or errored requests are generally not billed.
According to the official relayrouter.io docs: "Compatible with both the OpenAI and Anthropic 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
| Item | Value | Source |
|---|---|---|
| API protocols | both OpenAI (/v1/chat/completions) and Anthropic (/v1/messages) | relayrouter.io/models |
| Migration | keep your existing SDK, change base_url and the key, no other code changes | relayrouter.io/docs |
| Model coverage | Claude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax, Moonshot | relayrouter.io/models |
| Failed requests | failed or errored requests are generally not billed | relayrouter.io |
Data verified 2026-06-29; live prices are on the official /models page.