> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.askelephant.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.askelephant.ai/_mcp/server.

# Exchange OAuth credentials for an access token

POST https://app.askelephant.ai/api/v1/oauth/token
Content-Type: application/x-www-form-urlencoded

Exchanges OAuth client or user grant credentials for an access token.

Reference: https://docs.askelephant.ai/api-reference/authentication/oauth-token

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: AskElephant Public API
  version: 1.0.0
paths:
  /v1/oauth/token:
    post:
      operationId: oauth-token
      summary: Exchange OAuth credentials for an access token
      description: Exchanges OAuth client or user grant credentials for an access token.
      tags:
        - authentication
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Access token issued successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Authentication_oauthToken_Response_200'
        '400':
          description: Invalid OAuth request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OauthTokenRequestBadRequestError'
        '401':
          description: Invalid client credentials.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OauthTokenRequestUnauthorizedError'
        '500':
          description: Server error during token exchange.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OauthTokenRequestInternalServerError'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                grant_type:
                  $ref: >-
                    #/components/schemas/V1OauthTokenPostRequestBodyContentApplicationXWwwFormUrlencodedSchemaGrantType
                client_id:
                  type: string
                  description: OAuth client ID. Required for `client_secret_post`.
                client_secret:
                  type: string
                  description: OAuth client secret. Required for `client_secret_post`.
                scope:
                  type: string
                  description: Space-delimited scopes requested for the access token.
                code:
                  type: string
                  description: Authorization code for the `authorization_code` grant.
                redirect_uri:
                  type: string
                  format: uri
                  description: Redirect URI bound to the authorization code.
                code_verifier:
                  type: string
                  description: PKCE code verifier for the authorization code exchange.
                refresh_token:
                  type: string
                  description: Refresh token for the `refresh_token` grant.
              required:
                - grant_type
servers:
  - url: https://app.askelephant.ai/api
    description: Production
  - url: https://app-staging.askelephant.ai/api
    description: Staging
components:
  schemas:
    V1OauthTokenPostRequestBodyContentApplicationXWwwFormUrlencodedSchemaGrantType:
      type: string
      enum:
        - authorization_code
        - refresh_token
        - client_credentials
      title: >-
        V1OauthTokenPostRequestBodyContentApplicationXWwwFormUrlencodedSchemaGrantType
    Authentication_oauthToken_Response_200:
      type: object
      properties:
        access_token:
          type: string
        token_type:
          type: string
        expires_in:
          type: integer
        refresh_token:
          type: string
        scope:
          type: string
      required:
        - access_token
        - token_type
        - expires_in
      title: Authentication_oauthToken_Response_200
    OauthTokenRequestBadRequestError:
      type: object
      properties:
        error:
          type: string
        error_description:
          type: string
      required:
        - error
      title: OauthTokenRequestBadRequestError
    OauthTokenRequestUnauthorizedError:
      type: object
      properties:
        error:
          type: string
        error_description:
          type: string
      required:
        - error
      title: OauthTokenRequestUnauthorizedError
    OauthTokenRequestInternalServerError:
      type: object
      properties:
        error:
          type: string
      required:
        - error
      title: OauthTokenRequestInternalServerError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

```

## Examples



**Request**

```json
{
  "grant_type": "authorization_code"
}
```

**Response**

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFsaWNlIFVzZXIiLCJpYXQiOjE2ODU2MDAwMDB9.s5X9vQ1X9vQ2X9vQ3X9vQ4X9vQ5X9vQ6X9vQ7X9vQ8",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "def50200b3a1c2d4e5f67890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  "scope": "read write"
}
```

**SDK Code**

```python
import requests

url = "https://app.askelephant.ai/api/v1/oauth/token"

payload = ""
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/x-www-form-urlencoded"
}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.askelephant.ai/api/v1/oauth/token';
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: new URLSearchParams('')
};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://app.askelephant.ai/api/v1/oauth/token"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	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://app.askelephant.ai/api/v1/oauth/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/x-www-form-urlencoded'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://app.askelephant.ai/api/v1/oauth/token")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.askelephant.ai/api/v1/oauth/token', [
  'form_params' => null,
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.askelephant.ai/api/v1/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/x-www-form-urlencoded"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://app.askelephant.ai/api/v1/oauth/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```