Search + K

Command Palette

Search for a command to run...

Sign In

Create a Text Completion

POST /v1/complete
Copy endpoint
https://api.anthropic.com

[Legacy] Create a Text Completion.

The Text Completions API is a legacy API. We recommend using the Messages API going forward.

Future models and features will not be compatible with Text Completions. See our migration guide for guidance in migrating from Text Completions to Messages.

Parameters

header Header Parameters

Name Type
anthropic-version

The version of the Claude API you want to use.

Read more about versioning and our version history here.

string
anthropic-beta

Optional header to specify the beta version(s) you want to use.

To use multiple betas, use a comma separated list like beta1,beta2 or specify the header multiple times for each beta.

string

Request Body

application/json required
interface CompletionRequest {
model: Model

The model that will complete your prompt.\n\nSee models for additional details and options.

type Model = string | "claude-opus-4-5-20251101" | "claude-opus-4-5" | "claude-3-7-sonnet-latest" | "claude-3-7-sonnet-20250219" | "claude-3-5-haiku-latest" | "claude-3-5-haiku-20241022" | "claude-haiku-4-5" | "claude-haiku-4-5-20251001" | "claude-sonnet-4-20250514" | "claude-sonnet-4-0" | "claude-4-sonnet-20250514" | "claude-sonnet-4-5" | "claude-sonnet-4-5-20250929" | "claude-opus-4-0" | "claude-opus-4-20250514" | "claude-4-opus-20250514" | "claude-opus-4-1-20250805" | "claude-3-opus-latest" | "claude-3-opus-20240229" | "claude-3-haiku-20240307"
;
prompt: string;
max_tokens_to_sample: number;
stop_sequences?: string[];
temperature?: number;
top_p?: number;
top_k?: number;
metadata?: Metadata
interface Metadata {
user_id?: string | null;
}
;
stream?: boolean;
}

Responses

200 application/json

Text Completion object.

interface CompletionResponse {
completion: string;
id: string;
model: Model

The model that will complete your prompt.\n\nSee models for additional details and options.

type Model = string | "claude-opus-4-5-20251101" | "claude-opus-4-5" | "claude-3-7-sonnet-latest" | "claude-3-7-sonnet-20250219" | "claude-3-5-haiku-latest" | "claude-3-5-haiku-20241022" | "claude-haiku-4-5" | "claude-haiku-4-5-20251001" | "claude-sonnet-4-20250514" | "claude-sonnet-4-0" | "claude-4-sonnet-20250514" | "claude-sonnet-4-5" | "claude-sonnet-4-5-20250929" | "claude-opus-4-0" | "claude-opus-4-20250514" | "claude-4-opus-20250514" | "claude-opus-4-1-20250805" | "claude-3-opus-latest" | "claude-3-opus-20240229" | "claude-3-haiku-20240307"
;
stop_reason: string | null;
type: "completion";
}

Client Errors

4XX application/json

Error response.

See our errors documentation for more details.

interface ErrorResponse {
error: InvalidRequestError
interface InvalidRequestError {
message: string;
type: "invalid_request_error";
}
| AuthenticationError
interface AuthenticationError {
message: string;
type: "authentication_error";
}
| BillingError
interface BillingError {
message: string;
type: "billing_error";
}
| PermissionError
interface PermissionError {
message: string;
type: "permission_error";
}
| NotFoundError
interface NotFoundError {
message: string;
type: "not_found_error";
}
| RateLimitError
interface RateLimitError {
message: string;
type: "rate_limit_error";
}
| GatewayTimeoutError
interface GatewayTimeoutError {
message: string;
type: "timeout_error";
}
| APIError
interface APIError {
message: string;
type: "api_error";
}
| OverloadedError
interface OverloadedError {
message: string;
type: "overloaded_error";
}
;
request_id: string | null;
type: "error";
}