Skip to content

jkawamoto/go-civitai

Repository files navigation

Civitai API client

OpenAPI client library GoDoc OpenAPI spec

A Civitai API client generated by go-swagger.

Installation

go get github.com/jkawamoto/go-civitai

Examples

GetCreators API

This example fetches 3 creators and prints their name and the number of models.

func ExampleGetCreators() {
	ctx := context.Background()

	res, err := client.Default.Operations.GetCreators(
		operations.NewGetCreatorsParamsWithContext(ctx).WithLimit(swag.Int64(3)))
	if err != nil {
		log.Fatal(err)
	}

	for _, v := range res.Payload.Items {
		log.Println(v.Username, v.ModelCount)
	}
}

See the API reference to find the details of parameters and responses.

GetImages API

This example fetches 3 images and prints their usernames and URLs.

func ExampleGetImages() {
    ctx := context.Background()

    res, err := client.Default.Operations.GetImages(
        operations.NewGetImagesParamsWithContext(ctx).WithLimit(swag.Int64(3)))
    if err != nil {
        log.Fatal(err)
    }

    for _, v := range res.Payload.Items {
        log.Println(v.Username, v.URL)
    }
}

See the API reference to find the details of parameters and responses.

GetModels API

This example fetches 3 models and prints their name, ID, and tags.

func ExampleGetModels() {
	ctx := context.Background()

	res, err := client.Default.Operations.GetModels(
		operations.NewGetModelsParamsWithContext(ctx).WithLimit(swag.Int64(3)))
	if err != nil {
		log.Fatal(err)
	}

	for _, v := range res.Payload.Items {
		log.Println(v.Name, v.ID, v.Tags)
	}
}

See the API reference to find the details of parameters and responses.

GetModel API

This example retrieves one model by its ID and prints its model versions.

func ExampleGetModel() {
	ctx := context.Background()

	res, err := client.Default.Operations.GetModel(
		operations.NewGetModelParamsWithContext(ctx).WithModelID(6424))
	if err != nil {
		log.Fatal(err)
	}

	for _, v := range res.Payload.ModelVersions {
		log.Println(v.Name, v.DownloadURL, v.ID, v.Files[0].ID)
	}
}

See the API reference to find the details of parameters and responses.

GetModelVersion API

This example retrieves a model version by its ID and prints the version name and when it was created.

func ExampleGetModelVersion() {
	ctx := context.Background()

	res, err := client.Default.Operations.GetModelVersion(
		operations.NewGetModelVersionParamsWithContext(ctx).WithModelVersionID(8958))
	if err != nil {
		log.Fatal(err)
	}

	log.Println(res.Payload.Name, res.Payload.CreatedAt)
}

See the API reference to find the details of parameters and responses.

GetModelVersionByHash API

This example retrieves a model version by its hash and prints the version name and when it was updated.

func ExampleGetModelVersionByHash() {
	ctx := context.Background()
	hash := "64018b0e58e2495dbdc6b5ddfd97b39528af531c97ab4073ff13b45858a200a2"

	res, err := client.Default.Operations.GetModelVersionByHash(
		operations.NewGetModelVersionByHashParamsWithContext(ctx).WithHash(hash))
	if err != nil {
		log.Fatal(err)
	}

	log.Println(res.Payload.Name, res.Payload.UpdatedAt)
}

See the API reference to find the details of parameters and responses.

GetTags API

This example fetches 3 tags and prints its name and the number of models using the tag.

func ExampleGetTags() {
	ctx := context.Background()

	res, err := client.Default.Operations.GetTags(
		operations.NewGetTagsParamsWithContext(ctx).WithLimit(swag.Int64(3)))
	if err != nil {
		log.Fatal(err)
	}

	for _, v := range res.Payload.Items {
		log.Println(v.Name, v.ModelCount)
	}
}

See the API reference to find the details of parameters and responses.

License

This software is released under the MIT License, see LICENSE.