> 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-anthropic-message/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/_mcp/server. # Create an Anthropic message POST https://api.respan.ai/api/anthropic/v1/messages Content-Type: application/json Send native Anthropic Messages requests through Respan using provider credentials configured in Respan. Authenticate with your Respan key in `x-api-key` for Anthropic SDKs or `Authorization: Bearer` for bearer clients. Reference: https://respan.ai/docs/apis/gateway/create-anthropic-message ## Request ### Headers - `x-api-key` (string, required) — Your Respan API key in Anthropic's native authentication header. Bearer authentication is also accepted. - `anthropic-version` (string, optional, default: 2023-06-01) - `anthropic-beta` (string, optional) ### Body (application/json) This endpoint expects an object. - `model` (string, required) - `max_tokens` (integer, required) - `messages` (list of map from string to any, required) - `stream` (boolean, optional, default: false) - `respan_params` (map from string to any, optional) ## Response ### 200 Anthropic response or event stream. - `map from string to any` ## Errors ### 400 Bad Request Error Invalid request. - `map from string to any` ### 402 Payment Required Error Insufficient credits. - `map from string to any` ### 403 Forbidden Error The API key is missing, invalid or expired. - `detail` (string, required) ### 424 Failed Dependency Error Upstream provider failed. - `map from string to any` ### 429 Too Many Requests Error Rate limit exceeded. - `map from string to any` ## Examples **Request** ```json { "model": "claude-sonnet-4-5-20250929", "max_tokens": 64, "messages": [ { "role": "user", "content": "Explain how AI works in a few words." } ] } ``` **Response** ```json { "id": "msg_example", "type": "message", "role": "assistant", "model": "claude-sonnet-4-5-20250929", "content": [ { "type": "text", "text": "AI learns patterns from data to make predictions and generate responses." } ], "stop_reason": "end_turn", "stop_sequence": null } ``` **SDK Code** ```python Anthropic Gateway_api_anthropic_v1_messages_create_example import requests url = "https://api.respan.ai/api/anthropic/v1/messages" payload = { "model": "claude-sonnet-4-5-20250929", "max_tokens": 64, "messages": [ { "role": "user", "content": "Explain how AI works in a few words." } ] } headers = { "x-api-key": "YOUR_RESPAN_API_KEY", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Anthropic Gateway_api_anthropic_v1_messages_create_example const url = 'https://api.respan.ai/api/anthropic/v1/messages'; const options = { method: 'POST', headers: {'x-api-key': 'YOUR_RESPAN_API_KEY', 'Content-Type': 'application/json'}, body: '{"model":"claude-sonnet-4-5-20250929","max_tokens":64,"messages":[{"role":"user","content":"Explain how AI works in a few words."}]}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Anthropic Gateway_api_anthropic_v1_messages_create_example package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.respan.ai/api/anthropic/v1/messages" payload := strings.NewReader("{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"max_tokens\": 64,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain how AI works in a few words.\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("x-api-key", "YOUR_RESPAN_API_KEY") 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 Anthropic Gateway_api_anthropic_v1_messages_create_example require 'uri' require 'net/http' url = URI("https://api.respan.ai/api/anthropic/v1/messages") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["x-api-key"] = 'YOUR_RESPAN_API_KEY' request["Content-Type"] = 'application/json' request.body = "{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"max_tokens\": 64,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain how AI works in a few words.\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java Anthropic Gateway_api_anthropic_v1_messages_create_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.respan.ai/api/anthropic/v1/messages") .header("x-api-key", "YOUR_RESPAN_API_KEY") .header("Content-Type", "application/json") .body("{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"max_tokens\": 64,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain how AI works in a few words.\"\n }\n ]\n}") .asString(); ``` ```php Anthropic Gateway_api_anthropic_v1_messages_create_example request('POST', 'https://api.respan.ai/api/anthropic/v1/messages', [ 'body' => '{ "model": "claude-sonnet-4-5-20250929", "max_tokens": 64, "messages": [ { "role": "user", "content": "Explain how AI works in a few words." } ] }', 'headers' => [ 'Content-Type' => 'application/json', 'x-api-key' => 'YOUR_RESPAN_API_KEY', ], ]); echo $response->getBody(); ``` ```csharp Anthropic Gateway_api_anthropic_v1_messages_create_example using RestSharp; var client = new RestClient("https://api.respan.ai/api/anthropic/v1/messages"); var request = new RestRequest(Method.POST); request.AddHeader("x-api-key", "YOUR_RESPAN_API_KEY"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"model\": \"claude-sonnet-4-5-20250929\",\n \"max_tokens\": 64,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain how AI works in a few words.\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Anthropic Gateway_api_anthropic_v1_messages_create_example import Foundation let headers = [ "x-api-key": "YOUR_RESPAN_API_KEY", "Content-Type": "application/json" ] let parameters = [ "model": "claude-sonnet-4-5-20250929", "max_tokens": 64, "messages": [ [ "role": "user", "content": "Explain how AI works in a few words." ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/anthropic/v1/messages")! 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() ```