> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://documentation.sayari.com/api/api-reference/auth/get-token/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://documentation.sayari.com/_mcp/server. # Get Token POST https://api.sayari.com/oauth/token Content-Type: application/json Hit the auth endpoint to get a bearer token Reference: https://documentation.sayari.com/api/api-reference/auth/get-token ## Servers - `https://api.sayari.com` (Production, default) - `https://api.internal.sayari.com` (Dev) - `https://api.uk.sayari.com` (Production_UK) ## Request ### Body (application/json) This endpoint expects an object. - `client_id` (string, required) - `client_secret` (string, required) - `audience` ("sayari.com", required) - `grant_type` ("client_credentials", required) ## Response ### 200 OK - `access_token` (string, required) — The bearer token you will pass in to subsequent API calls to authenticate. - `expires_in` (integer, required) — Tells you how long (in seconds) until your bearer token expires. - `token_type` (string, required) — Will always be "Bearer" ## Errors ### 400 Bad Request - `any` ### 401 Unauthorized - `any` ### 500 Internal Server Error - `any` ## Examples **Request** ```json { "client_id": "your client_id here", "client_secret": "your client_secret here", "audience": "sayari.com", "grant_type": "client_credentials" } ``` **Response** ```json { "access_token": "sk_test_4eC39HqLyjWDarjtT1zdp7dc", "expires_in": 86400, "token_type": "Bearer" } ``` **SDK Code** ```python import requests url = "https://api.sayari.com/oauth/token" payload = { "client_id": "your client_id here", "client_secret": "your client_secret here", "audience": "sayari.com", "grant_type": "client_credentials" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```typescript import { SayariClient } from "sayari"; const sayari = new SayariClient({ clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET" }); await sayari.auth.getToken({ clientId: "your client_id here", clientSecret: "your client_secret here", audience: "sayari.com", grantType: "client_credentials" }); ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.sayari.com/oauth/token" payload := strings.NewReader("{\n \"client_id\": \"your client_id here\",\n \"client_secret\": \"your client_secret here\",\n \"audience\": \"sayari.com\",\n \"grant_type\": \"client_credentials\"\n}") req, _ := http.NewRequest("POST", url, payload) 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.sayari.com/oauth/token") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request.body = "{\n \"client_id\": \"your client_id here\",\n \"client_secret\": \"your client_secret here\",\n \"audience\": \"sayari.com\",\n \"grant_type\": \"client_credentials\"\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.sayari.com/oauth/token") .header("Content-Type", "application/json") .body("{\n \"client_id\": \"your client_id here\",\n \"client_secret\": \"your client_secret here\",\n \"audience\": \"sayari.com\",\n \"grant_type\": \"client_credentials\"\n}") .asString(); ``` ```php request('POST', 'https://api.sayari.com/oauth/token', [ 'body' => '{ "client_id": "your client_id here", "client_secret": "your client_secret here", "audience": "sayari.com", "grant_type": "client_credentials" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.sayari.com/oauth/token"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"client_id\": \"your client_id here\",\n \"client_secret\": \"your client_secret here\",\n \"audience\": \"sayari.com\",\n \"grant_type\": \"client_credentials\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "client_id": "your client_id here", "client_secret": "your client_secret here", "audience": "sayari.com", "grant_type": "client_credentials" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.sayari.com/oauth/token")! 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() ```