{"id":18047315,"url":"https://github.com/cryogenicplanet/claude-function-ts","last_synced_at":"2025-07-11T05:37:50.492Z","repository":{"id":230365735,"uuid":"779183094","full_name":"CryogenicPlanet/claude-function-ts","owner":"CryogenicPlanet","description":"a small library around anthropic lib to enable claude function calling","archived":false,"fork":false,"pushed_at":"2024-04-04T05:46:20.000Z","size":71,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T05:14:15.867Z","etag":null,"topics":["anthropic","claude","function-calling"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CryogenicPlanet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-29T08:23:14.000Z","updated_at":"2024-10-23T13:29:28.000Z","dependencies_parsed_at":"2024-10-30T19:11:05.650Z","dependency_job_id":"75d27603-5308-4e35-bf39-570879f7f104","html_url":"https://github.com/CryogenicPlanet/claude-function-ts","commit_stats":null,"previous_names":["cryogenicplanet/claude-function-ts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CryogenicPlanet%2Fclaude-function-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CryogenicPlanet%2Fclaude-function-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CryogenicPlanet%2Fclaude-function-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CryogenicPlanet%2Fclaude-function-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CryogenicPlanet","download_url":"https://codeload.github.com/CryogenicPlanet/claude-function-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161277,"owners_count":21057555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anthropic","claude","function-calling"],"created_at":"2024-10-30T19:11:03.330Z","updated_at":"2025-04-10T05:14:19.519Z","avatar_url":"https://github.com/CryogenicPlanet.png","language":"TypeScript","readme":"# claude-function-ts\n\nFunction calling sdk for claude in typescript (supports JSONSchema)\n\n\n## Installation\n\nYou need to install the `anthropic-sdk` as well to use this sdk.\n\n```sh\nnpm add claude-function-ts @anthropic-ai/sdk\nyarn add claude-function-ts @anthropic-ai/sdk\npnpm add claude-function-ts @anthropic-ai/sdk\nbun add claude-function-ts @anthropic-ai/sdk\n```\n\n## Quick start (with Anthropic sdk)\n\n```ts\nimport { Anthropic } from 'claude-function-ts';\n\nconst anthropic = new Anthropic({\n  apiKey: \"YOUR_API_KEY\",\n});\n\nconst resp = await anthropic.tools\n  .create(\n    [\n    //  ...JSONSchema\n    ] as const,\n    {\n      model: \"claude-3-haiku-20240307\",\n      stream: false,\n      max_tokens: 2000,\n      messages: [\n        {\n          role: \"user\",\n          content:\n            \"Send an email to rahul,zack and malay from scalar.video, I want to talk to him about how they built their CRDTs for their video editor; I am reaching out cold\",\n        },\n      ],\n    }\n  )\n  .manual();\n```\n\n## Wrap Anthropic SDK\n\n```ts\nimport {withTools} from 'claude-function-ts';\nimport {Anthropic} from '@anthropic/anthropic-sdk';\n\nconst anthropic = new Anthropic({\n  apiKey: \"YOUR_API_KEY\",\n});\n\nconst tools = withTools(anthropic);\n\ntools.create(...)\n\n```\n\n\n## API\n\n### Tools definition\n\nWould recommend using something like `zod` to generate the json schema for the tools.\n\n```ts\n.tools.create(tool: Tool[], message: MessageParams, options: RequestOptions)\n\nexport type Tool = {\n  name: Readonly\u003cstring\u003e;\n  description: string;\n  parameters: JSONSchema;\n};\n```\n\n### Manual\n\nManual will just give you the output of one single function call, it will return either the assistant response or the tool inputs for your function call.\n\n```ts\n.tools.create(...).manual({forceFunctionCall = false}: {forceFunctionCall: boolean}): Promise\u003c\n      Result\u003c\n        | { role: \"assistant\"; content: string }\n        | { role: \"tool_inputs\"; content?: string; tool_inputs: ToolInput[] },\n        string\n      \u003e\u003e;\n\nexport type ToolInput = {\n  tool_name: string;\n  tool_arguments: unknown;\n};\n```\n\n- the `forceFunctionCall` will ensure the model ends with a function call but forcing the stop sequence\n\n### Automatic\n\nAutomatic will keep calling the assistant with the function results till the assistant stops the conversation.\n\n```ts\n.tools.create(...).automatic(cb: {\n    [toolName: string] : (params: unknown): Promise\u003c{}\u003e | {}\n}): Promise\u003c\n      Result\u003c\n        { role: \"assistant\"; content: string },\n        string\n      \u003e\n    \u003e\n```\nIn automatic mode you need to ensure you have the tool callbacks for the tools you are using in the conversation.\n\n- if you use `as const` while defining the tools, you can use the toolNames and the params will be properly typed in the callback.\n\n## Example\n\n[Automatic Code Example](./src/example/automatic.ts)\n\n\n## Disclaimer\nI think the anthropic function calling api is kinda jank and this doesn't strictly follow it, sorta diverges to enable easy arrays and objects in the `xml` output. I expect to that the xml parsing here isn't perfect and happy to accept PRs to improve it.\n\nThis is based on the alpha-sdk for function calling from anthropic [here](https://github.com/anthropics/anthropic-tools/)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryogenicplanet%2Fclaude-function-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcryogenicplanet%2Fclaude-function-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryogenicplanet%2Fclaude-function-ts/lists"}