
com.cohere.api.CohereBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cohere-java Show documentation
Show all versions of cohere-java Show documentation
The official Java library for Cohere's API.
/**
* 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