> 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-openai-format-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 OpenAI-format chat completion POST https://api.respan.ai/api/{provider}/v1/chat/completions Content-Type: application/json Relay an OpenAI-format chat completions payload to one provider and get that provider's response back byte for byte. Respan authenticates the request, applies your [limits](/docs/documentation/features/gateway/limits), and logs it, but doesn't translate the request or recompute usage. Respan removes `respan_params` and merges a literal `extra_body` object into the body; unknown and provider-only fields are passed through. Streams are relayed frame by frame, and requests time out after 600 seconds. `{provider}` is a provider with an OpenAI-format API, such as `openai`, `azure_openai`, `xai`, `groq`, `mistral`, `deepseek`, `togetherai`, `fireworks`, or `perplexity`. A provider without an OpenAI-format API returns `404`. A provider with no fixed public endpoint, such as Azure OpenAI, needs the provider URL saved with its key; without it the request returns `400`. Anthropic, Google and OpenRouter have their own endpoints. Upstream, Respan sends only `accept`, `accept-language`, `content-type`, `user-agent`, and headers that start with `x-` plus the provider ID, with `_` written as `-` (for example `x-azure-openai-`). The response includes `X-Respan-Log-Id`, `X-Respan-Upstream-Request-Id`, and the provider's `x-ratelimit-*` and `retry-after` headers. Reference: https://respan.ai/docs/apis/gateway/create-openai-format-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 ### Path parameters - `provider` (string, required) — The provider ID, such as `openai`, `azure_openai`, `xai`, `groq`, `mistral`, `deepseek`, `togetherai`, `fireworks`, or `perplexity`. ### Body (application/json) This endpoint expects an object. - `model` (string, required) — The provider's own model ID. - `messages` (list of map from string to any, required) — Chat messages in OpenAI format. - `stream` (boolean, optional) — Stream the provider's response as server-sent events. - `respan_params` (map from string to any, optional) — Respan parameters such as `customer_identifier` or `metadata`. Removed before the request is forwarded. ## Response ### 200 The provider's response, unchanged. - `map from string to any` ## Errors ### 400 Bad Request Error No endpoint is known for the provider: save the provider URL with its key. Otherwise, the provider's own `400`. - `map from string to any` ### 401 Unauthorized Error No usable key for the provider. The code is `activation_required` when your organization has no credits and no provider key for the model. - `map from string to any` ### 402 Payment Required Error The request's customer is over their budget. - `map from string to any` ### 403 Forbidden Error The API key is missing, invalid or expired. - `detail` (string, required) ### 404 Not Found Error The provider isn't available on this route. - `map from string to any` ### 429 Too Many Requests Error Your Respan key's rate limit or an API key limit's block rule, or the provider's own `429`. - `map from string to any` ## Examples **Request** ```json { "model": "llama-3.3-70b-versatile", "messages": [ { "role": "user", "content": "Hello!" } ] } ``` **Response** ```json {} ``` **SDK Code** ```python import requests url = "https://api.respan.ai/api/groq/v1/chat/completions" payload = { "model": "llama-3.3-70b-versatile", "messages": [ { "role": "user", "content": "Hello!" } ] } headers = { "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/groq/v1/chat/completions'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"model":"llama-3.3-70b-versatile","messages":[{"role":"user","content":"Hello!"}]}' }; 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/groq/v1/chat/completions" payload := strings.NewReader("{\n \"model\": \"llama-3.3-70b-versatile\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) 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/groq/v1/chat/completions") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"model\": \"llama-3.3-70b-versatile\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\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/groq/v1/chat/completions") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"model\": \"llama-3.3-70b-versatile\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.respan.ai/api/groq/v1/chat/completions', [ 'body' => '{ "model": "llama-3.3-70b-versatile", "messages": [ { "role": "user", "content": "Hello!" } ] }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.respan.ai/api/groq/v1/chat/completions"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"model\": \"llama-3.3-70b-versatile\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Hello!\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "model": "llama-3.3-70b-versatile", "messages": [ [ "role": "user", "content": "Hello!" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/groq/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() ```