> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://respan.ai/docs/apis/gateway/create-openrouter-chat-completion/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/_mcp/server. # Create an OpenRouter chat completion POST https://api.respan.ai/api/openrouter/v1/chat/completions Content-Type: application/json Forward OpenRouter requests and return its response, status code, or event stream unchanged. OpenRouter fields such as `provider` and `reasoning` are preserved. Supply your Respan key in `Authorization` and your OpenRouter key in `x-openrouter-api-key`; this endpoint requires your own OpenRouter key and does not use Respan gateway credits. Reference: https://respan.ai/docs/apis/gateway/create-openrouter-chat-completion ## Authentication - `Authorization` header (bearer token, required) — Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer \. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan\_params.credential\_override in the request body, not in this authentication field. ## Request ### Headers - `x-openrouter-api-key` (string, required) — Your OpenRouter API key. Authorization carries the Respan API key on this operation. ### Body (application/json) This endpoint expects an object. - `model` (string, required) — OpenRouter model slug, for example anthropic/claude-sonnet-4-5. An openrouter/ prefix is also accepted and is stripped before the call goes upstream. - `messages` (list of map from string to any, required) - `stream` (boolean, optional, default: false) - `provider` (map from string to any, optional) — OpenRouter provider routing block, forwarded unchanged. - `reasoning` (map from string to any, optional) — OpenRouter reasoning block, forwarded unchanged. - `respan_params` (map from string to any, optional) — Respan gateway metadata. Stripped before the payload reaches OpenRouter. Must be a JSON object: a string, list, number or boolean is ignored and none of its params apply. ## Response ### 200 OpenRouter response or event stream. - `map from string to any` ## Errors ### 400 Bad Request Error `x-openrouter-api-key` is missing, or OpenRouter rejected the request. OpenRouter's own errors come back with its body. - `map from string to any` ### 402 Payment Required Error Relayed from OpenRouter: insufficient credits. - `map from string to any` ### 403 Forbidden Error The API key is missing, invalid or expired. - `detail` (string, required) ### 404 Not Found Error Relayed from OpenRouter: unknown model or route. - `map from string to any` ### 429 Too Many Requests Error Rate limit exceeded, from Respan or relayed from OpenRouter. - `map from string to any` ## Examples **Request** ```json { "model": "string", "messages": [ {} ] } ``` **Response** ```json {} ``` **SDK Code** ```python import requests url = "https://api.respan.ai/api/openrouter/v1/chat/completions" payload = { "model": "string", "messages": [{}] } headers = { "x-openrouter-api-key": "x-openrouter-api-key", "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.respan.ai/api/openrouter/v1/chat/completions'; const options = { method: 'POST', headers: { 'x-openrouter-api-key': 'x-openrouter-api-key', Authorization: 'Bearer ', 'Content-Type': 'application/json' }, body: '{"model":"string","messages":[{}]}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.respan.ai/api/openrouter/v1/chat/completions" payload := strings.NewReader("{\n \"model\": \"string\",\n \"messages\": [\n {}\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("x-openrouter-api-key", "x-openrouter-api-key") req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.respan.ai/api/openrouter/v1/chat/completions") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["x-openrouter-api-key"] = 'x-openrouter-api-key' request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"model\": \"string\",\n \"messages\": [\n {}\n ]\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.respan.ai/api/openrouter/v1/chat/completions") .header("x-openrouter-api-key", "x-openrouter-api-key") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"model\": \"string\",\n \"messages\": [\n {}\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.respan.ai/api/openrouter/v1/chat/completions', [ 'body' => '{ "model": "string", "messages": [ {} ] }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', 'x-openrouter-api-key' => 'x-openrouter-api-key', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.respan.ai/api/openrouter/v1/chat/completions"); var request = new RestRequest(Method.POST); request.AddHeader("x-openrouter-api-key", "x-openrouter-api-key"); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"model\": \"string\",\n \"messages\": [\n {}\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "x-openrouter-api-key": "x-openrouter-api-key", "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "model": "string", "messages": [[]] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/openrouter/v1/chat/completions")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```