---
title: "Create function"
method: POST
path: "/v1/function"
tags: ["Functions"]
---

# Create function

`POST /v1/function`

Create a new function. If there is an existing function in the project with the same slug as the one specified in the request, will return the existing function unmodified

## Request body

- CreateFunction
  - `project_id` string, uuid, required — Unique identifier for the project that the prompt belongs under
  - `name` string, required — Name of the prompt
  - `slug` string, required — Unique identifier for the prompt
  - `description` string, nullable — Textual description of the prompt
  - `prompt_data` PromptData, nullable — The prompt, model, and its parameters
    - `prompt` union
      - object
        - `type` 'completion', required
        - `content` string, required
      - object
        - `type` 'chat', required
        - `messages` ChatCompletionMessageParam[], required
          - union
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
        - `tools` string
      - object, nullable
    - `options` object, nullable
      - `model` string
      - `params` union
        - object
          - `use_cache` boolean
          - `temperature` number
          - `top_p` number
          - `max_tokens` number
          - `frequency_penalty` number
          - `presence_penalty` number
          - `response_format` object, nullable
            - `type` 'json_object', required
          - `tool_choice` union
            - 'auto'
            - 'none'
            - object
              - …
          - `function_call` union
            - 'auto'
            - 'none'
            - object
              - …
          - `n` number
          - `stop` string[]
        - object
          - `use_cache` boolean
          - `max_tokens` number, required
          - `temperature` number, required
          - `top_p` number
          - `top_k` number
          - `stop_sequences` string[]
          - `max_tokens_to_sample` number — This is a legacy parameter that should not be used.
        - object
          - `use_cache` boolean
          - `temperature` number
          - `maxOutputTokens` number
          - `topP` number
          - `topK` number
        - object
          - `use_cache` boolean
          - `temperature` number
          - `topK` number
        - object
          - `use_cache` boolean
      - `position` string
    - `parser` object, nullable
      - `type` 'llm_classifier', required
      - `use_cot` boolean, required
      - `choice_scores` object, required
    - `tool_functions` SavedFunctionId[], nullable
      - union
        - object
          - `type` 'function', required
          - `id` string, required
        - object
          - `type` 'global', required
          - `name` string, required
    - `origin` object, nullable
      - `prompt_id` string
      - `project_id` string
      - `prompt_version` string
  - `tags` string[], nullable — A list of tags for the prompt
  - `function_type` 'llm' | 'scorer' | 'task' | 'tool' | 'null', nullable
  - `function_data` union, required
    - object
      - `type` 'prompt', required
    - object
      - `type` 'code', required
      - `data` union, required
        - object
          - `type` 'bundle', required
          - `runtime_context` object, required
            - `runtime` 'node' | 'python', required
            - `version` string, required
          - `location` union, required
            - object
              - …
            - object
              - …
          - `bundle_id` string, required
          - `preview` string, nullable — A preview of the code
        - object
          - `type` 'inline', required
          - `runtime_context` object, required
            - `runtime` 'node' | 'python', required
            - `version` string, required
          - `code` string, required
    - object
      - `type` 'global', required
      - `name` string, required
  - `origin` object, nullable
    - `object_type` 'organization' | 'project' | 'experiment' | 'dataset' | 'prompt' | 'prompt_session' | 'group' | 'role' | 'org_member' | 'project_log' | 'org_project', required — The object type that the ACL applies to
    - `object_id` string, uuid, required — Id of the object the function is originating from
    - `internal` boolean, nullable — The function exists for internal purposes and should not be displayed in the list of functions.
  - `function_schema` object, nullable — JSON schema for the function's parameters and return type
    - `parameters` unknown
    - `returns` unknown

## Response `200`

Returns the new function object

- Function
  - `id` string, uuid, required — Unique identifier for the prompt
  - `_xact_id` string, required — The transaction id of an event is unique to the network operation that processed the event insertion. Transaction ids are monotonically increasing over time and can be used to retrieve a versioned snapshot of the prompt (see the `version` parameter)
  - `project_id` string, uuid, required — Unique identifier for the project that the prompt belongs under
  - `log_id` 'p', required — A literal 'p' which identifies the object as a project prompt
  - `org_id` string, uuid, required — Unique identifier for the organization
  - `name` string, required — Name of the prompt
  - `slug` string, required — Unique identifier for the prompt
  - `description` string, nullable — Textual description of the prompt
  - `created` string, date-time, nullable — Date of prompt creation
  - `prompt_data` PromptData, nullable — The prompt, model, and its parameters
    - `prompt` union
      - object
        - `type` 'completion', required
        - `content` string, required
      - object
        - `type` 'chat', required
        - `messages` ChatCompletionMessageParam[], required
          - union
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
            - object
              - …
        - `tools` string
      - object, nullable
    - `options` object, nullable
      - `model` string
      - `params` union
        - object
          - `use_cache` boolean
          - `temperature` number
          - `top_p` number
          - `max_tokens` number
          - `frequency_penalty` number
          - `presence_penalty` number
          - `response_format` object, nullable
            - `type` 'json_object', required
          - `tool_choice` union
            - 'auto'
            - 'none'
            - object
              - …
          - `function_call` union
            - 'auto'
            - 'none'
            - object
              - …
          - `n` number
          - `stop` string[]
        - object
          - `use_cache` boolean
          - `max_tokens` number, required
          - `temperature` number, required
          - `top_p` number
          - `top_k` number
          - `stop_sequences` string[]
          - `max_tokens_to_sample` number — This is a legacy parameter that should not be used.
        - object
          - `use_cache` boolean
          - `temperature` number
          - `maxOutputTokens` number
          - `topP` number
          - `topK` number
        - object
          - `use_cache` boolean
          - `temperature` number
          - `topK` number
        - object
          - `use_cache` boolean
      - `position` string
    - `parser` object, nullable
      - `type` 'llm_classifier', required
      - `use_cot` boolean, required
      - `choice_scores` object, required
    - `tool_functions` SavedFunctionId[], nullable
      - union
        - object
          - `type` 'function', required
          - `id` string, required
        - object
          - `type` 'global', required
          - `name` string, required
    - `origin` object, nullable
      - `prompt_id` string
      - `project_id` string
      - `prompt_version` string
  - `tags` string[], nullable — A list of tags for the prompt
  - `metadata` object, nullable — User-controlled metadata about the prompt
  - `function_type` 'llm' | 'scorer' | 'task' | 'tool' | 'null', nullable
  - `function_data` union, required
    - object
      - `type` 'prompt', required
    - object
      - `type` 'code', required
      - `data` union, required
        - object
          - `type` 'bundle', required
          - `runtime_context` object, required
            - `runtime` 'node' | 'python', required
            - `version` string, required
          - `location` union, required
            - object
              - …
            - object
              - …
          - `bundle_id` string, required
          - `preview` string, nullable — A preview of the code
        - object
          - `type` 'inline', required
          - `runtime_context` object, required
            - `runtime` 'node' | 'python', required
            - `version` string, required
          - `code` string, required
    - object
      - `type` 'global', required
      - `name` string, required
  - `origin` object, nullable
    - `object_type` 'organization' | 'project' | 'experiment' | 'dataset' | 'prompt' | 'prompt_session' | 'group' | 'role' | 'org_member' | 'project_log' | 'org_project', required — The object type that the ACL applies to
    - `object_id` string, uuid, required — Id of the object the function is originating from
    - `internal` boolean, nullable — The function exists for internal purposes and should not be displayed in the list of functions.
  - `function_schema` object, nullable — JSON schema for the function's parameters and return type
    - `parameters` unknown
    - `returns` unknown

## Other responses

- `400` — The request was unacceptable, often due to missing a required parameter
- `401` — No valid API key provided
- `403` — The API key doesn’t have permissions to perform the request
- `429` — Too many requests hit the API too quickly. We recommend an exponential backoff of your requests
- `500` — Something went wrong on Braintrust's end. (These are rare.)

## Changes

- **2024-09-30** `ac2727014d93` — 8 breaking, 2 info
  - the response's body became nullable
  - the response's body became nullable
  - the response's body became nullable
  - the response's body became nullable
  - …6 more
- **2024-09-25** `68955d9009ff` — 1 breaking, 1 info
  - removed the enum value `undefined` of the request property `origin/object_type`
  - removed the `undefined` enum value from the `origin/object_type` response property for the response status `200`
- **2024-09-24** `a774951c03d7` — 5 breaking, 4 warning, 7 info
  - the `function_data/anyOf[subschema #2: code]/data/anyOf[subschema #1: bundle]/allOf[subschema #2]/location` request property type/format changed from `object`/`` to ``/``
  - the `function_data/anyOf[subschema #2: code]/data/anyOf[subschema #1: bundle]/allOf[subschema #2]/location` response's property type/format changed from `object`/`` to ``/`` for status `200`
  - removed the required property `function_data/anyOf[subschema #2: code]/data/anyOf[subschema #1: bundle]/allOf[subschema #2]/location/eval_name` from the response with the `200` status
  - removed the required property `function_data/anyOf[subschema #2: code]/data/anyOf[subschema #1: bundle]/allOf[subschema #2]/location/position` from the response with the `200` status
  - …12 more
- …earlier changes not shown

[Full history](https://skmtc.dev/braintrustdata/apis/braintrust-api/changes/v1/function/post.md)

---

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