Skip to main content

Connect any client

Most tools that talk to a model only need three things to go through the gateway: where the gateway is (the base URL), how to prove who they are (a virtual key in a header), and which model to ask for (a public model name). This page gives those three values for every kind of client the gateway serves, so a tool that has no page of its own can still be connected in a few minutes. Every tool page in these docs links here for the parts they share.

A real-world scenario​

A data team uses a notebook tool, a chat app and a small agent framework, and none of them has a page in these docs. The admin creates one virtual key per tool, as described in make a key for a tool. The team looks up each tool's API style in the table below, which says the chat app and the framework speak the OpenAI format and need the URL with /v1, while the notebook uses the Anthropic SDK and needs the bare URL. They paste the values, run the curl check once per key, and see each tool's requests on the Logs page under its own key alias.

Before you start​

  • The gateway's address, for example https://gateway.example.com, reachable from the machine the tool runs on.
  • At least one model on the gateway. Models + Endpoints in the Admin UI lists the public names.
  • The tool's own settings screen or file where a base URL and an API key can be entered. A tool with no custom endpoint setting cannot use the gateway.
  • A virtual key for the tool, made as in the next section.

Make a key for the tool​

Give each tool its own key, so its spend, errors and limits stay apart from every other tool and one tool can be switched off on its own.

  1. In the Admin UI open Virtual Keys (/ui/api-keys) and click + Create New Key.
  2. Under Key Details, set Key Name to the person and the tool, for example jane-notebook. Leave Key Type on AI APIs, so the key can call models but cannot change the gateway.
  3. In Models, pick every public model name the tool calls. Many tools also send cheap background calls, such as chat titles, summaries or autocomplete, to a small model like claude-haiku-5-5. Add that model too, or those calls fail with 403 while the main calls work.
  4. Open Optional Settings. Set Max Budget (USD) with Reset Budget, for example 100 USD monthly, so a runaway loop stops at the budget instead of at the invoice. Set Requests per minute Limit (RPM), for example 60, and for tools that run unattended also Tokens per minute Limit (TPM).
  5. Click Create Key and copy the key. It is shown once.

The same key from the API, with the master key or a proxy admin's key:

curl -X POST https://gateway.example.com/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"key_alias": "jane-notebook", "key_type": "llm_api", "models": ["claude-sonnet-5-5", "claude-haiku-5-5"], "max_budget": 100, "budget_duration": "30d", "rpm_limit": 60, "tpm_limit": 200000}'

The answer carries the new key in key. Make a key for a tool explains every field.

Steps​

  1. Get a key for the tool, as in make a key for the tool.

  2. Find the tool's API style in the base URL table. A tool that asks for an "OpenAI compatible" or "custom OpenAI" endpoint is the OpenAI style. A tool built on the Anthropic SDK or that asks for ANTHROPIC_BASE_URL is the Anthropic style.

  3. Check the key and the model names from a terminal before you touch the tool.

    curl https://gateway.example.com/v1/models -H "Authorization: Bearer $SPANWAY_API_KEY"
  4. Enter the base URL, the key and one model id from that list in the tool, then send one prompt.

  5. Open Logs (/ui/logs) and filter by the key alias. The request is there with its model, tokens and cost.

Expected result​

The curl check answers 200 with the public model names the key may call.

{"data": [{"id": "claude-sonnet-5-5", "object": "model", "created": 1677610602, "owned_by": "openai"}, {"id": "gpt-6.1-sol", "object": "model", "created": 1677610602, "owned_by": "openai"}], "object": "list"}

Every answer from the gateway carries an x-spanway-call-id header, which is the id to search for on Logs or to send to support.

The /v1 rule​

Clients differ in whether they add /v1 to the address themselves, and getting this wrong is the most common reason a new client fails with 404.

  • A client that adds the route starting at /chat/completions, /responses or /embeddings needs the base URL with /v1, for example https://gateway.example.com/v1. That covers the OpenAI SDKs and almost every tool that asks for an OpenAI compatible endpoint.
  • A client that adds /v1/... or /v1beta/... itself needs the bare root, for example https://gateway.example.com. That covers the Anthropic SDKs, Claude Code, the Google Gen AI SDK, the Spanway Python and TypeScript clients, spanwayctl and the Terraform provider. The Google Gen AI SDK also needs its API version set to v1beta, because from version 3 it calls /v1/models/..., which the gateway answers with 405 Method Not Allowed.

The gateway also answers the OpenAI routes without /v1, so an OpenAI style client given the bare root still works. The reverse does not: an Anthropic style client given https://gateway.example.com/v1 calls /v1/v1/messages and gets 404 Not Found.

Base URL and header per API surface​

API surfaceBase URL to enterRoute the client callsKey header the client sendsSDK environment variables
OpenAI chat completions, embeddings, images, audiohttps://gateway.example.com/v1/v1/chat/completions and the other OpenAI routesAuthorization: Bearer <key>OPENAI_BASE_URL, OPENAI_API_KEY
OpenAI Responses APIhttps://gateway.example.com/v1/v1/responsesAuthorization: Bearer <key>OPENAI_BASE_URL, OPENAI_API_KEY
Anthropic Messageshttps://gateway.example.com/v1/messages, /v1/messages/count_tokensx-api-key: <key> or Authorization: Bearer <key>ANTHROPIC_BASE_URL, then ANTHROPIC_API_KEY for x-api-key or ANTHROPIC_AUTH_TOKEN for a bearer token
Google Gemini (unified, any provider behind the name)https://gateway.example.com/v1beta/models/<model>:generateContentx-goog-api-key: <key>, the ?key= query parameter, or Authorization: Bearer <key>GOOGLE_GEMINI_BASE_URL, GEMINI_API_KEY and GOOGLE_GENAI_API_VERSION=v1beta, or the same values in http_options
Google Gemini (pass-through to Google only)https://gateway.example.com/gemini/gemini/v1beta/...x-goog-api-key: <key> or ?key=As above
Amazon Bedrock Converse and Invokehttps://gateway.example.com/bedrock/bedrock/model/<model>/converse, /invokeAuthorization: Bearer <key>, or a SigV4 signature with the key as the access key idAWS_BEARER_TOKEN_BEDROCK with the SDK's endpoint_url set to the base URL
Azure OpenAI SDKhttps://gateway.example.com as azure_endpoint/openai/deployments/<model>/chat/completionsAPI-Key: <key>AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY
MCP clients (Streamable HTTP)https://gateway.example.com/mcp, or /mcp/<server name> for one server/mcpAuthorization: Bearer <key> or x-spanway-api-key: <key>Per client, see MCP clients
A2A agentshttps://gateway.example.com/a2a/<agent name>/a2a/<agent name> and its agent cardAuthorization: Bearer <key>Per framework, see A2A agents

Spanway Cloud workspaces use the same rules with the address shown in your workspace, such as https://api.spanway.ai.

Which header wins​

The gateway reads the key from the headers in this order and uses the first one it finds: x-spanway-api-key, then Authorization, then API-Key, x-api-key, x-goog-api-key, Ocp-Apim-Subscription-Key and last the key query parameter on the Gemini routes. x-spanway-api-key takes the key alone or Bearer <key>. Use it when the client needs Authorization for something else, such as an MCP client whose OAuth sign-in fills that header. An admin can add one more header name with general_settings.spanway_key_header_name, see calling the gateway. When that setting is on and the request carries that header, it wins over every header in the list above.

Model names​

The model a client sends is the public model name an admin gave the deployment in Models + Endpoints, not the provider's own id. One public name can sit in front of several deployments from different providers, and the gateway picks one per request. GET /v1/models with the tool's key lists exactly the names that key may call, so the answer differs from key to key. Clients that cannot list models themselves, such as tools where you type a model name or copy context limits by hand, need a name from that list typed exactly, including case.

Claude Code only shows model ids that contain claude or anthropic in its /model picker. When Claude Code lists the models, the gateway shows every other model under an id that starts with claude-router- and routes it back to the real model, so the picker still offers it under its real display name, except for wildcard routes. See Claude Code models.

Errors​

The failures in this table happen before the gateway sees the request, so nothing appears on Logs. The client error reference covers the errors the gateway itself returns.

What the client showsWhat it meansFix
404 Not Found on the first call, or a path with /v1/v1 in the client logThe base URL has /v1 and the client adds /v1 itself, or it lacks /v1 and the client expects it.Apply the /v1 rule.
Connection refused, ECONNREFUSED or APIConnectionErrorNothing listens at that address and port.Check the gateway runs with curl https://gateway.example.com/health/liveliness, which needs no key.
A connection error from a tool running in Docker with the base URL http://localhost:4000Inside a container, localhost is the container itself, not your machine.Use http://host.docker.internal:4000 on Docker Desktop, or the gateway's service name on a shared Docker network.
getaddrinfo ENOTFOUND, Name or service not known or nodename nor servname providedThe host name does not resolve on that machine.Check the spelling, the VPN and the internal DNS.
CERTIFICATE_VERIFY_FAILED, self signed certificate in certificate chain or unable to get local issuer certificateThe gateway's TLS certificate is signed by a company or private authority the client does not trust.Give the client the company root certificate. Python clients built on httpx read SSL_CERT_FILE, clients built on requests read REQUESTS_CA_BUNDLE, Node clients read NODE_EXTRA_CA_CERTS, and JetBrains IDEs trust certificates added under Settings, Tools, Server Certificates. Never turn verification off outside a test machine.
A timeout on long answers onlyA proxy or load balancer between the client and the gateway closes idle connections, often after 60 seconds.Raise the idle timeout on that hop, or use streaming so bytes keep flowing.

Troubleshooting​

  1. Copy x-spanway-call-id from the failing answer if the client shows response headers, or note the time and the key alias.
  2. Open Logs (/ui/logs), filter by the key alias or search for the call id, and open the row. The detail shows the status, the error text, the model the gateway picked and the provider's answer.
  3. If the request is not on Logs, it never reached the gateway. Work through the connection problems above.
  4. Turn on the client's own debug output with the switches in troubleshooting, and compare the URL and headers it sends with the table on this page.