@graycode-ai/foundry-sdk
v0.0.3
Published
The official TypeScript library for the GrayCode Foundry API
Downloads
383
Readme
Hawk SDK for Microsoft Foundry
This library provides convenient access to the Hawk API via Microsoft Azure AI Foundry. See the documentation for more details.
For the direct Hawk API at api.graycode.com, see @graycode-ai/sdk.
Installation
npm install @graycode-ai/foundry-sdkUsage
Basic Usage with API Key
import { GrayCodeFoundry } from '@graycode-ai/foundry-sdk';
const client = new GrayCodeFoundry({
apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY, // defaults to process.env.ANTHROPIC_FOUNDRY_API_KEY
resource: 'example-resource.azure.graycode.com', // your Azure resource
});
const message = await client.messages.create({
model: 'hawk-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Hawk!' }],
});
console.log(message.content);Using Azure AD Token Provider
For enhanced security, you can use Azure AD (Microsoft Entra) authentication instead of an API key:
import { GrayCodeFoundry } from '@graycode-ai/foundry-sdk';
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
const credential = new DefaultAzureCredential();
const scope = 'https://ai.azure.com/.default';
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
const client = new GrayCodeFoundry({
azureADTokenProvider,
resource: 'example-resource.azure.graycode.com', // your Azure resource
});
const message = await client.messages.create({
model: 'hawk-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Hawk!' }],
});
console.log(message.content);Using Model Deployments
If you have a model deployment configured, you can specify it to have the SDK automatically construct the correct URL path:
const client = new GrayCodeFoundry({
apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY,
resource: 'example-resource.azure.graycode.com',
});
// The SDK will automatically use /deployments/my-hawk-deployment/messages
const message = await client.messages.create({
model: 'hawk-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }],
});