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

# code

> Create an authored Code node with field bindings and Python source.

```ts theme={null}
import type { AuthoredCodeNode, AuthoringIdOptions, CodeAuthoringSettings } from "@toloka-platform/sdk";

declare function code(
  name: string,
  settings: CodeAuthoringSettings,
  options?: AuthoringIdOptions,
): AuthoredCodeNode;
```

## Parameters

**name** `string` *required*

Name used to derive the node ID. Also set `settings.about.name`; this constructor does not fill it for you.

**settings** `CodeAuthoringSettings` *required*

Python source, field bindings, and node settings. See the [Code node reference](https://docs.platform.toloka.ai/docs/data/reference/nodes/code.md) for runtime behavior, environment variables, and platform checks.

**Authoring settings**

**about** `CodeNodeSettings['about']` *required*

Node name and optional description.

**input** `readonly \{ field: Field; optional: boolean \}[]` *required*

Fields read by the node. Reuse declared `Field` objects.

**output** `readonly \{ field: Field; optional: boolean \}[]` *required*

Fields written by the node. [`optional(field)`](https://docs.platform.toloka.ai/docs/sdk/reference/field#optional-bindings) constructs an optional binding.

**code** `\{ code: string \}` *required*

Python source with an async `main(inputs)` function.

**envVars** `CodeNodeSettings['envVars']`

Array of static values and project-secret references. Each entry has one of these shapes.

**Static entry**

**type** `'static'` *required*

Selects a literal value.

**name** `string` *required*

Environment variable name exposed to Python.

**value** `string` *required*

Environment variable value.

**Secret reference**

**type** `'secret'` *required*

Selects a project secret.

**name** `string` *required*

Environment variable name exposed to Python.

**secretName** `string` *required*

Name of the project secret to read.

**checks** `CodeNodeSettings['checks']`

Platform check definitions, separate from [local tests](https://docs.platform.toloka.ai/docs/sdk/testing.md).

**Check settings**

**code** `array`

Saved Code checks.

**Check fields**

**id** `string` *required*

Check identifier.

**name** `string` *required*

Check display name.

**input** `string | Record\<string, string\>` *required*

JSON sample input as a string, or as an object with an `input` key containing that string.

**options** `AuthoringIdOptions` (default: \{})

Optional identity override.

**Options**

**id** `string`

Explicit graph node ID. Otherwise derived from the node type and name.

## Returns

**node** `AuthoredCodeNode`

Add the node to `definePipeline({ nodes })` and connect its ports.

**Node properties**

**id** `string`

Graph node ID.

**type** `'code'`

Node type.

**settings** `CodeNodeSettings`

Settings with field objects compiled to graph references.

**input** `InputPort`

Port for incoming connections.

**output** `OutputPort`

Port for outgoing connections.

Construction does not execute Python. Use [`runCodeNode` or `test.code`](https://docs.platform.toloka.ai/docs/sdk/testing#test-a-code-node) to exercise it locally.

The `SERVICE_TOKEN` environment variable references a project secret named `service_token`; create that secret before running the node on the platform.

```ts theme={null}
import { code, field } from "@toloka-platform/sdk";

const text = field("text", { type: "string" });
const normalized = field("normalized", { type: "string" });

export const normalize = code("normalize", {
  about: { name: "normalize" },
  input: [{ field: text, optional: false }],
  output: [{ field: normalized, optional: false }],
  envVars: [
    { type: "static", name: "LOG_LEVEL", value: "info" },
    { type: "secret", name: "SERVICE_TOKEN", secretName: "service_token" },
  ],
  code: {
    code: 'async def main(inputs):\n    return {"normalized": inputs["text"].strip()}\n',
  },
});
```


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