Skip to content

Commit 40b0e87

Browse files
committed
1 parent 34e041e commit 40b0e87

29 files changed

+3833
-12
lines changed

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
".": "0.69.0",
33
"packages/vertex-sdk": "0.14.0",
4-
"packages/bedrock-sdk": "0.26.0"
4+
"packages/bedrock-sdk": "0.26.0",
5+
"packages/foundry-sdk": "0.1.0"
56
}

bin/replace-internal-symlinks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -euo pipefail
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
99
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
1010

11-
PACKAGES=("bedrock-sdk" "vertex-sdk")
11+
PACKAGES=("bedrock-sdk" "vertex-sdk" "foundry-sdk")
1212

1313
for package in "${PACKAGES[@]}"; do
1414
PACKAGE_DIR="$ROOT_DIR/packages/$package"

packages/foundry-sdk/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
node_modules/
2+
dist/
3+
deno/
4+
.DS_Store
5+
*.log
6+
.env
7+
.env.*
8+
!.env.example
9+
*.tgz
10+
.yarn/
11+
yarn-error.log
12+
coverage/
13+
.nyc_output/
14+
.vscode/
15+
.idea/
16+
*.swp
17+
*.swo
18+
*~

packages/foundry-sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

packages/foundry-sdk/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Anthropic Foundry
2+
3+
To use this library with Foundry, use the `AnthropicFoundry`
4+
class instead of the `Anthropic` class.
5+
6+
## Installation
7+
8+
```bash
9+
npm install @anthropic-ai/foundry-sdk
10+
```
11+
12+
## Usage
13+
14+
### Basic Usage with API Key
15+
16+
```ts
17+
import { AnthropicFoundry } from '@anthropic-ai/foundry-sdk';
18+
19+
const client = new AnthropicFoundry({
20+
apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY, // defaults to process.env.ANTHROPIC_FOUNDRY_API_KEY
21+
resource: 'example-resource.azure.anthropic.com', // your Azure resource
22+
});
23+
24+
const message = await client.messages.create({
25+
model: 'claude-3-5-sonnet-20241022',
26+
max_tokens: 1024,
27+
messages: [{ role: 'user', content: 'Hello, Claude!' }],
28+
});
29+
30+
console.log(message.content);
31+
```
32+
33+
### Using Azure AD Token Provider
34+
35+
For enhanced security, you can use Azure AD (Microsoft Entra) authentication instead of an API key:
36+
37+
```ts
38+
import { AnthropicFoundry } from '@anthropic-ai/foundry-sdk';
39+
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
40+
41+
const credential = new DefaultAzureCredential();
42+
const scope = 'https://ai.azure.com/.default';
43+
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
44+
45+
const client = new AnthropicFoundry({
46+
azureADTokenProvider,
47+
resource: 'example-resource.azure.anthropic.com', // your Azure resource
48+
});
49+
50+
const message = await client.messages.create({
51+
model: 'claude-3-5-sonnet-20241022',
52+
max_tokens: 1024,
53+
messages: [{ role: 'user', content: 'Hello, Claude!' }],
54+
});
55+
56+
console.log(message.content);
57+
```
58+
59+
### Using Model Deployments
60+
61+
If you have a model deployment configured, you can specify it to have the SDK automatically construct the correct URL path:
62+
63+
```ts
64+
const client = new AnthropicFoundry({
65+
apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY,
66+
resource: 'example-resource.azure.anthropic.com',
67+
});
68+
69+
// The SDK will automatically use /deployments/my-claude-deployment/messages
70+
const message = await client.messages.create({
71+
model: 'claude-3-5-sonnet-20241022',
72+
max_tokens: 1024,
73+
messages: [{ role: 'user', content: 'Hello!' }],
74+
});
75+
```

packages/foundry-sdk/build

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
4+
rm -rf dist; mkdir dist
5+
6+
# Copy src to dist/src and build from dist/src into dist, so that
7+
# the source map for index.js.map will refer to ./src/index.ts etc
8+
cp -rp src README.md dist
9+
10+
for file in LICENSE; do
11+
if [ -e "../../${file}" ]; then cp "../../${file}" dist; fi
12+
done
13+
14+
for file in CHANGELOG.md; do
15+
if [ -e "${file}" ]; then cp "${file}" dist; fi
16+
done
17+
18+
# this converts the export map paths for the dist directory
19+
# and does a few other minor things
20+
PKG_JSON_PATH=../../packages/foundry-sdk/package.json node ../../scripts/utils/make-dist-package-json.cjs > dist/package.json
21+
22+
# updates the `@anthropic-ai/sdk` dependency to point to NPM
23+
node scripts/postprocess-dist-package-json.cjs
24+
25+
# build to .js/.mjs/.d.ts files
26+
npm exec tsc-multi
27+
# we need to patch index.js so that `new module.exports()` works for cjs backwards
28+
# compat. No way to get that from index.ts because it would cause compile errors
29+
# when building .mjs
30+
DIST_PATH=./dist node ../../scripts/utils/fix-index-exports.cjs
31+
32+
cp tsconfig.dist-src.json dist/src/tsconfig.json
33+
34+
DIST_PATH=./dist PKG_IMPORT_PATH=@anthropic-ai/foundry-sdk/ node ../../scripts/utils/postprocess-files.cjs
35+
36+
# make sure that nothing crashes when we require the output CJS or
37+
# import the output ESM
38+
(cd dist && node -e 'require("@anthropic-ai/foundry-sdk")')
39+
(cd dist && node -e 'import("@anthropic-ai/foundry-sdk")' --input-type=module)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env -S npm run tsn -T
2+
3+
import AnthropicFoundry from '@anthropic-ai/foundry-sdk';
4+
5+
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
6+
7+
const credential = new DefaultAzureCredential();
8+
const scope = 'https://ai.azure.com/.default';
9+
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
10+
11+
const anthropic = new AnthropicFoundry({
12+
azureADTokenProvider,
13+
resource: 'your-foundry-anthropic-resource-name',
14+
});
15+
16+
async function main() {
17+
const message = await anthropic.messages.create({
18+
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
19+
messages: [
20+
{
21+
role: 'user',
22+
content: 'Hello!',
23+
},
24+
],
25+
max_tokens: 1024,
26+
});
27+
console.log(message);
28+
}
29+
30+
main();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env -S npm run tsn -T
2+
3+
import AnthropicFoundry from '@anthropic-ai/foundry-sdk';
4+
5+
// Make sure to set the ANTHROPIC_FOUNDRY_API_KEY and ANTHROPIC_FOUNDRY_RESOURCE
6+
// environment variables before running this example.
7+
const anthropic = new AnthropicFoundry({});
8+
9+
async function main() {
10+
const message = await anthropic.messages.create({
11+
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
12+
messages: [
13+
{
14+
role: 'user',
15+
content: 'Hello!',
16+
},
17+
],
18+
max_tokens: 1024,
19+
});
20+
console.log(message);
21+
}
22+
23+
main();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { JestConfigWithTsJest } from 'ts-jest';
2+
3+
const config: JestConfigWithTsJest = {
4+
preset: 'ts-jest/presets/default-esm',
5+
testEnvironment: 'node',
6+
transform: {
7+
'^.+\\.(t|j)sx?$': ['@swc/jest', { sourceMaps: 'inline' }],
8+
},
9+
moduleNameMapper: {
10+
'^@anthropic-ai/foundry-sdk$': '<rootDir>/src/index.ts',
11+
'^@anthropic-ai/foundry-sdk/(.*)$': '<rootDir>/src/$1',
12+
},
13+
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/deno/'],
14+
testPathIgnorePatterns: ['scripts'],
15+
};
16+
17+
export default config;

packages/foundry-sdk/package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@anthropic-ai/foundry-sdk",
3+
"version": "0.1.0",
4+
"description": "The official TypeScript library for the Anthropic Foundry API",
5+
"author": "Anthropic <[email protected]>",
6+
"types": "dist/index.d.ts",
7+
"main": "dist/index.js",
8+
"type": "commonjs",
9+
"repository": "github:anthropics/anthropic-sdk-typescript",
10+
"license": "MIT",
11+
"packageManager": "[email protected]",
12+
"private": false,
13+
"scripts": {
14+
"test": "jest",
15+
"build": "bash ./build",
16+
"prepack": "echo 'to pack, run yarn build && (cd dist; yarn pack)' && exit 1",
17+
"prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1",
18+
"format": "prettier --write --cache --cache-strategy metadata . !dist",
19+
"prepare": "if [ $(basename $(dirname $PWD)) = 'node_modules' ]; then npm run build; fi",
20+
"tsn": "ts-node -r tsconfig-paths/register",
21+
"lint": "eslint --ext ts,js .",
22+
"fix": "eslint --fix --ext ts,js ."
23+
},
24+
"dependencies": {
25+
"@anthropic-ai/sdk": "file:../../dist/"
26+
},
27+
"devDependencies": {
28+
"@types/jest": "^29.4.0",
29+
"@types/node": "^20.17.6",
30+
"@typescript-eslint/eslint-plugin": "^6.7.0",
31+
"@typescript-eslint/parser": "^6.7.0",
32+
"eslint": "^8.49.0",
33+
"eslint-plugin-prettier": "^5.0.1",
34+
"eslint-plugin-unused-imports": "^3.0.0",
35+
"jest": "^29.4.0",
36+
"prettier": "^3.0.0",
37+
"ts-jest": "^29.1.0",
38+
"ts-morph": "^19.0.0",
39+
"ts-node": "^10.5.0",
40+
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.3/tsc-multi.tgz",
41+
"tsconfig-paths": "^4.0.0",
42+
"typescript": "5.8.3"
43+
},
44+
"imports": {
45+
"@anthropic-ai/foundry-sdk": ".",
46+
"@anthropic-ai/foundry-sdk/*": "./src/*"
47+
},
48+
"exports": {
49+
".": {
50+
"require": {
51+
"types": "./dist/index.d.ts",
52+
"default": "./dist/index.js"
53+
},
54+
"types": "./dist/index.d.mts",
55+
"default": "./dist/index.mjs"
56+
},
57+
"./*.mjs": {
58+
"types": "./dist/*.d.ts",
59+
"default": "./dist/*.mjs"
60+
},
61+
"./*.js": {
62+
"types": "./dist/*.d.ts",
63+
"default": "./dist/*.js"
64+
},
65+
"./*": {
66+
"types": "./dist/*.d.ts",
67+
"require": "./dist/*.js",
68+
"default": "./dist/*.mjs"
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)