Skip to content

Releases: anthropics/anthropic-sdk-typescript

v0.5.2

08 Jul 00:06
85b29d5
Compare
Choose a tag to compare
  1. Include README in dist
  2. Improve streaming

Full Changelog: v0.5.1...v0.5.2

v0.5.1

07 Jul 20:47
387bd17
Compare
Choose a tag to compare

What's Changed

  • Improved support for ESM & more platforms, including:
    • Cloudflare Workers
    • Vercel Edge Runtime
    • Deno
  • Increase default timeout to 10 minutes for completions
  • Minor improvements to api.md
  • Refactor internal structure to use a src/ directory
  • Add support for a defaultQuery client option
  • Improvements to documentation for client options
  • Deprecate .responseHeaders, stream.response & stream.responseHeaders

Full Changelog: v0.5.0...v0.5.1

v0.5.0 – ⚠️ BREAKING, fully rewritten library

28 Jun 02:57
d5552a5
Compare
Choose a tag to compare

Migration from v0.4.x and below

In v0.5.0, we introduced a fully rewritten SDK. The new version offers better error handling, a more robust and intuitive streaming implementation, and more.

Key interface changes:

  1. new Client(apiKey)new Anthropic({ apiKey })
  2. client.complete()client.completions.create()
  3. client.completeStream()client.completions.create({ stream: true })
    1. onUpdate callback → for await (const x of stream)
    2. full message in stream → delta of message in stream
Example diff
  // Import "Anthropic" instead of "Client":
- import { Client, HUMAN_PROMPT, AI_PROMPT } from '@anthropic-ai/sdk';
+ import Anthropic, { HUMAN_PROMPT, AI_PROMPT } from '@anthropic-ai/sdk';

  // Instantiate with "apiKey" as an object property:
- const client = new Client(apiKey);
+ const client = new Anthropic({ apiKey });
  // or, simply provide an ANTHROPIC_API_KEY environment variable:
+ const client = new Anthropic();

  async function main() {
    // Request & response types are the same as before, but better-typed.
    const params = {
      prompt: `${HUMAN_PROMPT} How many toes do dogs have?${AI_PROMPT}`,
      max_tokens_to_sample: 200,
      model: "claude-1",
    };

    // Instead of "client.complete()", you now call "client.completions.create()":
-   await client.complete(params);
+   await client.completions.create(params);

    // Streaming requests now use async iterators instead of callbacks:
-   client.completeStream(params, {
-     onUpdate: (completion) => {
-       console.log(completion.completion); // full text
-     },
-   });
+   const stream = await client.completions.create({ ...params, stream: true });
+   for await (const completion of stream) {
+     console.log(completion.completion); // incremental text
+   }

    // And, since this library uses `Anthropic-Version: 2023-06-01`,
    // completion streams are now incremental diffs of text
    // rather than sending the whole message every time:
    let text = '';
-   await client.completeStream(params, {
-     onUpdate: (completion) => {
-       const diff = completion.completion.replace(text, "");
-       text = completion.completion;
-       process.stdout.write(diff);
-     },
-   });
+   const stream = await client.completions.create({ ...params, stream: true });
+   for await (const completion of stream) {
+     const diff = completion.completion;
+     text += diff;
+     process.stdout.write(diff);
+   }
    console.log('Done; final text is:')
    console.log(text)
  }
  main();

v0.4.4

05 Jun 20:25
e071caf
Compare
Choose a tag to compare

What's Changed

  • Add pinned server version, fix sdk version header, bump local version. by @jenan-anthropic in #21

New Contributors

Full Changelog: v0.4.3...v0.4.4

v0.4.3

04 Apr 12:25
ec96afb
Compare
Choose a tag to compare

What's Changed

  • Add cancellation support using AbortController/AbortSignal by @jspahrsummers in #13

Full Changelog: v0.4.2...v0.4.3

v0.4.2

24 Feb 10:21
493075d
Compare
Choose a tag to compare

What's Changed

  • Expose tags parameter for custom metadata with completion calls by @jspahrsummers in #12

Full Changelog: v0.4.1...v0.4.2

v0.4.1

22 Feb 10:31
Compare
Choose a tag to compare

What's Changed

Full Changelog: v0.4.0...v0.4.1

v0.4.0

08 Feb 14:56
2ea3ea1
Compare
Choose a tag to compare

What's Changed

  • Add cross-fetch polyfill to support older Node versions by @jspahrsummers in #7

Full Changelog: v0.3.1...v0.4.0

v0.3.1

07 Feb 12:48
Compare
Choose a tag to compare

Full Changelog: v0.3.0...v0.3.1

v0.3.0

07 Feb 09:47
2567bce
Compare
Choose a tag to compare

What's Changed

Full Changelog: v0.2.4...v0.3.0