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

# Compile a function

> Compiles TypeScript function source code and returns the bundled JavaScript.

<Info>
  Requires an API key with the `environment:functions:compile` scope. [Learn more about API key scopes](/reference/backend/http-api/api-keys#scopes).
</Info>

Compiles TypeScript function source code and returns the bundled JavaScript.


## OpenAPI

````yaml POST /functions/compile
openapi: 3.1.0
info:
  title: Nango API
  description: Nango API specs used to authorize & sync data with external APIs.
  version: 1.0.0
servers:
  - url: https://api.nango.dev
    description: Production server
  - url: http://localhost:3003
    description: Local server
security:
  - bearerAuth: []
externalDocs:
  url: https://nango.dev/docs/reference/backend/http-api/authentication
paths:
  /functions/compile:
    post:
      summary: Compile a function
      description: >-
        Compiles TypeScript function source code and returns the bundled
        JavaScript.
      operationId: compileFunction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FunctionCompileRequest'
      responses:
        '200':
          description: Successfully compiled the function.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FunctionCompileResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/ServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
        '504':
          $ref: '#/components/responses/GatewayTimeout'
components:
  schemas:
    FunctionCompileRequest:
      type: object
      additionalProperties: false
      required:
        - code
      properties:
        code:
          type: string
          minLength: 1
          description: The TypeScript source code for the function.
    FunctionCompileResponse:
      type: object
      additionalProperties: false
      required:
        - bundle_size_bytes
        - bundled_js
        - compiled_at
      properties:
        bundle_size_bytes:
          type: integer
          minimum: 0
        bundled_js:
          type: string
          description: The bundled JavaScript output.
        compiled_at:
          type: string
          format: date-time
    StdError:
      type: object
      additionalProperties: false
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - code
          properties:
            code:
              type: string
            message:
              type: string
            errors:
              type: array
              items:
                type: object
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    ServerError:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    ServiceUnavailable:
      description: Service unavailable
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    GatewayTimeout:
      description: Gateway timeout
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: The secret key from your Nango environment.

````