All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cohere.api.CohereBuilder Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
/**
 * This file was auto-generated by Fern from our API Definition.
 */
package com.cohere.api;

import com.cohere.api.core.ClientOptions;
import com.cohere.api.core.Environment;

public final class CohereBuilder {
    private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder();

    private String token = System.getenv("CO_API_KEY");

    private String clientName = null;

    private Environment environment = Environment.PRODUCTION;

    /**
     * Sets token.
     * Defaults to the CO_API_KEY environment variable.
     */
    public CohereBuilder token(String token) {
        this.token = token;
        return this;
    }

    /**
     * Sets clientName
     */
    public CohereBuilder clientName(String clientName) {
        this.clientName = clientName;
        return this;
    }

    public CohereBuilder environment(Environment environment) {
        this.environment = environment;
        return this;
    }

    public CohereBuilder url(String url) {
        this.environment = Environment.custom(url);
        return this;
    }

    public Cohere build() {
        if (token == null) {
            throw new RuntimeException("Please provide token or set the CO_API_KEY environment variable.");
        }
        this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token);
        this.clientOptionsBuilder.addHeader("X-Client-Name", this.clientName);
        clientOptionsBuilder.environment(this.environment);
        return new Cohere(clientOptionsBuilder.build());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy