> ## Documentation Index
> Fetch the complete documentation index at: https://docs.near.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign in with a NEAR account

> Signs in with a message signed by a NEAR account (NEP-413). Returns an access token and a refresh token. Send a `User-Agent` header.



## OpenAPI

````yaml /api-reference/cloud-platform-openapi.json post /v1/auth/near
openapi: 3.1.0
info:
  description: Account, organization, workspace and billing routes of NEAR AI Cloud.
  title: NEAR AI Cloud Platform API
  version: '5'
servers:
  - url: https://cloud-platform.near.ai
    description: NEAR AI Cloud Platform
security: []
paths:
  /v1/auth/near:
    post:
      tags:
        - Authentication
      summary: Sign in with a NEAR account
      description: >-
        Signs in with a message signed by a NEAR account (NEP-413). Returns an
        access token and a refresh token. Send a `User-Agent` header.
      operationId: sign_in_with_near
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NearAuthRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenExchangeResponse'
          description: Signed in.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthErrorResponse'
          description: The request body is not valid.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthErrorResponse'
          description: The signed message could not be verified.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthErrorResponse'
          description: Sign-in is not available for this account.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthErrorResponse'
          description: Internal error.
components:
  schemas:
    NearAuthRequest:
      description: Request body for NEAR authentication (NEP-413).
      properties:
        payload:
          $ref: '#/components/schemas/NearPayload'
          description: The payload that was signed
        signed_message:
          $ref: '#/components/schemas/NearSignedMessage'
          description: The signed message from the wallet
      required:
        - signed_message
        - payload
      type: object
    TokenExchangeResponse:
      description: The tokens of a completed sign-in and the account they belong to.
      properties:
        access_token:
          description: 'Access token, sent as `Authorization: Bearer <token>`.'
          type: string
        refresh_token:
          description: >-
            Refresh token beginning with `rt_`. Exchange it for a new access
            token before the access token expires.
          type: string
        refresh_token_expiration:
          description: When the refresh token expires.
          format: date-time
          type: string
        user:
          $ref: '#/components/schemas/AuthResponse'
      required:
        - access_token
        - refresh_token
        - refresh_token_expiration
        - user
      type: object
    OAuthErrorResponse:
      description: The error body of the sign-in routes.
      properties:
        error:
          description: A short error code, such as `invalid_request` or `access_denied`.
          type: string
        error_description:
          description: A human-readable description of the error.
          type: string
      required:
        - error
        - error_description
      type: object
    NearPayload:
      description: The NEP-413 message that was signed.
      properties:
        callbackUrl:
          type:
            - string
            - 'null'
        message:
          description: The message that was signed.
          type: string
        nonce:
          description: A 32-byte nonce, as an array of integers.
          items:
            format: int32
            minimum: 0
            type: integer
          type: array
        recipient:
          description: The recipient the message was signed for.
          type: string
      required:
        - message
        - nonce
        - recipient
      type: object
    NearSignedMessage:
      description: The signature of a NEAR wallet over the sign-in message.
      properties:
        accountId:
          example: alice.near
          type: string
        publicKey:
          description: The public key that signed, such as `ed25519:...`.
          type: string
        signature:
          description: The base64-encoded signature.
          type: string
        state:
          type:
            - string
            - 'null'
      required:
        - accountId
        - publicKey
        - signature
      type: object
    AuthResponse:
      description: The signed-in account, as a sign-in answers it.
      properties:
        email:
          description: The email address the account signs in with.
          type: string
        message:
          type: string
        provider:
          description: 'The sign-in provider: `github`, `google` or `near`.'
          type: string
      required:
        - message
        - email
        - provider
      type: object

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.