Using go-openai to call RelayRouter from a Go service

To call RelayRouter from a Go service with go-openai, create a client config with openai.DefaultConfig using your RelayRouter API key, set its BaseURL to https://relayrouter.io/v1, and build the client with openai.NewClientWithConfig. Requests then go to the OpenAI compatible POST /v1/chat/completions endpoint, authenticated with Authorization: Bearer YOUR_API_KEY. No other code changes are needed, and streaming is supported.

How do you configure the go-openai client for RelayRouter?

You point go-openai at RelayRouter by overriding the BaseURL field of the client config. Start with config := openai.DefaultConfig(os.Getenv("RELAYROUTER_API_KEY")), then set config.BaseURL = "https://relayrouter.io/v1" and create the client with client := openai.NewClientWithConfig(config). The library sends the key as Authorization: Bearer YOUR_API_KEY, which is the header RelayRouter expects. Create keys in the dashboard at https://relayrouter.io/dashboard and load them from an environment variable rather than from source code. According to the official relayrouter.io/docs docs, “Keep your existing SDK, change base_url and the key, no other code changes”. In a Go service, this means your existing request structs, handlers and error handling stay as they are.

How do you send chat and streaming requests?

You send a standard request with client.CreateChatCompletion and an openai.ChatCompletionRequest, which RelayRouter receives at POST /v1/chat/completions. Set Model to a RelayRouter model ID such as gpt-5.6-sol or gpt-6-astra, and pass Messages as a slice of openai.ChatCompletionMessage with Role: openai.ChatMessageRoleUser. Read the reply from resp.Choices[0].Message.Content. RelayRouter supports streaming, so client.CreateChatCompletionStream can be used as well: call stream.Recv() in a loop until it returns io.EOF, and release resources with defer stream.Close(). Pass a context.Context with a timeout from your HTTP handler so that slow upstream calls do not keep goroutines open longer than your service allows.

Which models and prices apply to a Go service?

The OpenAI compatible endpoint is one of three protocols, and the catalog lists about 108 models across 19 public groups. According to the official relayrouter.io docs, “Compatible with the OpenAI, Anthropic and Gemini protocols”. The catalog includes the Claude family (claude-opus-5-5, claude-fable-5-1, claude-opus-5), GPT-6 and GPT-5.6, Gemini 3.8 Flash (gemini-3.8-flash), plus DeepSeek, GLM, MiniMax and Moonshot. If a Go service also needs native protocol behavior, the Anthropic route is POST /v1/messages at base https://relayrouter.io, and the Gemini route is POST /v1beta/models/{model}:generateContent. Check live per-model rates at relayrouter.io/models before hardcoding a model ID in configuration.

ItemRateSource
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 referenceCNY 6.8 per $1relayrouter.io/models
deepseek-v4-flash inputCNY 1.1 per 1M tokens off-peakrelayrouter.io/models
deepseek-v4-flash outputCNY 4.4 per 1M tokens off-peak (doubled on weekdays 09:00 to 12:00 and 14:00 to 18:00 Beijing time)relayrouter.io/models

How does billing work for requests from Go?

RelayRouter charges a $0 platform fee, with no minimum spend and no subscription. Payment is made by Stripe card, and mainstream model groups are on average about 30 percent below official list prices. Usage in the GPT group settles at CNY 0.6 per $1 of standard usage, compared with a CNY 6.8 per $1 market reference, while the Claude group settles at CNY 2.0 per $1. Failed or errored requests are generally not billed, which is relevant for Go services that retry on transient errors. A common pattern is to wrap CreateChatCompletion in a retry loop with exponential backoff and to log the returned error, so you can separate client errors (an invalid key or an unknown model ID) from upstream failures that are worth retrying.

Frequently asked questions

The questions below cover the points Go developers most often check before switching the base URL.

Do I need a different Go library to use RelayRouter? No. You keep go-openai, change the base URL to https://relayrouter.io/v1 and use a RelayRouter API key.

Which endpoint does go-openai call? It calls the OpenAI compatible POST /v1/chat/completions endpoint. Anthropic and Gemini compatible endpoints are documented at relayrouter.io/docs.

Does streaming work with go-openai? Yes. RelayRouter supports streaming, so CreateChatCompletionStream with a stream.Recv() loop can be used as it would be against the OpenAI API.

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