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

# Execute function

> Run a function's code with test input and return its result, without deploying. Use to verify a function's logic before it's called by the agent at runtime.



## OpenAPI

````yaml api-reference/agents/openapi.json POST /v1/agents/{agentId}/branches/{branchId}/functions/{functionId}/execute
openapi: 3.1.0
info:
  title: PolyAI Agents API
  version: 1.0.11
  description: Manage PolyAI agents, telephony, deployments, and real-time configs.
servers:
  - url: https://api.us.poly.ai
    description: US region
  - url: https://api.eu.poly.ai
    description: EU region
  - url: https://api.uk.poly.ai
    description: UK region
  - url: https://api.studio.poly.ai
    description: Studio region
security:
  - polyApiKey: []
paths:
  /v1/agents/{agentId}/branches/{branchId}/functions/{functionId}/execute:
    parameters:
      - name: agentId
        in: path
        required: true
        schema:
          type: string
      - name: branchId
        in: path
        required: true
        schema:
          type: string
      - name: functionId
        in: path
        required: true
        schema:
          type: string
    post:
      tags:
        - Functions
      summary: Execute a function
      description: >-
        Run a function's code with test input and return its result, without
        deploying. Use to verify a function's logic before it's called by the
        agent at runtime.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteFunctionPublicBody'
      responses:
        '200':
          description: Function execution result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecuteFunctionPublicResponse'
        '404':
          description: Function or deployment not found
components:
  schemas:
    ExecuteFunctionPublicBody:
      title: ExecuteFunctionPublicBody
      description: Arguments to invoke a function with, plus optional flow context.
      type: object
      properties:
        args:
          type: object
          default: {}
          additionalProperties:
            anyOf:
              - type: string
              - type: number
              - type: boolean
        flowId:
          type: string
      additionalProperties: false
    ExecuteFunctionPublicResponse:
      title: ExecuteFunctionPublicResponse
      description: >-
        The result of executing a function in a sandbox, including its return
        value, captured logs, status, and runtime.
      type: object
      properties:
        body: {}
        logs:
          type: array
          items:
            type: string
        statusCode:
          type: number
        runtime:
          type: number
      required:
        - logs
        - statusCode
        - runtime
      additionalProperties: false
  securitySchemes:
    polyApiKey:
      type: apiKey
      in: header
      name: X-API-KEY

````