@anthropic-ai/sdk 0.10.2 → 0.11.0

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +9 -9
  3. package/error.d.ts.map +1 -1
  4. package/error.js +2 -1
  5. package/error.js.map +1 -1
  6. package/error.mjs +2 -1
  7. package/error.mjs.map +1 -1
  8. package/index.d.mts +9 -5
  9. package/index.d.ts +9 -5
  10. package/index.d.ts.map +1 -1
  11. package/index.js +7 -5
  12. package/index.js.map +1 -1
  13. package/index.mjs +7 -5
  14. package/index.mjs.map +1 -1
  15. package/lib/MessageStream.d.ts +94 -0
  16. package/lib/MessageStream.d.ts.map +1 -0
  17. package/lib/MessageStream.js +421 -0
  18. package/lib/MessageStream.js.map +1 -0
  19. package/lib/MessageStream.mjs +417 -0
  20. package/lib/MessageStream.mjs.map +1 -0
  21. package/package.json +3 -2
  22. package/resources/beta/beta.d.ts +25 -0
  23. package/resources/beta/beta.d.ts.map +1 -0
  24. package/resources/beta/beta.js +40 -0
  25. package/resources/beta/beta.js.map +1 -0
  26. package/resources/beta/beta.mjs +13 -0
  27. package/resources/beta/beta.mjs.map +1 -0
  28. package/resources/beta/index.d.ts +3 -0
  29. package/resources/beta/index.d.ts.map +1 -0
  30. package/resources/beta/index.js +9 -0
  31. package/resources/beta/index.js.map +1 -0
  32. package/resources/beta/index.mjs +4 -0
  33. package/resources/beta/index.mjs.map +1 -0
  34. package/resources/beta/messages.d.ts +511 -0
  35. package/resources/beta/messages.d.ts.map +1 -0
  36. package/resources/beta/messages.js +35 -0
  37. package/resources/beta/messages.js.map +1 -0
  38. package/resources/beta/messages.mjs +30 -0
  39. package/resources/beta/messages.mjs.map +1 -0
  40. package/resources/completions.d.ts +55 -40
  41. package/resources/completions.d.ts.map +1 -1
  42. package/resources/completions.js +4 -2
  43. package/resources/completions.js.map +1 -1
  44. package/resources/completions.mjs +4 -2
  45. package/resources/completions.mjs.map +1 -1
  46. package/resources/index.d.ts +1 -0
  47. package/resources/index.d.ts.map +1 -1
  48. package/resources/index.js +3 -1
  49. package/resources/index.js.map +1 -1
  50. package/resources/index.mjs +1 -0
  51. package/resources/index.mjs.map +1 -1
  52. package/src/error.ts +2 -1
  53. package/src/index.ts +11 -5
  54. package/src/lib/MessageStream.ts +515 -0
  55. package/src/resources/beta/beta.ts +28 -0
  56. package/src/resources/beta/index.ts +22 -0
  57. package/src/resources/beta/messages.ts +605 -0
  58. package/src/resources/completions.ts +62 -42
  59. package/src/resources/index.ts +1 -0
  60. package/src/streaming.ts +21 -1
  61. package/src/uploads.ts +2 -3
  62. package/src/version.ts +1 -1
  63. package/streaming.d.ts.map +1 -1
  64. package/streaming.js +15 -0
  65. package/streaming.js.map +1 -1
  66. package/streaming.mjs +15 -0
  67. package/streaming.mjs.map +1 -1
  68. package/uploads.d.ts.map +1 -1
  69. package/uploads.js +2 -1
  70. package/uploads.js.map +1 -1
  71. package/uploads.mjs +2 -1
  72. package/uploads.mjs.map +1 -1
  73. package/version.d.ts +1 -1
  74. package/version.js +1 -1
  75. package/version.mjs +1 -1
@@ -5,23 +5,29 @@ import * as CompletionsAPI from '@anthropic-ai/sdk/resources/completions';
5
5
  import { Stream } from '@anthropic-ai/sdk/streaming';
6
6
  export declare class Completions extends APIResource {
7
7
  /**
8
- * Create a completion
8
+ * Create a Completion
9
9
  */
10
- create(body: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Completion>;
11
- create(body: CompletionCreateParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<Completion>>;
12
- create(body: CompletionCreateParamsBase, options?: Core.RequestOptions): APIPromise<Stream<Completion> | Completion>;
10
+ create(params: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Completion>;
11
+ create(params: CompletionCreateParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<Completion>>;
12
+ create(params: CompletionCreateParamsBase, options?: Core.RequestOptions): APIPromise<Stream<Completion> | Completion>;
13
13
  }
14
14
  export interface Completion {
15
+ /**
16
+ * Unique object identifier.
17
+ *
18
+ * The format and length of IDs may change over time.
19
+ */
20
+ id: string;
15
21
  /**
16
22
  * The resulting completion up to and excluding the stop sequences.
17
23
  */
18
24
  completion: string;
19
25
  /**
20
- * The model that performed the completion.
26
+ * The model that handled the request.
21
27
  */
22
28
  model: string;
23
29
  /**
24
- * The reason that we stopped sampling.
30
+ * The reason that we stopped.
25
31
  *
26
32
  * This may be one the following values:
27
33
  *
@@ -30,48 +36,53 @@ export interface Completion {
30
36
  * - `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum
31
37
  */
32
38
  stop_reason: string;
39
+ type: 'completion';
33
40
  }
34
41
  export type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;
35
42
  export interface CompletionCreateParamsBase {
36
43
  /**
37
- * The maximum number of tokens to generate before stopping.
44
+ * Body param: The maximum number of tokens to generate before stopping.
38
45
  *
39
46
  * Note that our models may stop _before_ reaching this maximum. This parameter
40
47
  * only specifies the absolute maximum number of tokens to generate.
41
48
  */
42
49
  max_tokens_to_sample: number;
43
50
  /**
44
- * The model that will complete your prompt.
51
+ * Body param: The model that will complete your prompt.
45
52
  *
46
- * As we improve Claude, we develop new versions of it that you can query. This
47
- * parameter controls which version of Claude answers your request. Right now we
48
- * are offering two model families: Claude, and Claude Instant. You can use them by
49
- * setting `model` to `"claude-2"` or `"claude-instant-1"`, respectively. See
50
- * [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
51
- * additional details.
53
+ * As we improve Claude, we develop new versions of it that you can query. The
54
+ * `model` parameter controls which version of Claude responds to your request.
55
+ * Right now we offer two model families: Claude, and Claude Instant. You can use
56
+ * them by setting `model` to `"claude-2.1"` or `"claude-instant-1.2"`,
57
+ * respectively.
58
+ *
59
+ * See [models](https://docs.anthropic.com/claude/reference/selecting-a-model) for
60
+ * additional details and options.
52
61
  */
53
- model: (string & {}) | 'claude-2' | 'claude-instant-1';
62
+ model: (string & {}) | 'claude-2.1' | 'claude-instant-1';
54
63
  /**
55
- * The prompt that you want Claude to complete.
64
+ * Body param: The prompt that you want Claude to complete.
56
65
  *
57
- * For proper response generation you will need to format your prompt as follows:
66
+ * For proper response generation you will need to format your prompt using
67
+ * alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
58
68
  *
59
- * ```javascript
60
- * const userQuestion = r"Why is the sky blue?";
61
- * const prompt = `\n\nHuman: ${userQuestion}\n\nAssistant:`;
69
+ * ```
70
+ * "\n\nHuman: {userQuestion}\n\nAssistant:"
62
71
  * ```
63
72
  *
64
- * See our
65
- * [comments on prompts](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
66
- * for more context.
73
+ * See
74
+ * [prompt validation](https://anthropic.readme.io/claude/reference/prompt-validation)
75
+ * and our guide to
76
+ * [prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
77
+ * for more details.
67
78
  */
68
79
  prompt: string;
69
80
  /**
70
- * An object describing metadata about the request.
81
+ * Body param: An object describing metadata about the request.
71
82
  */
72
83
  metadata?: CompletionCreateParams.Metadata;
73
84
  /**
74
- * Sequences that will cause the model to stop generating completion text.
85
+ * Body param: Sequences that will cause the model to stop generating.
75
86
  *
76
87
  * Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
77
88
  * sequences in the future. By providing the stop_sequences parameter, you may
@@ -79,29 +90,29 @@ export interface CompletionCreateParamsBase {
79
90
  */
80
91
  stop_sequences?: Array<string>;
81
92
  /**
82
- * Whether to incrementally stream the response using server-sent events.
93
+ * Body param: Whether to incrementally stream the response using server-sent
94
+ * events.
83
95
  *
84
- * See
85
- * [this guide to SSE events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
86
- * for details.
96
+ * See [streaming](https://docs.anthropic.com/claude/reference/streaming) for
97
+ * details.
87
98
  */
88
99
  stream?: boolean;
89
100
  /**
90
- * Amount of randomness injected into the response.
101
+ * Body param: Amount of randomness injected into the response.
91
102
  *
92
103
  * Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical /
93
104
  * multiple choice, and closer to 1 for creative and generative tasks.
94
105
  */
95
106
  temperature?: number;
96
107
  /**
97
- * Only sample from the top K options for each subsequent token.
108
+ * Body param: Only sample from the top K options for each subsequent token.
98
109
  *
99
110
  * Used to remove "long tail" low probability responses.
100
111
  * [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
101
112
  */
102
113
  top_k?: number;
103
114
  /**
104
- * Use nucleus sampling.
115
+ * Body param: Use nucleus sampling.
105
116
  *
106
117
  * In nucleus sampling, we compute the cumulative distribution over all the options
107
118
  * for each subsequent token in decreasing probability order and cut it off once it
@@ -109,6 +120,10 @@ export interface CompletionCreateParamsBase {
109
120
  * `temperature` or `top_p`, but not both.
110
121
  */
111
122
  top_p?: number;
123
+ /**
124
+ * Header param:
125
+ */
126
+ 'x-api-key'?: string;
112
127
  }
113
128
  export declare namespace CompletionCreateParams {
114
129
  /**
@@ -129,21 +144,21 @@ export declare namespace CompletionCreateParams {
129
144
  }
130
145
  export interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {
131
146
  /**
132
- * Whether to incrementally stream the response using server-sent events.
147
+ * Body param: Whether to incrementally stream the response using server-sent
148
+ * events.
133
149
  *
134
- * See
135
- * [this guide to SSE events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
136
- * for details.
150
+ * See [streaming](https://docs.anthropic.com/claude/reference/streaming) for
151
+ * details.
137
152
  */
138
153
  stream?: false;
139
154
  }
140
155
  export interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {
141
156
  /**
142
- * Whether to incrementally stream the response using server-sent events.
157
+ * Body param: Whether to incrementally stream the response using server-sent
158
+ * events.
143
159
  *
144
- * See
145
- * [this guide to SSE events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
146
- * for details.
160
+ * See [streaming](https://docs.anthropic.com/claude/reference/streaming) for
161
+ * details.
147
162
  */
148
163
  stream: true;
149
164
  }
@@ -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,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,qBAAa,WAAY,SAAQ,WAAW;IAC1C;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,kCAAkC,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC;IACvG,MAAM,CACJ,IAAI,EAAE,+BAA+B,EACrC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,MAAM,CACJ,IAAI,EAAE,0BAA0B,EAChC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;CAY/C;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,GAAG,kCAAkC,GAAG,+BAA+B,CAAC;AAE1G,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;;;;;;;OASG;IACH,KAAK,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,UAAU,GAAG,kBAAkB,CAAC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AE3C;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yBAAiB,sBAAsB,CAAC;IACtC;;OAEG;IACH,UAAiB,QAAQ;QACvB;;;;;;WAMG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;IAED,KAAY,kCAAkC,GAAG,cAAc,CAAC,kCAAkC,CAAC;IACnG,KAAY,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,CAAC;CAC9F;AAED,MAAM,WAAW,kCAAmC,SAAQ,0BAA0B;IACpF;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,WAAW,+BAAgC,SAAQ,0BAA0B;IACjF;;;;;;OAMG;IACH,MAAM,EAAE,IAAI,CAAC;CACd;AAED,yBAAiB,WAAW,CAAC;IAC3B,MAAM,QAAQ,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;IACrD,MAAM,QAAQ,sBAAsB,GAAG,cAAc,CAAC,sBAAsB,CAAC;IAC7E,MAAM,QAAQ,kCAAkC,GAAG,cAAc,CAAC,kCAAkC,CAAC;IACrG,MAAM,QAAQ,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,CAAC;CAChG"}
@@ -4,12 +4,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Completions = void 0;
5
5
  const resource_1 = require("@anthropic-ai/sdk/resource");
6
6
  class Completions extends resource_1.APIResource {
7
- create(body, options) {
7
+ create(params, options) {
8
+ const { 'x-api-key': xAPIKey, ...body } = params;
8
9
  return this._client.post('/v1/complete', {
9
10
  body,
10
11
  timeout: 600000,
11
12
  ...options,
12
- stream: body.stream ?? false,
13
+ headers: { 'x-api-key': xAPIKey || '', ...options?.headers },
14
+ stream: params.stream ?? false,
13
15
  });
14
16
  }
15
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAIrD,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAa1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AAxBD,kCAwBC;AA2JD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAK3B"}
1
+ {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAIrD,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAa1C,MAAM,CACJ,MAA8B,EAC9B,OAA6B;QAE7B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE;YAC5D,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,KAAK;SAC/B,CAA4D,CAAC;IAChE,CAAC;CACF;AA1BD,kCA0BC;AA6KD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAK3B"}
@@ -1,12 +1,14 @@
1
1
  // File generated from our OpenAPI spec by Stainless.
2
2
  import { APIResource } from '@anthropic-ai/sdk/resource';
3
3
  export class Completions extends APIResource {
4
- create(body, options) {
4
+ create(params, options) {
5
+ const { 'x-api-key': xAPIKey, ...body } = params;
5
6
  return this._client.post('/v1/complete', {
6
7
  body,
7
8
  timeout: 600000,
8
9
  ...options,
9
- stream: body.stream ?? false,
10
+ headers: { 'x-api-key': xAPIKey || '', ...options?.headers },
11
+ stream: params.stream ?? false,
10
12
  });
11
13
  }
12
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAI9C,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAa1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AA2JD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,KAAX,WAAW,QAK3B"}
1
+ {"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAI9C,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAa1C,MAAM,CACJ,MAA8B,EAC9B,OAA6B;QAE7B,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE;YAC5D,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,KAAK;SAC/B,CAA4D,CAAC;IAChE,CAAC;CACF;AA6KD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,KAAX,WAAW,QAK3B"}
@@ -1,2 +1,3 @@
1
+ export { Beta } from "./beta/beta.js";
1
2
  export { Completion, CompletionCreateParams, CompletionCreateParamsNonStreaming, CompletionCreateParamsStreaming, Completions, } from "./completions.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,kCAAkC,EAClC,+BAA+B,EAC/B,WAAW,GACZ,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,kCAAkC,EAClC,+BAA+B,EAC/B,WAAW,GACZ,MAAM,eAAe,CAAC"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  // File generated from our OpenAPI spec by Stainless.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Completions = void 0;
4
+ exports.Completions = exports.Beta = void 0;
5
+ var beta_1 = require("./beta/beta.js");
6
+ Object.defineProperty(exports, "Beta", { enumerable: true, get: function () { return beta_1.Beta; } });
5
7
  var completions_1 = require("./completions.js");
6
8
  Object.defineProperty(exports, "Completions", { enumerable: true, get: function () { return completions_1.Completions; } });
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAErD,gDAMuB;AADrB,0GAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":";AAAA,qDAAqD;;;AAErD,uCAAmC;AAA1B,4FAAA,IAAI,OAAA;AACb,gDAMuB;AADrB,0GAAA,WAAW,OAAA"}
@@ -1,3 +1,4 @@
1
1
  // File generated from our OpenAPI spec by Stainless.
2
+ export { Beta } from "./beta/beta.mjs";
2
3
  export { Completions, } from "./completions.mjs";
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAE9C,EAKL,WAAW,GACZ"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAE9C,EAAE,IAAI,EAAE;OACR,EAKL,WAAW,GACZ"}
package/src/error.ts CHANGED
@@ -24,7 +24,8 @@ export class APIError extends AnthropicError {
24
24
  private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
25
25
  const msg =
26
26
  error?.message ?
27
- typeof error.message === 'string' ? error.message
27
+ typeof error.message === 'string' ?
28
+ error.message
28
29
  : JSON.stringify(error.message)
29
30
  : error ? JSON.stringify(error)
30
31
  : message;
package/src/index.ts CHANGED
@@ -19,8 +19,10 @@ export interface ClientOptions {
19
19
 
20
20
  /**
21
21
  * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
22
+ *
23
+ * Defaults to process.env['ANTHROPIC_BASE_URL'].
22
24
  */
23
- baseURL?: string;
25
+ baseURL?: string | null | undefined;
24
26
 
25
27
  /**
26
28
  * The maximum amount of time (in milliseconds) that the client should wait for a response
@@ -82,9 +84,9 @@ export class Anthropic extends Core.APIClient {
82
84
  /**
83
85
  * API Client for interfacing with the Anthropic API.
84
86
  *
85
- * @param {string | null} [opts.apiKey==process.env['ANTHROPIC_API_KEY'] ?? null]
86
- * @param {string | null} [opts.authToken==process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
87
- * @param {string} [opts.baseURL] - Override the default base URL for the API.
87
+ * @param {string | null} [opts.apiKey=process.env['ANTHROPIC_API_KEY'] ?? null]
88
+ * @param {string | null} [opts.authToken=process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
89
+ * @param {string} [opts.baseURL=process.env['ANTHROPIC_BASE_URL'] ?? https://api.anthropic.com] - Override the default base URL for the API.
88
90
  * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
89
91
  * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
90
92
  * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
@@ -93,6 +95,7 @@ export class Anthropic extends Core.APIClient {
93
95
  * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
94
96
  */
95
97
  constructor({
98
+ baseURL = Core.readEnv('ANTHROPIC_BASE_URL'),
96
99
  apiKey = Core.readEnv('ANTHROPIC_API_KEY') ?? null,
97
100
  authToken = Core.readEnv('ANTHROPIC_AUTH_TOKEN') ?? null,
98
101
  ...opts
@@ -101,7 +104,7 @@ export class Anthropic extends Core.APIClient {
101
104
  apiKey,
102
105
  authToken,
103
106
  ...opts,
104
- baseURL: opts.baseURL ?? `https://api.anthropic.com`,
107
+ baseURL: baseURL ?? `https://api.anthropic.com`,
105
108
  };
106
109
 
107
110
  super({
@@ -118,6 +121,7 @@ export class Anthropic extends Core.APIClient {
118
121
  }
119
122
 
120
123
  completions: API.Completions = new API.Completions(this);
124
+ beta: API.Beta = new API.Beta(this);
121
125
 
122
126
  protected override defaultQuery(): Core.DefaultQuery | undefined {
123
127
  return this._options.defaultQuery;
@@ -231,6 +235,8 @@ export namespace Anthropic {
231
235
  export import CompletionCreateParams = API.CompletionCreateParams;
232
236
  export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
233
237
  export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
238
+
239
+ export import Beta = API.Beta;
234
240
  }
235
241
 
236
242
  export default Anthropic;