@anthropic-ai/sdk 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,51 +51,11 @@ export declare namespace CompletionCreateParams {
51
51
  * The model that will complete your prompt.
52
52
  *
53
53
  * As we improve Claude, we develop new versions of it that you can query. This
54
- * controls which version of Claude answers your request. Right now we are offering
55
- * two model families: Claude and Claude Instant.
56
- *
57
- * Specifiying any of the following models will automatically switch to you the
58
- * newest compatible models as they are released:
59
- *
60
- * - `"claude-1"`: Our largest model, ideal for a wide range of more complex tasks.
61
- * - `"claude-1-100k"`: An enhanced version of `claude-1` with a 100,000 token
62
- * (roughly 75,000 word) context window. Ideal for summarizing, analyzing, and
63
- * querying long documents and conversations for nuanced understanding of complex
64
- * topics and relationships across very long spans of text.
65
- * - `"claude-instant-1"`: A smaller model with far lower latency, sampling at
66
- * roughly 40 words/sec! Its output quality is somewhat lower than the latest
67
- * `claude-1` model, particularly for complex tasks. However, it is much less
68
- * expensive and blazing fast. We believe that this model provides more than
69
- * adequate performance on a range of tasks including text classification,
70
- * summarization, and lightweight chat applications, as well as search result
71
- * summarization.
72
- * - `"claude-instant-1-100k"`: An enhanced version of `claude-instant-1` with a
73
- * 100,000 token context window that retains its performance. Well-suited for
74
- * high throughput use cases needing both speed and additional context, allowing
75
- * deeper understanding from extended conversations and documents.
76
- *
77
- * You can also select specific sub-versions of the above models:
78
- *
79
- * - `"claude-1.3"`: Compared to `claude-1.2`, it's more robust against red-team
80
- * inputs, better at precise instruction-following, better at code, and better
81
- * and non-English dialogue and writing.
82
- * - `"claude-1.3-100k"`: An enhanced version of `claude-1.3` with a 100,000 token
83
- * (roughly 75,000 word) context window.
84
- * - `"claude-1.2"`: An improved version of `claude-1`. It is slightly improved at
85
- * general helpfulness, instruction following, coding, and other tasks. It is
86
- * also considerably better with non-English languages. This model also has the
87
- * ability to role play (in harmless ways) more consistently, and it defaults to
88
- * writing somewhat longer and more thorough responses.
89
- * - `"claude-1.0"`: An earlier version of `claude-1`.
90
- * - `"claude-instant-1.1"`: Our latest version of `claude-instant-1`. It is better
91
- * than `claude-instant-1.0` at a wide variety of tasks including writing,
92
- * coding, and instruction following. It performs better on academic benchmarks,
93
- * including math, reading comprehension, and coding tests. It is also more
94
- * robust against red-teaming inputs.
95
- * - `"claude-instant-1.1-100k"`: An enhanced version of `claude-instant-1.1` with
96
- * a 100,000 token context window that retains its lightning fast 40 word/sec
97
- * performance.
98
- * - `"claude-instant-1.0"`: An earlier version of `claude-instant-1`.
54
+ * parameter controls which version of Claude answers your request. Right now we
55
+ * are offering two model families: Claude, and Claude Instant. You can use them by
56
+ * setting `model` to `"claude-2"` or `"claude-instant-1"`, respectively. See
57
+ * [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
58
+ * additional details.
99
59
  */
100
60
  model: string;
101
61
  /**
@@ -108,7 +68,8 @@ export declare namespace CompletionCreateParams {
108
68
  * const prompt = `\n\nHuman: ${userQuestion}\n\nAssistant:`;
109
69
  * ```
110
70
  *
111
- * See our [comments on prompts](https://console.anthropic.com/docs/prompt-design)
71
+ * See our
72
+ * [comments on prompts](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
112
73
  * for more context.
113
74
  */
114
75
  prompt: string;
@@ -183,51 +144,11 @@ export declare namespace CompletionCreateParams {
183
144
  * The model that will complete your prompt.
184
145
  *
185
146
  * As we improve Claude, we develop new versions of it that you can query. This
186
- * controls which version of Claude answers your request. Right now we are offering
187
- * two model families: Claude and Claude Instant.
188
- *
189
- * Specifiying any of the following models will automatically switch to you the
190
- * newest compatible models as they are released:
191
- *
192
- * - `"claude-1"`: Our largest model, ideal for a wide range of more complex tasks.
193
- * - `"claude-1-100k"`: An enhanced version of `claude-1` with a 100,000 token
194
- * (roughly 75,000 word) context window. Ideal for summarizing, analyzing, and
195
- * querying long documents and conversations for nuanced understanding of complex
196
- * topics and relationships across very long spans of text.
197
- * - `"claude-instant-1"`: A smaller model with far lower latency, sampling at
198
- * roughly 40 words/sec! Its output quality is somewhat lower than the latest
199
- * `claude-1` model, particularly for complex tasks. However, it is much less
200
- * expensive and blazing fast. We believe that this model provides more than
201
- * adequate performance on a range of tasks including text classification,
202
- * summarization, and lightweight chat applications, as well as search result
203
- * summarization.
204
- * - `"claude-instant-1-100k"`: An enhanced version of `claude-instant-1` with a
205
- * 100,000 token context window that retains its performance. Well-suited for
206
- * high throughput use cases needing both speed and additional context, allowing
207
- * deeper understanding from extended conversations and documents.
208
- *
209
- * You can also select specific sub-versions of the above models:
210
- *
211
- * - `"claude-1.3"`: Compared to `claude-1.2`, it's more robust against red-team
212
- * inputs, better at precise instruction-following, better at code, and better
213
- * and non-English dialogue and writing.
214
- * - `"claude-1.3-100k"`: An enhanced version of `claude-1.3` with a 100,000 token
215
- * (roughly 75,000 word) context window.
216
- * - `"claude-1.2"`: An improved version of `claude-1`. It is slightly improved at
217
- * general helpfulness, instruction following, coding, and other tasks. It is
218
- * also considerably better with non-English languages. This model also has the
219
- * ability to role play (in harmless ways) more consistently, and it defaults to
220
- * writing somewhat longer and more thorough responses.
221
- * - `"claude-1.0"`: An earlier version of `claude-1`.
222
- * - `"claude-instant-1.1"`: Our latest version of `claude-instant-1`. It is better
223
- * than `claude-instant-1.0` at a wide variety of tasks including writing,
224
- * coding, and instruction following. It performs better on academic benchmarks,
225
- * including math, reading comprehension, and coding tests. It is also more
226
- * robust against red-teaming inputs.
227
- * - `"claude-instant-1.1-100k"`: An enhanced version of `claude-instant-1.1` with
228
- * a 100,000 token context window that retains its lightning fast 40 word/sec
229
- * performance.
230
- * - `"claude-instant-1.0"`: An earlier version of `claude-instant-1`.
147
+ * parameter controls which version of Claude answers your request. Right now we
148
+ * are offering two model families: Claude, and Claude Instant. You can use them by
149
+ * setting `model` to `"claude-2"` or `"claude-instant-1"`, respectively. See
150
+ * [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
151
+ * additional details.
231
152
  */
232
153
  model: string;
233
154
  /**
@@ -240,7 +161,8 @@ export declare namespace CompletionCreateParams {
240
161
  * const prompt = `\n\nHuman: ${userQuestion}\n\nAssistant:`;
241
162
  * ```
242
163
  *
243
- * See our [comments on prompts](https://console.anthropic.com/docs/prompt-design)
164
+ * See our
165
+ * [comments on prompts](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
244
166
  * for more context.
245
167
  */
246
168
  prompt: string;
@@ -1 +1 @@
1
- {"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,qBAAa,WAAY,SAAQ,WAAW;IAC1C;;OAEG;IACH,MAAM,CACJ,IAAI,EAAE,sBAAsB,CAAC,6BAA6B,EAC1D,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACxC,MAAM,CACJ,IAAI,EAAE,sBAAsB,CAAC,0BAA0B,EACvD,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;CAOjD;AAED,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;OAQG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,sBAAsB,GAC9B,sBAAsB,CAAC,6BAA6B,GACpD,sBAAsB,CAAC,0BAA0B,CAAC;AAEtD,yBAAiB,sBAAsB,CAAC;IACtC,UAAiB,6BAA6B;QAC5C;;;;;WAKG;QACH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AA0B,CAAC;QAC1C;;WAEG;QACH,UAAiB,QAAQ;YACvB;;;;;;eAMG;YACH,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB;KACF;CACF;AAED,yBAAiB,WAAW,CAAC;IAC3B,MAAM,QAAQ,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;IAC1C,MAAM,QAAQ,sBAAsB,GAAG,GAAG,CAAC,sBAAsB,CAAC;CACnE"}
@@ -1 +1 @@
1
- {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAGrD,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAY1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;;QAE7B,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,KAAK,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AAlBD,kCAkBC;AA2TD,WAAiB,WAAW;AAG5B,CAAC,EAHgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAG3B"}
1
+ {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAGrD,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAY1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;;QAE7B,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,KAAK,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AAlBD,kCAkBC;AA6OD,WAAiB,WAAW;AAG5B,CAAC,EAHgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAG3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAG9C,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAY1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;;QAE7B,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,KAAK,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AA2TD,WAAiB,WAAW;AAG5B,CAAC,EAHgB,WAAW,KAAX,WAAW,QAG3B"}
1
+ {"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAG9C,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAY1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;;QAE7B,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,KAAK,EAAE,CAAC,CAAC;IACxG,CAAC;CACF;AA6OD,WAAiB,WAAW;AAG5B,CAAC,EAHgB,WAAW,KAAX,WAAW,QAG3B"}
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { fileFromPath as _fileFromPath } from 'formdata-node/file-from-path';
6
- import type { File, FilePropertyBag } from './formdata.node';
6
+ import type { File, FilePropertyBag } from './formdata.node.js';
7
7
 
8
8
  export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
9
9
 
@@ -5,7 +5,7 @@
5
5
  * in the package export map
6
6
  */
7
7
 
8
- import type { FilePropertyBag, File } from './formdata';
8
+ import type { FilePropertyBag, File } from './formdata.js';
9
9
 
10
10
  export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
11
11
 
@@ -2,7 +2,7 @@
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
4
 
5
- import { FormData } from './formdata.node';
5
+ import { FormData } from './formdata.node.js';
6
6
  import type { RequestOptions } from '../core';
7
7
  import { Readable } from 'node:stream';
8
8
  import { FormDataEncoder } from 'form-data-encoder';
@@ -2,7 +2,7 @@
2
2
  * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
3
  */
4
4
 
5
- import { FormData } from './formdata';
5
+ import { FormData } from './formdata.js';
6
6
  import type { RequestOptions } from '../core';
7
7
  import { MultipartBody } from '../uploads';
8
8
 
package/src/core.ts CHANGED
@@ -2,15 +2,15 @@ import * as qs from 'qs';
2
2
  import { VERSION } from './version';
3
3
  import { Stream } from './streaming';
4
4
  import { APIError, APIConnectionError, APIConnectionTimeoutError } from './error';
5
- import type { Readable } from '@anthropic-ai/sdk/_shims/node-readable';
6
- import { getDefaultAgent, type Agent } from '@anthropic-ai/sdk/_shims/agent';
5
+ import type { Readable } from './_shims/node-readable';
6
+ import { getDefaultAgent, type Agent } from './_shims/agent';
7
7
  import {
8
8
  fetch,
9
9
  isPolyfilled as fetchIsPolyfilled,
10
10
  type RequestInfo,
11
11
  type RequestInit,
12
12
  type Response,
13
- } from '@anthropic-ai/sdk/_shims/fetch';
13
+ } from './_shims/fetch.js';
14
14
  import { isMultipartBody } from './uploads';
15
15
  export {
16
16
  maybeMultipartFormRequestOptions,
@@ -21,7 +21,7 @@ export {
21
21
 
22
22
  const MAX_RETRIES = 2;
23
23
 
24
- type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
24
+ export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
25
25
 
26
26
  export abstract class APIClient {
27
27
  baseURL: string;
@@ -37,18 +37,20 @@ export abstract class APIClient {
37
37
  maxRetries,
38
38
  timeout = 60 * 1000, // 60s
39
39
  httpAgent,
40
+ fetch: overridenFetch,
40
41
  }: {
41
42
  baseURL: string;
42
43
  maxRetries?: number | undefined;
43
44
  timeout: number | undefined;
44
45
  httpAgent: Agent | undefined;
46
+ fetch: Fetch | undefined;
45
47
  }) {
46
48
  this.baseURL = baseURL;
47
49
  this.maxRetries = validatePositiveInteger('maxRetries', maxRetries ?? MAX_RETRIES);
48
50
  this.timeout = validatePositiveInteger('timeout', timeout);
49
51
  this.httpAgent = httpAgent;
50
52
 
51
- this.fetch = fetch;
53
+ this.fetch = overridenFetch ?? fetch;
52
54
  }
53
55
 
54
56
  protected authHeaders(): Headers {
@@ -120,6 +122,20 @@ export abstract class APIClient {
120
122
  return this.requestAPIList(Page, { method: 'get', path, ...opts });
121
123
  }
122
124
 
125
+ private calculateContentLength(body: unknown): string | null {
126
+ if (typeof body === 'string') {
127
+ if (typeof Buffer !== 'undefined') {
128
+ return Buffer.byteLength(body, 'utf8').toString();
129
+ }
130
+
131
+ const encoder = new TextEncoder();
132
+ const encoded = encoder.encode(body);
133
+ return encoded.length.toString();
134
+ }
135
+
136
+ return null;
137
+ }
138
+
123
139
  buildRequest<Req extends {}>(
124
140
  options: FinalRequestOptions<Req>,
125
141
  ): { req: RequestInit; url: string; timeout: number } {
@@ -129,12 +145,20 @@ export abstract class APIClient {
129
145
  isMultipartBody(options.body) ? options.body.body
130
146
  : options.body ? JSON.stringify(options.body, null, 2)
131
147
  : null;
132
- const contentLength = typeof body === 'string' ? body.length.toString() : null;
148
+ const contentLength = this.calculateContentLength(body);
133
149
 
134
150
  const url = this.buildURL(path!, query);
135
- const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
151
+ if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
136
152
  const timeout = options.timeout ?? this.timeout;
137
- validatePositiveInteger('timeout', timeout);
153
+ const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
154
+ const minAgentTimeout = timeout + 1000;
155
+ if ((httpAgent as any)?.options && minAgentTimeout > ((httpAgent as any).options.timeout ?? 0)) {
156
+ // Allow any given request to bump our agent active socket timeout.
157
+ // This may seem strange, but leaking active sockets should be rare and not particularly problematic,
158
+ // and without mutating agent we would need to create more of them.
159
+ // This tradeoff optimizes for performance.
160
+ (httpAgent as any).options.timeout = minAgentTimeout;
161
+ }
138
162
 
139
163
  if (this.idempotencyHeader && method !== 'get') {
140
164
  if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
package/src/index.ts CHANGED
@@ -4,7 +4,7 @@ import * as qs from 'qs';
4
4
  import * as Core from './core';
5
5
  import * as API from './resources/index';
6
6
  import * as Errors from './error';
7
- import type { Agent } from '@anthropic-ai/sdk/_shims/agent';
7
+ import type { Agent } from './_shims/agent';
8
8
  import * as Uploads from './uploads';
9
9
 
10
10
  type Config = {
@@ -35,6 +35,14 @@ type Config = {
35
35
  */
36
36
  httpAgent?: Agent;
37
37
 
38
+ /**
39
+ * Specify a custom `fetch` function implementation.
40
+ *
41
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
42
+ * defined globally.
43
+ */
44
+ fetch?: Core.Fetch | undefined;
45
+
38
46
  /**
39
47
  * The maximum number of times that the client will retry a request in case of a
40
48
  * temporary failure, like a network error or a 5XX error from the server.
@@ -81,6 +89,7 @@ export class Anthropic extends Core.APIClient {
81
89
  timeout: options.timeout,
82
90
  httpAgent: options.httpAgent,
83
91
  maxRetries: options.maxRetries,
92
+ fetch: options.fetch,
84
93
  });
85
94
  this.apiKey = options.apiKey || null;
86
95
  this._options = options;
@@ -1,9 +1,9 @@
1
1
  // File generated from our OpenAPI spec by Stainless.
2
2
 
3
- import * as Core from '@anthropic-ai/sdk/core';
4
- import { APIResource } from '@anthropic-ai/sdk/resource';
5
- import * as API from './';
6
- import { Stream } from '@anthropic-ai/sdk/streaming';
3
+ import * as Core from '../core';
4
+ import { APIResource } from '../resource';
5
+ import * as API from '.';
6
+ import { Stream } from '../streaming';
7
7
 
8
8
  export class Completions extends APIResource {
9
9
  /**
@@ -66,51 +66,11 @@ export namespace CompletionCreateParams {
66
66
  * The model that will complete your prompt.
67
67
  *
68
68
  * As we improve Claude, we develop new versions of it that you can query. This
69
- * controls which version of Claude answers your request. Right now we are offering
70
- * two model families: Claude and Claude Instant.
71
- *
72
- * Specifiying any of the following models will automatically switch to you the
73
- * newest compatible models as they are released:
74
- *
75
- * - `"claude-1"`: Our largest model, ideal for a wide range of more complex tasks.
76
- * - `"claude-1-100k"`: An enhanced version of `claude-1` with a 100,000 token
77
- * (roughly 75,000 word) context window. Ideal for summarizing, analyzing, and
78
- * querying long documents and conversations for nuanced understanding of complex
79
- * topics and relationships across very long spans of text.
80
- * - `"claude-instant-1"`: A smaller model with far lower latency, sampling at
81
- * roughly 40 words/sec! Its output quality is somewhat lower than the latest
82
- * `claude-1` model, particularly for complex tasks. However, it is much less
83
- * expensive and blazing fast. We believe that this model provides more than
84
- * adequate performance on a range of tasks including text classification,
85
- * summarization, and lightweight chat applications, as well as search result
86
- * summarization.
87
- * - `"claude-instant-1-100k"`: An enhanced version of `claude-instant-1` with a
88
- * 100,000 token context window that retains its performance. Well-suited for
89
- * high throughput use cases needing both speed and additional context, allowing
90
- * deeper understanding from extended conversations and documents.
91
- *
92
- * You can also select specific sub-versions of the above models:
93
- *
94
- * - `"claude-1.3"`: Compared to `claude-1.2`, it's more robust against red-team
95
- * inputs, better at precise instruction-following, better at code, and better
96
- * and non-English dialogue and writing.
97
- * - `"claude-1.3-100k"`: An enhanced version of `claude-1.3` with a 100,000 token
98
- * (roughly 75,000 word) context window.
99
- * - `"claude-1.2"`: An improved version of `claude-1`. It is slightly improved at
100
- * general helpfulness, instruction following, coding, and other tasks. It is
101
- * also considerably better with non-English languages. This model also has the
102
- * ability to role play (in harmless ways) more consistently, and it defaults to
103
- * writing somewhat longer and more thorough responses.
104
- * - `"claude-1.0"`: An earlier version of `claude-1`.
105
- * - `"claude-instant-1.1"`: Our latest version of `claude-instant-1`. It is better
106
- * than `claude-instant-1.0` at a wide variety of tasks including writing,
107
- * coding, and instruction following. It performs better on academic benchmarks,
108
- * including math, reading comprehension, and coding tests. It is also more
109
- * robust against red-teaming inputs.
110
- * - `"claude-instant-1.1-100k"`: An enhanced version of `claude-instant-1.1` with
111
- * a 100,000 token context window that retains its lightning fast 40 word/sec
112
- * performance.
113
- * - `"claude-instant-1.0"`: An earlier version of `claude-instant-1`.
69
+ * parameter controls which version of Claude answers your request. Right now we
70
+ * are offering two model families: Claude, and Claude Instant. You can use them by
71
+ * setting `model` to `"claude-2"` or `"claude-instant-1"`, respectively. See
72
+ * [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
73
+ * additional details.
114
74
  */
115
75
  model: string;
116
76
 
@@ -124,7 +84,8 @@ export namespace CompletionCreateParams {
124
84
  * const prompt = `\n\nHuman: ${userQuestion}\n\nAssistant:`;
125
85
  * ```
126
86
  *
127
- * See our [comments on prompts](https://console.anthropic.com/docs/prompt-design)
87
+ * See our
88
+ * [comments on prompts](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
128
89
  * for more context.
129
90
  */
130
91
  prompt: string;
@@ -208,51 +169,11 @@ export namespace CompletionCreateParams {
208
169
  * The model that will complete your prompt.
209
170
  *
210
171
  * As we improve Claude, we develop new versions of it that you can query. This
211
- * controls which version of Claude answers your request. Right now we are offering
212
- * two model families: Claude and Claude Instant.
213
- *
214
- * Specifiying any of the following models will automatically switch to you the
215
- * newest compatible models as they are released:
216
- *
217
- * - `"claude-1"`: Our largest model, ideal for a wide range of more complex tasks.
218
- * - `"claude-1-100k"`: An enhanced version of `claude-1` with a 100,000 token
219
- * (roughly 75,000 word) context window. Ideal for summarizing, analyzing, and
220
- * querying long documents and conversations for nuanced understanding of complex
221
- * topics and relationships across very long spans of text.
222
- * - `"claude-instant-1"`: A smaller model with far lower latency, sampling at
223
- * roughly 40 words/sec! Its output quality is somewhat lower than the latest
224
- * `claude-1` model, particularly for complex tasks. However, it is much less
225
- * expensive and blazing fast. We believe that this model provides more than
226
- * adequate performance on a range of tasks including text classification,
227
- * summarization, and lightweight chat applications, as well as search result
228
- * summarization.
229
- * - `"claude-instant-1-100k"`: An enhanced version of `claude-instant-1` with a
230
- * 100,000 token context window that retains its performance. Well-suited for
231
- * high throughput use cases needing both speed and additional context, allowing
232
- * deeper understanding from extended conversations and documents.
233
- *
234
- * You can also select specific sub-versions of the above models:
235
- *
236
- * - `"claude-1.3"`: Compared to `claude-1.2`, it's more robust against red-team
237
- * inputs, better at precise instruction-following, better at code, and better
238
- * and non-English dialogue and writing.
239
- * - `"claude-1.3-100k"`: An enhanced version of `claude-1.3` with a 100,000 token
240
- * (roughly 75,000 word) context window.
241
- * - `"claude-1.2"`: An improved version of `claude-1`. It is slightly improved at
242
- * general helpfulness, instruction following, coding, and other tasks. It is
243
- * also considerably better with non-English languages. This model also has the
244
- * ability to role play (in harmless ways) more consistently, and it defaults to
245
- * writing somewhat longer and more thorough responses.
246
- * - `"claude-1.0"`: An earlier version of `claude-1`.
247
- * - `"claude-instant-1.1"`: Our latest version of `claude-instant-1`. It is better
248
- * than `claude-instant-1.0` at a wide variety of tasks including writing,
249
- * coding, and instruction following. It performs better on academic benchmarks,
250
- * including math, reading comprehension, and coding tests. It is also more
251
- * robust against red-teaming inputs.
252
- * - `"claude-instant-1.1-100k"`: An enhanced version of `claude-instant-1.1` with
253
- * a 100,000 token context window that retains its lightning fast 40 word/sec
254
- * performance.
255
- * - `"claude-instant-1.0"`: An earlier version of `claude-instant-1`.
172
+ * parameter controls which version of Claude answers your request. Right now we
173
+ * are offering two model families: Claude, and Claude Instant. You can use them by
174
+ * setting `model` to `"claude-2"` or `"claude-instant-1"`, respectively. See
175
+ * [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
176
+ * additional details.
256
177
  */
257
178
  model: string;
258
179
 
@@ -266,7 +187,8 @@ export namespace CompletionCreateParams {
266
187
  * const prompt = `\n\nHuman: ${userQuestion}\n\nAssistant:`;
267
188
  * ```
268
189
  *
269
- * See our [comments on prompts](https://console.anthropic.com/docs/prompt-design)
190
+ * See our
191
+ * [comments on prompts](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
270
192
  * for more context.
271
193
  */
272
194
  prompt: string;