---
title: "Create Function"
method: POST
path: "/functions"
tags: ["functions"]
---

# Create Function

`POST /functions`

Create a function

## Request body

- CreateFunctionRequest
  - `name` string, required — The name of the function. Must be unique within the project and can only contain letters, numbers, underscores and hyphens.
  - `description` string, nullable — Optional description of the function. This is used to describe the function to a user.
  - `instructions` string, required — The instructions for the function, this is the prompt that will be sent to the model to complete the task. Recommended to be concise and to the point
  - `input_schema` object, nullable — Optional input schema for the function. Can preferably include field descriptions to allow the model to reason about the input variables. Schema is validated against the input data and issues an error if it does not match. With the Opper SDKs you can define these schemas through libraries like Pydantic and Zod. For schemas with definitions, prefer using '$defs' and '#/$defs/...' references.
  - `output_schema` object, nullable — Optional output schema for the function. Can preferably include field descriptions to allow the model to reason about the output variables. Schema is validated against the output data and issues an error if it does not match. With the Opper SDKs you can define these schemas through libraries like Pydantic and Zod. For schemas with definitions, prefer using '$defs' and '#/$defs/...' references.
  - `model` union
    - string
    - Model
      - `name` string, required
      - `extra_headers` object, nullable
      - `options` object, nullable
    - object
    - union[]
      - union
        - string
        - Model
          - `name` string, required
          - `extra_headers` object, nullable
          - `options` object, nullable
        - object
  - `configuration` FunctionCallConfigurationInput
    - `invocation.few_shot.count` integer — [DEPRECATED via /call] This field is ignored when passed via /call endpoint. The system enforces a default of 3. Configure via PATCH /v2/functions/{uuid} or the Platform UI instead. The number of few-shot examples to use for the call, selected using nearest neighbor search of the function's dataset.
    - `beta.evaluation` unknown
    - `invocation.structured_generation.max_attempts` integer — The maximum number of attempts to make when generating a response matching the output schema if provided.
    - `invocation.cache.ttl` integer — The time to live for the cache in seconds. If 0, the cache is disabled.
    - `beta.invocation.input_validation.enabled` boolean — Whether to enable input validation against the input schema. This is a beta feature and is disabled by default.
    - `beta.invocation.xml_mode.enabled` boolean — Experimental: enable XML structured output. The model receives an XML schema and its response is converted back to JSON. We have observed better adherence to multi-paragraph text fields (especially with Anthropic models) when this is enabled.

## Response `201`

Successful Response

- CreateFunctionResponse
  - `name` string, required — The name of the function. Must be unique within the project and can only contain letters, numbers, underscores and hyphens.
  - `description` string, nullable — Optional description of the function. This is used to describe the function to a user.
  - `instructions` string, required — The instructions for the function, this is the prompt that will be sent to the model to complete the task. Recommended to be concise and to the point
  - `input_schema` object, nullable — Optional input schema for the function. Can preferably include field descriptions to allow the model to reason about the input variables. Schema is validated against the input data and issues an error if it does not match. With the Opper SDKs you can define these schemas through libraries like Pydantic and Zod. For schemas with definitions, prefer using '$defs' and '#/$defs/...' references.
  - `output_schema` object, nullable — Optional output schema for the function. Can preferably include field descriptions to allow the model to reason about the output variables. Schema is validated against the output data and issues an error if it does not match. With the Opper SDKs you can define these schemas through libraries like Pydantic and Zod. For schemas with definitions, prefer using '$defs' and '#/$defs/...' references.
  - `model` union
    - string
    - Model
      - `name` string, required
      - `extra_headers` object, nullable
      - `options` object, nullable
    - object
    - union[]
      - union
        - string
        - Model
          - `name` string, required
          - `extra_headers` object, nullable
          - `options` object, nullable
        - object
  - `configuration` FunctionCallConfigurationOutput
    - `invocation.few_shot.count` integer — [DEPRECATED via /call] This field is ignored when passed via /call endpoint. The system enforces a default of 3. Configure via PATCH /v2/functions/{uuid} or the Platform UI instead. The number of few-shot examples to use for the call, selected using nearest neighbor search of the function's dataset.
    - `invocation.structured_generation.max_attempts` integer — The maximum number of attempts to make when generating a response matching the output schema if provided.
    - `invocation.cache.ttl` integer — The time to live for the cache in seconds. If 0, the cache is disabled.
    - `beta.invocation.input_validation.enabled` boolean — Whether to enable input validation against the input schema. This is a beta feature and is disabled by default.
    - `beta.invocation.xml_mode.enabled` boolean — Experimental: enable XML structured output. The model receives an XML schema and its response is converted back to JSON. We have observed better adherence to multi-paragraph text fields (especially with Anthropic models) when this is enabled.
  - `id` string, uuid, required — The ID of the function
  - `dataset_id` string, uuid, nullable — The ID of the dataset associated with the function
  - `revision_id` string, uuid, nullable — The ID of the latest revision of the function
  - `observer_enabled` boolean — Whether the observer is enabled for this function. When enabled, the observer monitors and evaluates all generations.
  - `is_v3` boolean — Whether this function has been executed through the v3 API

## Other responses

- `400` — Bad Request
- `401` — Unauthorized
- `402` — Payment Required (out of credits)
- `404` — Not Found
- `409` — Conflict
- `422` — Request Validation Error

---

[API](https://skmtc.dev/opper/apis/opper-api-v2.md) · [All operations](https://skmtc.dev/opper/apis/opper-api-v2/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/opper/opper-api-v2/revisions/d3ccdaa15678/schema)
