create method

Future<Skill> create({
  1. required Uint8List skillBytes,
  2. String? displayTitle,
})

Creates a new skill.

The skillBytes is the skill content as a ZIP archive. The displayTitle is an optional human-readable title for the skill.

Returns a Skill with information about the created skill.

Example:

final bytes = await File('my-skill.zip').readAsBytes();
final skill = await client.skills.create(
  skillBytes: bytes,
  displayTitle: 'My Custom Skill',
);
print('Created skill: ${skill.id}');

Implementation

Future<Skill> create({
  required Uint8List skillBytes,
  String? displayTitle,
}) async {
  final uri = requestBuilder.buildUrl('/v1/skills');
  // Remove content-type as multipart will set its own
  final headers = requestBuilder.buildHeaders(
    additionalHeaders: {'anthropic-beta': _betaHeader},
  )..remove('content-type');

  final request = http.MultipartRequest('POST', uri)
    ..headers.addAll(headers)
    ..files.add(
      http.MultipartFile.fromBytes(
        'skill',
        skillBytes,
        filename: 'skill.zip',
        contentType: http.MediaType('application', 'zip'),
      ),
    );
  if (displayTitle != null) {
    request.fields['display_title'] = displayTitle;
  }

  // Add authentication header
  await _applyAuthentication(request);

  final streamedResponse = await httpClient.send(request);
  final response = await http.Response.fromStream(streamedResponse);

  if (response.statusCode >= 400) {
    _throwError(response);
  }

  final json = jsonDecode(response.body) as Map<String, dynamic>;
  return Skill.fromJson(json);
}